Skip to content

Commit f92a8b6

Browse files
authored
work (#8720)
1 parent 029ad20 commit f92a8b6

2 files changed

Lines changed: 32 additions & 25 deletions

File tree

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

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,16 @@ jobs:
101101
102102
# Check if patch output exists and contains branch info
103103
if [ -f patch_output.log ]; then
104-
if grep -q "already exists" patch_output.log; then
105-
# Branch exists - find the PR for it
106-
BRANCH=$(grep "Hotfix branch" patch_output.log | grep "already exists" | sed 's/.*Hotfix branch \(.*\) already exists.*/\1/')
107-
108-
# Find the PR for this branch
109-
PR_INFO=$(gh pr list --head "$BRANCH" --json number,url --jq '.[0] // empty')
104+
if grep -q "already has an open PR" patch_output.log; then
105+
# Branch exists with existing PR
106+
PR_NUMBER=$(grep "Found existing PR" patch_output.log | sed 's/.*Found existing PR #\([0-9]*\).*/\1/')
107+
PR_URL=$(grep "Found existing PR" patch_output.log | sed 's/.*Found existing PR #[0-9]*: \(.*\)/\1/')
108+
gh pr comment ${{ github.event.inputs.original_pr }} --body "ℹ️ Patch PR already exists! A patch PR for this change already exists: [#$PR_NUMBER]($PR_URL). Please review and approve this existing patch PR. If it's incorrect, close it and run the patch command again."
110109
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
110+
elif grep -q "exists but has no open PR" patch_output.log; then
111+
# Branch exists but no PR
112+
BRANCH=$(grep "Hotfix branch" patch_output.log | grep "already exists" | sed 's/.*Hotfix branch \(.*\) already exists.*/\1/')
113+
gh pr comment ${{ github.event.inputs.original_pr }} --body "ℹ️ Patch branch exists but no PR found! A patch branch [\`$BRANCH\`](https://github.com/${{ github.repository }}/tree/$BRANCH) exists but has no open PR. This might indicate an incomplete patch process. Please delete the branch and run the patch command again."
121114
122115
elif [ "$EXIT_CODE" = "0" ]; then
123116
# Success - find the newly created PR
@@ -129,19 +122,15 @@ jobs:
129122
if [ -n "$PR_INFO" ]; then
130123
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number')
131124
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"
125+
gh pr comment ${{ github.event.inputs.original_pr }} --body "🚀 Patch PR created! The patch release PR has been created: [#$PR_NUMBER]($PR_URL). Please review and approve this PR to complete the patch release."
134126
else
135127
# 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"
128+
gh pr comment ${{ github.event.inputs.original_pr }} --body "🚀 Patch PR created! The patch release PR for this change has been created. Please review and approve it: [View all patch PRs](https://github.com/${{ github.repository }}/pulls?q=is%3Apr+is%3Aopen+label%3Apatch)"
138129
fi
139130
else
140131
# Other error
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"
132+
gh pr comment ${{ github.event.inputs.original_pr }} --body "❌ Patch creation failed! There was an error creating the patch. Please check the workflow logs for details: [View workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
143133
fi
144134
else
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"
135+
gh pr comment ${{ github.event.inputs.original_pr }} --body "❌ Patch creation failed! No output was generated. Please check the workflow logs: [View workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
147136
fi

scripts/create-patch-pr.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,25 @@ async function main() {
6262
// Check if hotfix branch already exists
6363
if (branchExists(hotfixBranch)) {
6464
console.log(`Hotfix branch ${hotfixBranch} already exists.`);
65-
return { existingBranch: hotfixBranch };
65+
66+
// Check if there's already a PR for this branch
67+
try {
68+
const prInfo = execSync(`gh pr list --head ${hotfixBranch} --json number,url --jq '.[0] // empty'`).toString().trim();
69+
if (prInfo && prInfo !== 'null' && prInfo !== '') {
70+
const pr = JSON.parse(prInfo);
71+
console.log(`Found existing PR #${pr.number}: ${pr.url}`);
72+
console.log(`Hotfix branch ${hotfixBranch} already has an open PR.`);
73+
return { existingBranch: hotfixBranch, existingPR: pr };
74+
} else {
75+
console.log(`Hotfix branch ${hotfixBranch} exists but has no open PR.`);
76+
console.log(`You may need to delete the branch and run this command again.`);
77+
return { existingBranch: hotfixBranch };
78+
}
79+
} catch (err) {
80+
console.error(`Error checking for existing PR: ${err.message}`);
81+
console.log(`Hotfix branch ${hotfixBranch} already exists.`);
82+
return { existingBranch: hotfixBranch };
83+
}
6684
}
6785

6886
// Create the hotfix branch from the release branch.

0 commit comments

Comments
 (0)