Skip to content

fix git #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Apr 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 48 additions & 26 deletions .github/workflows/auto-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
if: steps.run_script.outputs.script_success == 'true'
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_BODY: ${{ github.event.issue.body }}
shell: /usr/bin/bash -e {0}
run: |
# Create a unique branch name with issue number
Expand All @@ -91,29 +91,51 @@ jobs:
git add -f local/ mcp-registry/ # Add all files generated by the script
git commit -m "Update repo with server manifest from issue #$ISSUE_NUMBER" || echo "No changes to commit"
git push origin "$BRANCH_NAME" --force # Push to the new branch

# Create PR directly using GitHub API instead of peter-evans/create-pull-request
PR_TITLE="Add server from issue #$ISSUE_NUMBER"
PR_BODY="Automated PR from issue #$ISSUE_NUMBER\n\nServer URL: $ISSUE_BODY"

# Check if PR already exists
PR_EXISTS=$(gh pr list --head "$BRANCH_NAME" --json number --jq 'length')

if [ "$PR_EXISTS" = "0" ]; then
# Create PR if it doesn't exist
PR_URL=$(gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base main --head "$BRANCH_NAME")
echo "pr_number=$(echo $PR_URL | grep -o '[0-9]*$')" >> $GITHUB_ENV
echo "pr_url=$PR_URL" >> $GITHUB_ENV
else
# Get PR number if it exists
PR_DATA=$(gh pr list --head "$BRANCH_NAME" --json number,url --jq '.[0]')
echo "pr_number=$(echo $PR_DATA | jq -r '.number')" >> $GITHUB_ENV
echo "pr_url=$(echo $PR_DATA | jq -r '.url')" >> $GITHUB_ENV
fi
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV

- name: Setup GitHub CLI
- name: Create Pull Request
if: steps.run_script.outputs.script_success == 'true'
uses: cli/cli-action@v1
uses: actions/github-script@v6
id: create_pr
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const issue_body = context.payload.issue.body;
const branch_name = process.env.branch_name;

// Check if PR already exists
const prs = await github.rest.pulls.list({
owner,
repo,
head: `${owner}:${branch_name}`,
state: 'open'
});

let pr_number;
let pr_url;

if (prs.data.length === 0) {
// Create new PR
const result = await github.rest.pulls.create({
owner,
repo,
title: `Add server from issue #${issue_number}`,
body: `Automated PR from issue #${issue_number}\n\nServer URL: ${issue_body}`,
head: branch_name,
base: 'main'
});

pr_number = result.data.number;
pr_url = result.data.html_url;
} else {
// PR exists
pr_number = prs.data[0].number;
pr_url = prs.data[0].html_url;
}

return { pr_number, pr_url };

- name: Comment on issue with success
if: steps.run_script.outputs.script_success == 'true'
Expand All @@ -123,12 +145,12 @@ jobs:
script: |
const issue_number = context.issue.number;
const repo = context.repo;
const pr_number = process.env.pr_number;
const pr_url = process.env.pr_url;
const pr_result = ${{ steps.create_pr.outputs.result }};
const result = JSON.parse(pr_result);

let body = '';
if (pr_number) {
body = `✅ Processing complete!\n\nA pull request has been created with the server manifest: [PR #${pr_number}](${pr_url})`;
if (result.pr_number) {
body = `✅ Processing complete!\n\nA pull request has been created with the server manifest: [PR #${result.pr_number}](${result.pr_url})`;
} else {
body = `⚠️ Processing completed, but no pull request was created. Please check the action logs for details.`;
}
Expand Down