Claude's changes for CodeRabbit suggestion

This commit is contained in:
Edward Firmo
2025-08-05 10:57:08 +02:00
parent c1f1b5a7e7
commit 07de172188

View File

@@ -48,36 +48,36 @@ jobs:
with: with:
script: | script: |
try { try {
// Get the commit that triggered this workflow // Use GitHub's reliable API to find PRs associated with this commit
const { data: associatedPRs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha
});
if (associatedPRs.length > 0) {
// Get the most recent merged PR
const pr = associatedPRs.find(pr => pr.state === 'closed' && pr.merged_at) || associatedPRs[0];
return {
title: pr.title,
body: pr.body || 'No description provided',
number: pr.number,
found: true
};
} else {
// Fallback for direct pushes or when no PR is found
const commit = await github.rest.repos.getCommit({ const commit = await github.rest.repos.getCommit({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
ref: context.sha ref: context.sha
}); });
// Look for PR number in commit message (GitHub merge commits include this)
const commitMessage = commit.data.commit.message;
const prMatch = commitMessage.match(/Merge pull request #(\d+)/);
if (prMatch) {
const prNumber = parseInt(prMatch[1]);
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
return {
title: pr.data.title,
body: pr.data.body || 'No description provided',
number: prNumber
};
} else {
// Fallback for direct pushes
return { return {
title: 'Direct push to main', title: 'Direct push to main',
body: commitMessage, body: commit.data.commit.message,
number: null number: null,
found: false
}; };
} }
} catch (error) { } catch (error) {
@@ -85,7 +85,8 @@ jobs:
return { return {
title: 'Version update', title: 'Version update',
body: 'Automated version bump', body: 'Automated version bump',
number: null number: null,
found: false
}; };
} }
@@ -99,19 +100,15 @@ jobs:
run: | run: |
NEW_VERSION=$(cat ./versioning/VERSION) NEW_VERSION=$(cat ./versioning/VERSION)
if [ "${{ github.event_name }}" == "push" ]; then if [ "${{ github.event_name }}" == "push" ] && [ "${{ steps.pr_info.outcome }}" == "success" ]; then
# Use PR information from previous step # Use PR information directly in heredoc to avoid quoting issues
PR_TITLE='${{ fromJson(steps.pr_info.outputs.result).title }}'
PR_BODY='${{ fromJson(steps.pr_info.outputs.result).body }}'
# Create formatted tag message
cat > tag_message.txt << EOF cat > tag_message.txt << EOF
# v${NEW_VERSION} - ${PR_TITLE} # v${NEW_VERSION} - ${{ fromJson(steps.pr_info.outputs.result).title }}
${PR_BODY} ${{ fromJson(steps.pr_info.outputs.result).body }}
EOF EOF
else else
# Manual dispatch - simpler message # Manual dispatch or PR info unavailable - simpler message
cat > tag_message.txt << EOF cat > tag_message.txt << EOF
# v${NEW_VERSION} - Manual tag update # v${NEW_VERSION} - Manual tag update