80
80
if : steps.run_script.outputs.script_success == 'true'
81
81
env :
82
82
ISSUE_NUMBER : ${{ github.event.issue.number }}
83
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
83
+ ISSUE_BODY : ${{ github.event.issue.body }}
84
84
shell : /usr/bin/bash -e {0}
85
85
run : |
86
86
# Create a unique branch name with issue number
@@ -91,29 +91,51 @@ jobs:
91
91
git add -f local/ mcp-registry/ # Add all files generated by the script
92
92
git commit -m "Update repo with server manifest from issue #$ISSUE_NUMBER" || echo "No changes to commit"
93
93
git push origin "$BRANCH_NAME" --force # Push to the new branch
94
-
95
- # Create PR directly using GitHub API instead of peter-evans/create-pull-request
96
- PR_TITLE="Add server from issue #$ISSUE_NUMBER"
97
- PR_BODY="Automated PR from issue #$ISSUE_NUMBER\n\nServer URL: $ISSUE_BODY"
98
-
99
- # Check if PR already exists
100
- PR_EXISTS=$(gh pr list --head "$BRANCH_NAME" --json number --jq 'length')
101
-
102
- if [ "$PR_EXISTS" = "0" ]; then
103
- # Create PR if it doesn't exist
104
- PR_URL=$(gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base main --head "$BRANCH_NAME")
105
- echo "pr_number=$(echo $PR_URL | grep -o '[0-9]*$')" >> $GITHUB_ENV
106
- echo "pr_url=$PR_URL" >> $GITHUB_ENV
107
- else
108
- # Get PR number if it exists
109
- PR_DATA=$(gh pr list --head "$BRANCH_NAME" --json number,url --jq '.[0]')
110
- echo "pr_number=$(echo $PR_DATA | jq -r '.number')" >> $GITHUB_ENV
111
- echo "pr_url=$(echo $PR_DATA | jq -r '.url')" >> $GITHUB_ENV
112
- fi
94
+ echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
113
95
114
- - name : Setup GitHub CLI
96
+ - name : Create Pull Request
115
97
if : steps.run_script.outputs.script_success == 'true'
116
- uses : cli/cli-action@v1
98
+ uses : actions/github-script@v6
99
+ id : create_pr
100
+ with :
101
+ github-token : ${{ secrets.GITHUB_TOKEN }}
102
+ script : |
103
+ const { owner, repo } = context.repo;
104
+ const issue_number = context.issue.number;
105
+ const issue_body = context.payload.issue.body;
106
+ const branch_name = process.env.branch_name;
107
+
108
+ // Check if PR already exists
109
+ const prs = await github.rest.pulls.list({
110
+ owner,
111
+ repo,
112
+ head: `${owner}:${branch_name}`,
113
+ state: 'open'
114
+ });
115
+
116
+ let pr_number;
117
+ let pr_url;
118
+
119
+ if (prs.data.length === 0) {
120
+ // Create new PR
121
+ const result = await github.rest.pulls.create({
122
+ owner,
123
+ repo,
124
+ title: `Add server from issue #${issue_number}`,
125
+ body: `Automated PR from issue #${issue_number}\n\nServer URL: ${issue_body}`,
126
+ head: branch_name,
127
+ base: 'main'
128
+ });
129
+
130
+ pr_number = result.data.number;
131
+ pr_url = result.data.html_url;
132
+ } else {
133
+ // PR exists
134
+ pr_number = prs.data[0].number;
135
+ pr_url = prs.data[0].html_url;
136
+ }
137
+
138
+ return { pr_number, pr_url };
117
139
118
140
- name : Comment on issue with success
119
141
if : steps.run_script.outputs.script_success == 'true'
@@ -123,12 +145,12 @@ jobs:
123
145
script : |
124
146
const issue_number = context.issue.number;
125
147
const repo = context.repo;
126
- const pr_number = process.env.pr_number ;
127
- const pr_url = process.env.pr_url ;
148
+ const pr_result = ${{ steps.create_pr.outputs.result }} ;
149
+ const result = JSON.parse(pr_result) ;
128
150
129
151
let body = '';
130
- if (pr_number) {
131
- body = `✅ Processing complete!\n\nA pull request has been created with the server manifest: [PR #${pr_number}](${pr_url})`;
152
+ if (result. pr_number) {
153
+ body = `✅ Processing complete!\n\nA pull request has been created with the server manifest: [PR #${result. pr_number}](${result. pr_url})`;
132
154
} else {
133
155
body = `⚠️ Processing completed, but no pull request was created. Please check the action logs for details.`;
134
156
}
0 commit comments