Skip to content

Commit 53d9632

Browse files
nielspardonclaude
andauthored
ci: remove PR title check comment when check passes (#172)
Ports substrait-io/substrait-java#850 to substrait-python. Previously the PR Title Check workflow posted an "ACTION NEEDED" comment when the PR title/description did not follow Conventional Commits, but never removed it once the title was fixed. This consolidates the comment logic into a single `github-script` step that branches on the commitlint outcome (using `continue-on-error: true` plus `core.setFailed(...)` to keep the check red on failure): - On pass: delete any previously posted comment. - On fail: post the comment if not already present. The bot comment is identified via a hidden `<!-- pr-title-check -->` marker rather than exact body matching, so cleanup survives wording or whitespace changes. The workflow now declares `permissions: pull-requests: write` so it can delete comments. The Python-specific `.commitlintrc.js` content (the dependabot `Bumps [...]` ignore rule) is preserved. Note: cleanup is marker-based, so it only applies to comments posted by this new version going forward. Pre-existing comments from the old workflow version won't be automatically removed. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5acd539 commit 53d9632

1 file changed

Lines changed: 46 additions & 24 deletions

File tree

.github/workflows/pr_title.yml

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: PR Title Check
33
on:
44
pull_request_target:
55
types: [opened, edited, synchronize, reopened]
6+
7+
permissions:
8+
pull-requests: write
9+
610
jobs:
711
commitlint:
812
name: PR title / description conforms to semantic-release
@@ -25,42 +29,60 @@ jobs:
2529
"body-leading-blank": [0, "always"]
2630
}
2731
}' > .commitlintrc.js
28-
- run: npx commitlint --extends @commitlint/config-conventional --verbose <<< $COMMIT_MSG
32+
- id: commitlint
33+
continue-on-error: true
34+
run: npx commitlint --extends @commitlint/config-conventional --verbose <<< $COMMIT_MSG
2935
env:
3036
COMMIT_MSG: >
3137
${{ github.event.pull_request.title }}
3238
3339
${{ github.event.pull_request.body }}
34-
- if: failure()
35-
uses: actions/github-script@v9
40+
- uses: actions/github-script@v9
3641
with:
3742
script: |
38-
const message = `**ACTION NEEDED**
43+
// Hidden marker used to find this job's comment regardless of wording.
44+
const marker = "<!-- pr-title-check -->";
45+
const message = `${marker}
46+
**ACTION NEEDED**
47+
48+
Substrait follows the [Conventional Commits
49+
specification](https://www.conventionalcommits.org/en/v1.0.0/) for
50+
release automation.
3951
40-
Substrait follows the [Conventional Commits
41-
specification](https://www.conventionalcommits.org/en/v1.0.0/) for
42-
release automation.
52+
The PR title and description are used as the merge commit message.
53+
Please update your PR title and description to match the specification.
54+
`;
55+
const passed = "${{ steps.commitlint.outcome }}" === "success";
4356
44-
The PR title and description are used as the merge commit message.\
45-
Please update your PR title and description to match the specification.
46-
`
47-
// Get list of current comments
57+
// Find an existing comment from this job, if any.
4858
const comments = await github.paginate(github.rest.issues.listComments, {
4959
owner: context.repo.owner,
5060
repo: context.repo.repo,
51-
issue_number: context.issue.number
61+
issue_number: context.issue.number,
5262
});
53-
// Check if this job already commented
54-
for (const comment of comments) {
55-
if (comment.body === message) {
56-
return // Already commented
63+
const existing = comments.find((c) => c.body.includes(marker));
64+
65+
if (passed) {
66+
// Clean up the comment now that the check passes.
67+
if (existing) {
68+
await github.rest.issues.deleteComment({
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
comment_id: existing.id,
72+
});
5773
}
74+
return;
5875
}
59-
// Post the comment about Conventional Commits
60-
github.rest.issues.createComment({
61-
owner: context.repo.owner,
62-
repo: context.repo.repo,
63-
issue_number: context.issue.number,
64-
body: message
65-
})
66-
core.setFailed(message)
76+
77+
// Check failed: post the comment if it isn't already there, then fail the job.
78+
if (!existing) {
79+
await github.rest.issues.createComment({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
issue_number: context.issue.number,
83+
body: message,
84+
});
85+
}
86+
core.setFailed(
87+
"PR title and description do not follow the Conventional Commits specification."
88+
);

0 commit comments

Comments
 (0)