This commit is contained in:
matt korwel
2025-09-18 10:45:42 -07:00
committed by GitHub
parent b88d9c6353
commit b376df7691
2 changed files with 32 additions and 25 deletions

View File

@@ -101,23 +101,16 @@ jobs:
# Check if patch output exists and contains branch info
if [ -f patch_output.log ]; then
if grep -q "already exists" patch_output.log; then
# Branch exists - find the PR for it
if grep -q "already has an open PR" patch_output.log; then
# Branch exists with existing PR
PR_NUMBER=$(grep "Found existing PR" patch_output.log | sed 's/.*Found existing PR #\([0-9]*\).*/\1/')
PR_URL=$(grep "Found existing PR" patch_output.log | sed 's/.*Found existing PR #[0-9]*: \(.*\)/\1/')
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."
elif grep -q "exists but has no open PR" patch_output.log; then
# Branch exists but no PR
BRANCH=$(grep "Hotfix branch" patch_output.log | grep "already exists" | sed 's/.*Hotfix branch \(.*\) already exists.*/\1/')
# Find the PR for this branch
PR_INFO=$(gh pr list --head "$BRANCH" --json number,url --jq '.[0] // empty')
if [ -n "$PR_INFO" ]; then
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number')
PR_URL=$(echo "$PR_INFO" | jq -r '.url')
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."
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
else
# Branch exists but no PR
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."
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
fi
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."
elif [ "$EXIT_CODE" = "0" ]; then
# Success - find the newly created PR
@@ -129,19 +122,15 @@ jobs:
if [ -n "$PR_INFO" ]; then
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number')
PR_URL=$(echo "$PR_INFO" | jq -r '.url')
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."
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
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."
else
# Fallback if we can't find the specific PR
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)"
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
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)"
fi
else
# Other error
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 }})"
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
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 }})"
fi
else
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 }})"
gh pr comment ${{ github.event.inputs.original_pr }} --body "$MESSAGE"
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 }})"
fi

View File

@@ -62,7 +62,25 @@ async function main() {
// Check if hotfix branch already exists
if (branchExists(hotfixBranch)) {
console.log(`Hotfix branch ${hotfixBranch} already exists.`);
return { existingBranch: hotfixBranch };
// Check if there's already a PR for this branch
try {
const prInfo = execSync(`gh pr list --head ${hotfixBranch} --json number,url --jq '.[0] // empty'`).toString().trim();
if (prInfo && prInfo !== 'null' && prInfo !== '') {
const pr = JSON.parse(prInfo);
console.log(`Found existing PR #${pr.number}: ${pr.url}`);
console.log(`Hotfix branch ${hotfixBranch} already has an open PR.`);
return { existingBranch: hotfixBranch, existingPR: pr };
} else {
console.log(`Hotfix branch ${hotfixBranch} exists but has no open PR.`);
console.log(`You may need to delete the branch and run this command again.`);
return { existingBranch: hotfixBranch };
}
} catch (err) {
console.error(`Error checking for existing PR: ${err.message}`);
console.log(`Hotfix branch ${hotfixBranch} already exists.`);
return { existingBranch: hotfixBranch };
}
}
// Create the hotfix branch from the release branch.