Skip to content

Commit ec9e548

Browse files
authored
Prstep3 (#8717)
1 parent 4f468a9 commit ec9e548

2 files changed

Lines changed: 37 additions & 24 deletions

File tree

.github/workflows/release-patch-1-create-pr.yml

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,34 +102,46 @@ jobs:
102102
# Check if patch output exists and contains branch info
103103
if [ -f patch_output.log ]; then
104104
if grep -q "already exists" patch_output.log; then
105-
# Branch exists - let user review
105+
# Branch exists - find the PR for it
106106
BRANCH=$(grep "Hotfix branch" patch_output.log | grep "already exists" | sed 's/.*Hotfix branch \(.*\) already exists.*/\1/')
107-
gh pr comment ${{ github.event.inputs.original_pr }} --body "ℹ️ Patch branch already exists!
108107
109-
A patch branch already exists: [\`$BRANCH\`](https://github.com/${{ github.repository }}/tree/$BRANCH)
108+
# Find the PR for this branch
109+
PR_INFO=$(gh pr list --head "$BRANCH" --json number,url --jq '.[0] // empty')
110110
111-
Please review this existing branch. If it's correct, check for an existing PR:
112-
[View patch PRs for this branch](https://github.com/${{ github.repository }}/pulls?q=is%3Apr+head%3A$BRANCH)
113-
114-
If the branch is incorrect or outdated, please delete it manually and run the patch command again."
111+
if [ -n "$PR_INFO" ]; then
112+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number')
113+
PR_URL=$(echo "$PR_INFO" | jq -r '.url')
114+
MESSAGE="ℹ️ Patch branch already exists!\n\nA patch branch already exists with an open PR: [#$PR_NUMBER]($PR_URL)\n\nPlease review and approve this existing patch PR. If it's incorrect, close it and run the patch command again."
115+
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
116+
else
117+
# Branch exists but no PR
118+
MESSAGE="ℹ️ Patch branch already exists!\n\nA patch branch [\`$BRANCH\`](https://github.com/${{ github.repository }}/tree/$BRANCH) exists but has no open PR.\n\nThis might indicate an incomplete patch process. Please delete the branch and run the patch command again."
119+
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
120+
fi
115121
116122
elif [ "$EXIT_CODE" = "0" ]; then
117-
# Success - new branch created
118-
gh pr comment ${{ github.event.inputs.original_pr }} --body "🚀 Patch PR created!
119-
120-
The patch release PR for this change has been created. Please review and approve it to complete the patch release:
121-
122-
[View all patch PRs](https://github.com/${{ github.repository }}/pulls?q=is%3Apr+is%3Aopen+label%3Apatch)"
123+
# Success - find the newly created PR
124+
BRANCH=$(grep "Creating hotfix branch" patch_output.log | sed 's/.*Creating hotfix branch \(.*\) from.*/\1/')
125+
126+
# Find the PR for the new branch
127+
PR_INFO=$(gh pr list --head "$BRANCH" --json number,url --jq '.[0] // empty')
128+
129+
if [ -n "$PR_INFO" ]; then
130+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number')
131+
PR_URL=$(echo "$PR_INFO" | jq -r '.url')
132+
MESSAGE="🚀 Patch PR created!\n\nThe patch release PR has been created: [#$PR_NUMBER]($PR_URL)\n\nPlease review and approve this PR to complete the patch release."
133+
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
134+
else
135+
# Fallback if we can't find the specific PR
136+
MESSAGE="🚀 Patch PR created!\n\nThe patch release PR for this change has been created. Please review and approve it:\n\n[View all patch PRs](https://github.com/${{ github.repository }}/pulls?q=is%3Apr+is%3Aopen+label%3Apatch)"
137+
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
138+
fi
123139
else
124140
# Other error
125-
gh pr comment ${{ github.event.inputs.original_pr }} --body "❌ Patch creation failed!
126-
127-
There was an error creating the patch. Please check the workflow logs for details:
128-
[View workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
141+
MESSAGE="❌ Patch creation failed!\n\nThere was an error creating the patch. Please check the workflow logs for details:\n[View workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
142+
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
129143
fi
130144
else
131-
gh pr comment ${{ github.event.inputs.original_pr }} --body "❌ Patch creation failed!
132-
133-
No output was generated. Please check the workflow logs:
134-
[View workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
145+
MESSAGE="❌ Patch creation failed!\n\nNo output was generated. Please check the workflow logs:\n[View workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
146+
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
135147
fi

.github/workflows/release-patch-from-comment.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
jobs:
88
slash-command:
99
runs-on: 'ubuntu-latest'
10-
# Only run if the comment is from a human user (not a bot)
11-
if: "!endsWith(github.event.comment.user.login, '[bot]')"
10+
# Only run if the comment is from a human user (not automated)
11+
if: "github.event.comment.user.type == 'User' && github.event.comment.user.login != 'github-actions[bot]'"
1212
permissions:
1313
contents: 'write'
1414
pull-requests: 'write'
@@ -31,7 +31,7 @@ jobs:
3131
dry_run=false
3232
3333
- name: 'Acknowledge Patch Command'
34-
if: "contains(github.event.comment.body, '/patch')"
34+
if: "startsWith(github.event.comment.body, '/patch')"
3535
uses: 'peter-evans/create-or-update-comment@67dcc547d311b736a8e6c5c236542148a47adc3d'
3636
with:
3737
issue-number: '${{ github.event.issue.number }}'
@@ -42,6 +42,7 @@ jobs:
4242
4343
- name: 'Get PR Status'
4444
id: 'pr_status'
45+
if: "steps.slash_command.outputs.dispatched == 'true'"
4546
env:
4647
GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
4748
run: |

0 commit comments

Comments
 (0)