Skip to content

Commit 842f159

Browse files
author
Jeremy Dai
authored
update git (#36)
1 parent 8e58f6b commit 842f159

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

.github/workflows/auto-update.yml

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
if: steps.run_script.outputs.script_success == 'true'
8181
env:
8282
ISSUE_NUMBER: ${{ github.event.issue.number }}
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8384
shell: /usr/bin/bash -e {0}
8485
run: |
8586
# Create a unique branch name with issue number
@@ -90,22 +91,29 @@ jobs:
9091
git add -f local/ mcp-registry/ # Add all files generated by the script
9192
git commit -m "Update repo with server manifest from issue #$ISSUE_NUMBER" || echo "No changes to commit"
9293
git push origin "$BRANCH_NAME" --force # Push to the new branch
93-
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
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
94113
95-
- name: Create Pull Request
96-
id: create_pr
114+
- name: Setup GitHub CLI
97115
if: steps.run_script.outputs.script_success == 'true'
98-
uses: peter-evans/create-pull-request@v5
99-
with:
100-
token: ${{ secrets.GITHUB_TOKEN }}
101-
commit-message: "Add server from issue #${{ github.event.issue.number }}"
102-
title: "Add server from issue #${{ github.event.issue.number }}"
103-
body: |
104-
Automated PR from issue #${{ github.event.issue.number }}
105-
106-
Server URL: ${{ github.event.issue.body }}
107-
branch: ${{ env.branch_name }}
108-
base: main
116+
uses: cli/cli-action@v1
109117

110118
- name: Comment on issue with success
111119
if: steps.run_script.outputs.script_success == 'true'
@@ -115,8 +123,8 @@ jobs:
115123
script: |
116124
const issue_number = context.issue.number;
117125
const repo = context.repo;
118-
const pr_number = '${{ steps.create_pr.outputs.pull-request-number }}';
119-
const pr_url = pr_number ? `https://github.com/${repo.owner}/${repo.repo}/pull/${pr_number}` : '';
126+
const pr_number = process.env.pr_number;
127+
const pr_url = process.env.pr_url;
120128
121129
let body = '';
122130
if (pr_number) {

0 commit comments

Comments
 (0)