Skip to content

🌱 Add workflow to link automated bugs on PR merge - #693

Open
nachandr wants to merge 2 commits into
migtools:mainfrom
nachandr:link_automated_bugs
Open

🌱 Add workflow to link automated bugs on PR merge#693
nachandr wants to merge 2 commits into
migtools:mainfrom
nachandr:link_automated_bugs

Conversation

@nachandr

@nachandr nachandr commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

This adds automation coverage details for bugs.

  1. Triggers on PR merge
  2. Scans the PR diff for added lines matching // Automates: https://github.com/migtools/crane/issues/NNN
  3. Comments on each referenced issue with Automated through PR #xyz (url) (closed issues included)
  4. Deduplicates — if the same issue is referenced multiple times (like [BUG] [validate] --api-resources mutual exclusion not enforced for --server, --token, --cluster, --user #429 in 5 tests), it only comments once

Signed-off-by: Nandini Chandra <nachandr@redhat.com>
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a GitHub Actions workflow that runs for merged pull requests, extracts // Automates: issue references from added diff lines, and comments on matching issues in the same repository.

Changes

Automated bug linking

Layer / File(s) Summary
Workflow trigger and execution setup
.github/workflows/link-automated-bugs.yml
Runs after merged pull requests close, configures permissions, and checks out the repository with full history.
Issue reference extraction and comments
.github/workflows/link-automated-bugs.yml
Lists changed files, scans added lines for issue references, deduplicates targets, and posts pull request comments to matching same-repository issues with per-issue error handling.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GitHub as GitHub
  participant Workflow as Link automated bugs
  participant PullRequestAPI as Pull request API
  participant IssueAPI as Issue API
  GitHub->>Workflow: Trigger on merged pull_request closed event
  Workflow->>PullRequestAPI: List changed files and patches
  PullRequestAPI-->>Workflow: Return pull request diffs
  Workflow->>Workflow: Find unique Automates issue references
  Workflow->>IssueAPI: Create comments on same-repository issues
  IssueAPI-->>Workflow: Return comment results or errors
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: a new workflow that links automated bugs when a PR is merged.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/link-automated-bugs.yml:
- Around line 18-21: Remove the unused “Checkout merged code”
actions/checkout@v4 step from the workflow, leaving the github-script REST API
operations unchanged. Do not replace it with another checkout configuration.
- Around line 30-36: Update the PR file retrieval around
github.rest.pulls.listFiles to use github.paginate with the same repository and
pull request parameters, ensuring all changed files are collected rather than
only the first 100; preserve the existing downstream file-processing behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8681468e-e755-403b-916f-0da6eb584f19

📥 Commits

Reviewing files that changed from the base of the PR and between 5c411a5 and 149b0c5.

📒 Files selected for processing (1)
  • .github/workflows/link-automated-bugs.yml

Comment thread .github/workflows/link-automated-bugs.yml Outdated
Comment thread .github/workflows/link-automated-bugs.yml
@nachandr nachandr changed the title Add workflow to link automated bugs on PR merge 🌱 Add workflow to link automated bugs on PR merge Jul 24, 2026
@nachandr nachandr self-assigned this Jul 24, 2026
@nachandr nachandr moved this from Todo to In progress in Crane Development Jul 24, 2026
Signed-off-by: Nandini Chandra <nachandr@redhat.com>
@nachandr
nachandr force-pushed the link_automated_bugs branch from fa721b9 to 748ede0 Compare July 24, 2026 08:45
@nachandr
nachandr requested a review from istein1 July 28, 2026 12:11
@aufi

aufi commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR, I have two issues to be considered:

  1. No idempotency protection against duplicate comments

If the workflow is re-run (e.g. via "Re-run jobs" on a merged PR), it will post duplicate comments on issues. Consider checking for an existing comment before posting:

  const comments = await github.rest.issues.listComments({
    owner, repo, issue_number: number, per_page: 100
  });
  const alreadyCommented = comments.data.some(c =>
    c.body.includes(`Automated through PR #${prNumber}`)
  );
  if (alreadyCommented) {
    console.log(`Already commented on issue #${number}, skipping`);
    continue;
  }
  1. Missing concurrency guard

The existing pr-closed.yaml (cherry-pick workflow) triggers on the same event. If a PR merge fires both workflows simultaneously and both try to interact with the same issue, there's a theoretical race. Consider adding a concurrency group:

  concurrency:
    group: link-bugs-${{ github.event.pull_request.number }}
    cancel-in-progress: true

  This is low-risk but follows the pattern used in reconcile_gh_issue.yaml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants