8080 if : steps.run_script.outputs.script_success == 'true'
8181 env :
8282 ISSUE_NUMBER : ${{ github.event.issue.number }}
83- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
83+ ISSUE_BODY : ${{ github.event.issue.body }}
8484 shell : /usr/bin/bash -e {0}
8585 run : |
8686 # Create a unique branch name with issue number
@@ -91,29 +91,51 @@ jobs:
9191 git add -f local/ mcp-registry/ # Add all files generated by the script
9292 git commit -m "Update repo with server manifest from issue #$ISSUE_NUMBER" || echo "No changes to commit"
9393 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
11395
114- - name : Setup GitHub CLI
96+ - name : Create Pull Request
11597 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 };
117139
118140 - name : Comment on issue with success
119141 if : steps.run_script.outputs.script_success == 'true'
@@ -123,12 +145,12 @@ jobs:
123145 script : |
124146 const issue_number = context.issue.number;
125147 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) ;
128150
129151 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})`;
132154 } else {
133155 body = `⚠️ Processing completed, but no pull request was created. Please check the action logs for details.`;
134156 }
0 commit comments