cla-file-check GitHub action - check before again and again posting about the CLA that needs signing by the contributor.#168
Conversation
cla-file-check GitHub action - check before again and again about the CLA that needs signing by the contributor.cla-file-check GitHub action - check before again and again posting about the CLA that needs signing by the contributor.
|
we can test at least the command within this. gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments[] | select(.author.login == "github-actions[bot]") | .body' | grep -q "Contributor License Agreement"the script, ( supposedly), if this is true will skip. |
There was a problem hiding this comment.
Pull request overview
This pull request addresses issue #54 by preventing the CLA workflow from posting duplicate comments on every commit to a pull request. The workflow now checks if a CLA-related comment from the github-actions bot already exists before posting a new one.
Changes:
- Added a new step to check for existing CLA comments from the github-actions bot
- Modified the comment posting step to only execute when no existing CLA comment is found
- Reduced notification noise for contributors who haven't signed the CLA
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.github/workflows/cla-file-check.yml
Outdated
| id: check_comment | ||
| run: | | ||
| # Check if github-actions bot has already commented about CLA on this PR | ||
| if gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments[] | select(.author.login == "github-actions[bot]") | .body' | grep -q "Contributor License Agreement"; then |
There was a problem hiding this comment.
This command pipeline will fail if no comments from github-actions bot exist yet, because grep returns a non-zero exit code when it finds no matches. This would prevent the workflow from ever posting the first CLA comment. Add error handling by appending || true to the end of the pipeline, or restructure to explicitly handle the exit code. For example: if gh pr view ... | grep -q "..." 2>/dev/null; then or wrap the entire condition in a way that handles the failure case.
| if gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments[] | select(.author.login == "github-actions[bot]") | .body' | grep -q "Contributor License Agreement"; then | |
| COMMENTS=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments[] | select(.author.login == "github-actions[bot]") | .body' || true) | |
| if echo "$COMMENTS" | grep -q "Contributor License Agreement"; then |
cla-file-check GitHub action - check before again and again posting about the CLA that needs signing by the contributor.cla-file-check GitHub action - check before again and again posting about the CLA that needs signing by the contributor.
| else | ||
| echo "No CLA comment found, will post one" | ||
| echo "comment_exists=false" >> $GITHUB_OUTPUT | ||
| fi |
There was a problem hiding this comment.
here's a simple test I ran for this ( copied this into a bash script with configurable pr passed in )
[03:06:26] /home/user/visualsign-parser (fix/cla-duplicate-comments=)
\─<")>< cat test.sh
#!/bin/bash
COMMENTS=$(gh pr view $PR_NUMBER --json comments --jq '.comments[] | select(.author.login == "github-actions") | .body')
if echo "$COMMENTS" | grep -q "Contributor License Agreement"; then
echo "CLA comment already exists, skipping"
echo "comment_exists=true" >> $GITHUB_OUTPUT
else
echo "No CLA comment found, will post one"
echo "comment_exists=false" >> $GITHUB_OUTPUT
fi
/─[03:06:28] /home/user/visualsign-parser (fix/cla-duplicate-comments=)
\─<")>< PR_NUMBER=162 ./test.sh
CLA comment already exists, skipping
./test.sh: line 7: $GITHUB_OUTPUT: ambiguous redirect
/─1 [03:06:38] /home/user/visualsign-parser (fix/cla-duplicate-comments=)
\─<")>< PR_NUMBER=168 ./test.sh
No CLA comment found, will post one
./test.sh: line 10: $GITHUB_OUTPUT: ambiguous redirect
/─1 [03:06:53] /home/user/visualsign-parser (fix/cla-duplicate-comments=)
There was a problem hiding this comment.
note that the $GITHUB_OUTPUT: ambiguous redirect can be ignored... this shouldn't occur when it runs within the Github Action vs my local machine. its a special variable not defined in my machine but yes defined within Github Actions ( proved by its usage in the previous step in this file )
see https://github.com/anchorageoss/visualsign-parser/pull/168/changes#r2772045200 |
cla-file-check GitHub action - check before again and again posting about the CLA that needs signing by the contributor.cla-file-check GitHub action - check before again and again posting about the CLA that needs signing by the contributor.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.github/workflows/cla-file-check.yml
Outdated
| # Check if github-actions bot has already commented about CLA on this PR | ||
| COMMENTS=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments[] | select(.author.login == "github-actions") | .body') | ||
|
|
||
| if echo "$COMMENTS" | grep -q "Contributor License Agreement"; then |
There was a problem hiding this comment.
The grep pattern "Contributor License Agreement" is fragile because it depends on exact matching of this phrase. If the comment text in the "Comment on PR if user is not signed" step (line 65-69) is ever modified to use different wording (e.g., abbreviated as "CLA" or rephrased), this check will fail to detect existing comments and duplicate comments will be posted. Consider using a more stable identifier or searching for a unique marker that's less likely to change, such as the CLA_URL environment variable value.
| if echo "$COMMENTS" | grep -q "Contributor License Agreement"; then | |
| if echo "$COMMENTS" | grep -Fq "${{ env.CLA_URL }}"; then |
There was a problem hiding this comment.
ya that's a good call.....
Previously, the CLA workflow would post a comment asking the user to sign the CLA on every commit pushed to a PR. This created noise and made PR reviewing harder. Now the workflow checks if a CLA comment already exists before posting, ensuring users only get notified once per PR. Fixes #54 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The github-actions bot's author login is "github-actions", not "github-actions[bot]". This fixes the duplicate comment issue by correctly detecting existing CLA comments. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Capture comments in a variable first, then check for CLA text. This makes the logic clearer and handles the case where no comments exist without cryptic error handling. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Search for the CLA URL in existing comments rather than the text "Contributor License Agreement" for more robust duplicate detection. The URL is a stable, unique identifier that won't break if comment wording changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
70d58ca to
8b7ae67
Compare

Previously, the CLA workflow would post a comment asking the user to sign the CLA on every commit pushed to a PR. This created noise and made PR reviewing harder.
Now the workflow checks if a CLA comment already exists before posting, ensuring users only get notified once per PR.
above to be verified post-merge via opening a PR via my other GitHub account
testing of the bash within the new step orchestrated here -> https://github.com/anchorageoss/visualsign-parser/pull/168/changes#r2772045200
Fixes #54
🤖 Generated with Claude Code