Skip to content

fix(workflows): safe PR body parsing and idempotent summary comments#74

Merged
MarkusNeusinger merged 1 commit intomainfrom
fix/workflow-sync-idempotency
Dec 1, 2025
Merged

fix(workflows): safe PR body parsing and idempotent summary comments#74
MarkusNeusinger merged 1 commit intomainfrom
fix/workflow-sync-idempotency

Conversation

@MarkusNeusinger
Copy link
Copy Markdown
Owner

Summary

  • Fix bot-sync-status PR body parsing that caused shell errors with newlines
  • Add idempotency check to prevent duplicate 'Generation Complete' comments

Changes

File Fix
bot-sync-status.yml Safely fetch PR body via gh pr view instead of direct variable interpolation
gen-new-plot.yml Check if summary comment exists before posting (prevents duplicates)

Root Cause

Test plan

  • Merge to main
  • Create new simple plot request
  • Verify sync-status works without errors
  • Verify no duplicate comments

- bot-sync-status: safely fetch PR body via gh CLI to avoid shell escaping errors
- gen-new-plot: add idempotency check to prevent duplicate 'Generation Complete' comments
Copilot AI review requested due to automatic review settings December 1, 2025 16:00
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@MarkusNeusinger MarkusNeusinger merged commit 0843d63 into main Dec 1, 2025
7 checks passed
@MarkusNeusinger MarkusNeusinger deleted the fix/workflow-sync-idempotency branch December 1, 2025 16:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes two GitHub Actions workflow issues: shell escaping errors when parsing PR bodies containing newlines, and duplicate "Generation Complete" comments caused by multiple workflow runs. The bot-sync-status workflow now uses gh pr view with JSON output for safe PR body retrieval, and the gen-new-plot workflow adds an idempotency check before posting summary comments.

Key Changes

  • Fixed PR body parsing in bot-sync-status.yml to prevent shell errors with multi-line content
  • Added idempotency check in gen-new-plot.yml to prevent duplicate summary comments
  • Removed dead code that built an unused results list

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
.github/workflows/bot-sync-status.yml Replaced direct PR body variable interpolation with gh pr view --json body to safely handle newlines and special characters
.github/workflows/gen-new-plot.yml Added check for existing "Generation Complete" comments before posting, and removed unused results collection code

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

run: |
# Check if "Generation Complete" comment already exists (idempotency)
EXISTING=$(gh api repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments \
--jq '[.[] | select(.body | startswith("## Generation Complete"))] | length')
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --jq filter syntax is correct, but the variable assignment could be more robust. If the API call fails, EXISTING could be empty, which would cause the comparison [ "$EXISTING" -gt "0" ] to fail with a "unary operator expected" error.

Consider adding error handling:

EXISTING=$(gh api repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments \
  --jq '[.[] | select(.body | startswith("## Generation Complete"))] | length' 2>/dev/null || echo "0")

This ensures EXISTING defaults to "0" if the API call fails, preventing the script from crashing.

Suggested change
--jq '[.[] | select(.body | startswith("## Generation Complete"))] | length')
--jq '[.[] | select(.body | startswith("## Generation Complete"))] | length' 2>/dev/null || echo "0")

Copilot uses AI. Check for mistakes.
fi

- name: Post summary to main issue
if: steps.check_summary.outputs.skip != 'true'
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The condition if: steps.check_summary.outputs.skip != 'true' will execute the step when skip is anything other than the string 'true', including when it's 'false'. This is correct, but for clarity and consistency with GitHub Actions best practices, consider using a positive check instead:

if: steps.check_summary.outputs.skip == 'false'

This makes the intent more explicit and reduces the risk of unintended execution if the output is unexpectedly empty or malformed.

Suggested change
if: steps.check_summary.outputs.skip != 'true'
if: steps.check_summary.outputs.skip == 'false'

Copilot uses AI. Check for mistakes.
MarkusNeusinger added a commit that referenced this pull request Dec 1, 2025
…74)

## Summary
- Fix bot-sync-status PR body parsing that caused shell errors with
newlines
- Add idempotency check to prevent duplicate 'Generation Complete'
comments

## Changes
| File | Fix |
|------|-----|
| bot-sync-status.yml | Safely fetch PR body via gh pr view instead of
direct variable interpolation |
| gen-new-plot.yml | Check if summary comment exists before posting
(prevents duplicates) |

## Root Cause
- The PR_BODY variable syntax breaks when the body contains newlines
- The approved label was added 3 times to issue #53, causing 3 duplicate
comments

## Test plan
- Merge to main
- Create new simple plot request
- Verify sync-status works without errors
- Verify no duplicate comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants