Skip to content

ci: add PR triage workflow for issue linkage and duplicate detection - #12469

Merged
smith-xyz merged 4 commits into
typeorm:masterfrom
smith-xyz:ci/pr-triage-workflow
Jun 8, 2026
Merged

smith-xyz merged 4 commits into
typeorm:masterfrom
smith-xyz:ci/pr-triage-workflow

Conversation

@smith-xyz

Copy link
Copy Markdown
Collaborator

Description of change

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated tests validating the change (tests/**.test.ts)
  • Documentation has been updated to reflect this change (docs/docs/**.md)

🛡️ Security fixes: Do not submit security fixes as public PRs — the diff exposes the vulnerability. Use GitHub Security Advisories instead.

@smith-xyz
smith-xyz marked this pull request as ready for review May 13, 2026 12:55
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented May 13, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (13) 📘 Rule violations (1)

Grey Divider


Action required

1. Wrong exemption message 🐞 Bug ≡ Correctness
Description
FAIL_SUMMARY claims maintainers are exempt via skip-issue-check, but the job if: only exempts
Bot users and PRs that already have the label; maintainers will still be checked/fail unless someone
manually adds the label. This mismatch will confuse users/maintainers about why the check ran and
how to bypass it.
Code

.github/workflows/pr-triage.yml[R19-48]

+    if: >-
+      github.repository == 'typeorm/typeorm' &&
+      github.event.pull_request.user.type != 'Bot' &&
+      !contains(github.event.pull_request.labels.*.name, 'skip-issue-check')
+    runs-on: ubuntu-latest
+    permissions:
+      pull-requests: write
+      issues: read
+      checks: write
+    steps:
+      - name: Triage PR
+        env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          PR_NUMBER: ${{ github.event.pull_request.number }}
+          PR_BODY: ${{ github.event.pull_request.body }}
+          HEAD_SHA: ${{ github.event.pull_request.head.sha }}
+          EVENT_ACTION: ${{ github.event.action }}
+        run: |
+          set -euo pipefail
+
+          REPO="typeorm/typeorm"
+          CHECK_NAME="pr-triage / issue-link"
+          LABEL_LINKED="linked-issue"
+          LABEL_TRIAGE="needs-triage"
+          LABEL_DUPE="possible-duplicate"
+          FAIL_TITLE="No issue reference found"
+          FAIL_SUMMARY="Link this PR to an issue by adding one of: \
+          \`Fixes #NNNN\`, \`Closes #NNNN\`, or \`Resolves #NNNN\` \
+          to your PR description. If no issue exists, please create one first. \
+          Maintainers and bots are exempt via the \`skip-issue-check\` label."
Evidence
The job condition does not check maintainer/author association, while the failure message explicitly
claims maintainers are exempt.

.github/workflows/pr-triage.yml[19-22]
.github/workflows/pr-triage.yml[45-48]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow failure summary states that “Maintainers and bots are exempt via the `skip-issue-check` label,” but the workflow does not implement a maintainer exemption in the job condition. This is a factual mismatch between behavior and messaging.
## Issue Context
- Job-level `if:` currently checks only repository, PR author `user.type != 'Bot'`, and absence of `skip-issue-check`.
- `FAIL_SUMMARY` claims maintainers are exempt.
## Fix Focus Areas
Choose one:
1) **Fix behavior**: implement maintainer exemption (e.g., allow `author_association` of `MEMBER`/`OWNER`/`COLLABORATOR`).
2) **Fix messaging**: update `FAIL_SUMMARY` to remove/adjust the maintainer exemption claim, keeping only what’s true.
- .github/workflows/pr-triage.yml[19-48]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Duplicate check-runs created 🐞 Bug ☼ Reliability
Description
report_check() always creates a new check-run via POST; when the workflow runs on edited events
this can generate multiple check-runs with the same name for the same HEAD SHA. This leads to
noisy/stale check entries and can leave earlier conclusions visible even after the PR body is
corrected.
Code

.github/workflows/pr-triage.yml[R60-68]

+          report_check() {
+            gh api "repos/${REPO}/check-runs" --method POST \
+              -f name="$CHECK_NAME" \
+              -f head_sha="$HEAD_SHA" \
+              -f status="completed" \
+              -f conclusion="$1" \
+              -f "output[title]=$2" \
+              -f "output[summary]=$3"
+          }
Evidence
The workflow is triggered on PR edits, and the function that reports results always POSTs a new
check-run with a constant name rather than updating an existing one.

.github/workflows/pr-triage.yml[8-12]
.github/workflows/pr-triage.yml[40-41]
.github/workflows/pr-triage.yml[60-68]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow posts a brand new check-run every time it runs (`POST /check-runs`) instead of updating an existing check-run for the same `name` + `head_sha`. Because the workflow runs on `pull_request_target.edited`, edits can create repeated/stale check-runs.
## Issue Context
- Trigger includes `edited`.
- `report_check()` only does a POST.
## Fix Focus Areas
- Find existing check-run ID for `CHECK_NAME` on `HEAD_SHA` and `PATCH /check-runs/{check_run_id}` instead of POST when one exists.
- (Alternative) Use commit status API (`repos/.../statuses/{sha}`) with a stable context name, if you don’t need rich check-run output.
- .github/workflows/pr-triage.yml[8-12]
- .github/workflows/pr-triage.yml[60-68]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Unsafe PR body parsing 🐞 Bug ☼ Reliability
Description
The workflow parses PR_BODY via echo "$PR_BODY", but echo can treat leading -n/-e as
options and (depending on shell) process escapes, so some PR descriptions can be
transformed/truncated before the issue-link regex runs. This can cause missed/incorrect issue
detection and therefore incorrect check-run conclusions and labels.
Code

.github/workflows/pr-triage.yml[R52-58]

Evidence
The issue-reference extraction pipeline is fed exclusively by echo "$PR_BODY", making parsing
behavior dependent on echo’s option/escape handling rather than preserving the PR body verbatim.

.github/workflows/pr-triage.yml[52-58]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow uses `echo "$PR_BODY"` to feed PR text into the issue-reference extraction pipeline. `echo` is not reliable for arbitrary/untrusted content because it may interpret leading `-n`/`-e` as options and can mangle content, which can break matching and labeling.
## Issue Context
This runs under `pull_request_target`, so PR authors fully control `PR_BODY` content.
## Fix Focus Areas
- Replace `echo "$PR_BODY"` with a safe, no-surprises primitive such as `printf '%s\n' "$PR_BODY"` (or a heredoc).
### Suggested patch sketch

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (3)
4. Issue regex false positives 🐞 Bug ≡ Correctness
Description
The issue-reference extraction regex has no word boundaries around the closing keywords, so it can
match keywords embedded inside larger words (e.g., "unfixes #123" matches "fixes #123"), incorrectly
marking a PR as linked. This weakens the enforcement signal and can drive incorrect
labeling/duplicate checks.
Code

.github/workflows/pr-triage.yml[53]

Evidence
The workflow uses a PCRE alternation for closing keywords without \b boundaries, so the engine can
start a match at the fixes substring within a longer token as long as it is followed by whitespace
and an issue reference.

.github/workflows/pr-triage.yml[50-57]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The grep regex used to detect closing keywords (`fix/close/resolve`) is missing word boundaries, allowing matches inside longer words (e.g., `unfixes #123`). This can incorrectly treat a PR as having a valid closing keyword.
## Issue Context
The match is performed with `grep -ioP` and then digits are extracted; any false-positive keyword match will be treated as an issue reference.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[50-57]
## Suggested change
Update the regex to require keyword boundaries, e.g. `\b(?:fix(?:es)?|close[sd]?|resolve[sd]?)\b`, and optionally allow punctuation like `:` after the keyword if you want to support `Fixes: #123`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Missing synchronize trigger 🐞 Bug ☼ Reliability
Description
The workflow triggers only on pull_request_target opened/edited, so pushing new commits to an
existing PR (synchronize) will not rerun triage and will not create a check-run for the new HEAD
SHA. This leaves the latest commit without the "pr-triage / issue-link" status and can make the
gating signal stale/inconsistent across commits.
Code

.github/workflows/pr-triage.yml[R7-12]

Evidence
The workflow’s trigger list omits synchronize, yet the script posts a check-run tied to
github.event.pull_request.head.sha, so any new commit SHA will not receive this check unless the
body is edited again. A comparable workflow in the repo includes synchronize for
pull_request_target PR checks.

.github/workflows/pr-triage.yml[7-12]
.github/workflows/pr-triage.yml[30-35]
.github/workflows/pr-triage.yml[59-66]
.github/workflows/pull-request.yml[3-9]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`pr-triage.yml` creates a check-run bound to the PR head SHA, but the workflow is not triggered on `pull_request_target:synchronize` (new commits pushed). This means updated PR commits won’t get the triage check-run/label updates.
## Issue Context
- The workflow posts check-runs using `head_sha=$HEAD_SHA`.
- On commit pushes, `github.event.pull_request.head.sha` changes, but the workflow does not run.
- In this repo, other `pull_request_target` workflows include `synchronize`.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[7-12]
- .github/workflows/pr-triage.yml[30-35]
- .github/workflows/pr-triage.yml[59-66]
- .github/workflows/pull-request.yml[3-9]
## Proposed fix
Add `synchronize` to the `pull_request_target.types` list so the workflow re-evaluates and reports status on every new PR head commit.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. Invalid issue marked success 🐞 Bug ≡ Correctness
Description
The workflow posts a successful check-run as soon as it finds a Fixes/Closes/Resolves number,
before verifying that the referenced issue exists or is readable. As a result, a PR body like `Fixes
#99999999 can receive a green check even though the subsequent gh issue view` fails and the PR is
effectively unverified.
Code

.github/workflows/pr-triage.yml[R83-87]

Evidence
report_check "success" is executed unconditionally whenever FIRST_ISSUE is non-empty, and only
afterwards does the workflow attempt to query the issue; the query is explicitly error-suppressed,
so a non-existent/unreadable issue does not prevent the already-posted green check-run.

.github/workflows/pr-triage.yml[83-87]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow reports a success check-run immediately after extracting `FIRST_ISSUE`, without validating that the issue exists / is accessible.
## Issue Context
Because `gh issue view` errors are suppressed (`2>/dev/null || echo "0"`), invalid issue references won’t fail the job, but the check-run will already be recorded as `success`, which is misleading.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[83-92]
## Suggested fix
1. Validate the issue before reporting success:
- Run `gh issue view "$FIRST_ISSUE" --repo "$REPO" --json number` (or similar) and check the exit code.
2. If the issue lookup fails:
- Post a `failure` check-run (e.g., "Referenced issue not found") and apply the triage label.
3. Only after the issue lookup succeeds:
- Post the `success` check-run and proceed with label/duplicate logic.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

7. Fallback skips label removal 🐞 Bug ≡ Correctness ⭐ New
Description
In apply_label(), if the combined add+remove label edit fails, the fallback retries with
--add-label only, so the opposing label may remain and the PR can end up with both needs-triage
and linked-issue. This breaks the workflow’s intended mutual exclusivity for triage labels and can
confuse downstream triage automation.
Code

.github/workflows/pr-triage.yml[R70-74]

+          apply_label() {
+            gh pr edit "$PR_NUMBER" --repo "$REPO" \
+              --add-label "$1" --remove-label "$2" 2>/dev/null \
+              || gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "$1" \
+              || echo "Warning: failed to apply label $1"
Evidence
The workflow uses apply_label(new, old) specifically to toggle between linked-issue and
needs-triage, but the fallback path omits the removal step entirely.

.github/workflows/pr-triage.yml[70-75]
.github/workflows/pr-triage.yml[89-93]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`apply_label()` is intended to swap mutually exclusive labels, but its fallback path drops `--remove-label`, allowing the old label to remain if the first call fails.

### Issue Context
This affects the `linked-issue` vs `needs-triage` state toggling.

### Fix Focus Areas
- .github/workflows/pr-triage.yml[70-75]
- .github/workflows/pr-triage.yml[89-93]

### Suggested fix
Refactor `apply_label()` so that if the combined add/remove fails, it still attempts removal in a separate command (or retries the full swap), e.g.:
- Try combined add/remove.
- If that fails, run `gh pr edit ... --add-label "$1"` and then `gh pr edit ... --remove-label "$2"` (removal best-effort with `|| true`).
This preserves mutual exclusivity even when one of the operations is flaky.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. Dupe scan spams API 🐞 Bug ➹ Performance
Description
Duplicate detection performs eight separate gh pr list queries per run, increasing latency and the
likelihood of hitting GitHub API rate limits. When rate limits/errors occur, duplicate detection
will silently degrade due to the || true pipeline.
Code

.github/workflows/pr-triage.yml[R96-105]

Evidence
The DUPES command substitution explicitly contains eight gh pr list invocations; each is an API
call and the final || true suppresses errors.

.github/workflows/pr-triage.yml[95-105]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow runs 8 `gh pr list` searches to detect duplicates, which is slow and rate-limit prone.
## Issue Context
This job can run on PR edits as well as opens, so the total API usage can grow quickly.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[95-105]
## Suggested change
Replace the 8 calls with a single query using GitHub search syntax (e.g., OR conditions) or a single GraphQL request that searches PR bodies for the issue number across multiple keyword variants, then filter out the current PR.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


9. Skip label won't rerun 🐞 Bug ☼ Reliability
Description
The job is gated on the absence of the skip-issue-check label, but adding/removing that label does
not trigger the workflow because labeled/unlabeled actions are not subscribed. This leaves any
previously created check-run and triage/linked labels unchanged until a separate opened/edited event
occurs.
Code

.github/workflows/pr-triage.yml[R7-12]

Evidence
The workflow explicitly checks for skip-issue-check in the job condition, but the subscribed
pull_request_target event types do not include label-change actions, so changing that label cannot
cause the job to re-evaluate and update its outputs.

.github/workflows/pr-triage.yml[7-12]
.github/workflows/pr-triage.yml[19-23]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow uses the `skip-issue-check` label in the job `if:` guard, but does not run on `pull_request_target:labeled` / `unlabeled`. As a result, applying the exemption label won’t immediately update/clear the workflow’s check/labels.
## Issue Context
- The job is skipped when `skip-issue-check` is present.
- The workflow only runs for `opened` and `edited`, so label changes alone do not cause reevaluation.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[7-12]
- .github/workflows/pr-triage.yml[19-23]
## Proposed fix
Add `labeled` and `unlabeled` (and optionally `reopened`) to `pull_request_target.types` so the workflow re-runs and updates status/labels when maintainers toggle `skip-issue-check`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (7)
10. Wrong issue chosen 🐞 Bug ≡ Correctness
Description
When multiple issue references exist in the PR body, the workflow sorts all extracted issue numbers
and then picks the smallest one, so it may link/label the PR against the wrong issue. This also
poisons duplicate detection because it runs against the wrong issue number.
Code

.github/workflows/pr-triage.yml[R55-57]

Evidence
The workflow explicitly sorts extracted issue numbers and then takes the first entry, which will be
the smallest numeric ID, not the first referenced issue in the PR body.

.github/workflows/pr-triage.yml[50-58]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow extracts all referenced issue numbers, sorts them (`sort -u`), and then selects the first (`head -1`). Sorting changes the intended order, so if a PR references multiple issues, the workflow may select the smallest ID instead of the first-mentioned/primary issue.
### Issue Context
This affects the reported check message (`Issue linked: #...`), the `linked-issue`/`needs-triage` labeling decision, and downstream duplicate detection.
### Fix Focus Areas
- .github/workflows/pr-triage.yml[50-58]
### Suggested fix
- Preserve mention order when picking `FIRST_ISSUE` (e.g., pick the first match from the grep results before sorting).
- If you still need a unique list for other purposes, compute it separately (e.g., `ISSUES_UNIQ=$(...) | sort -u`), but do not use it to determine the primary issue.
- Optionally: if multiple distinct issues are found, consider failing/neutral-checking with a message asking for a single closing keyword to avoid ambiguity.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


11. Issue lookup errors masked 🐞 Bug ☼ Reliability
Description
If gh issue view fails, the script coerces LABEL_COUNT to 0, causing it to apply
needs-triage and remove linked-issue even when the issue is valid and labeled. This hides
transient API/permission failures and can mislabel PRs without indicating the lookup failed.
Code

.github/workflows/pr-triage.yml[R85-92]

Evidence
The code suppresses all errors from gh issue view and defaults to 0, and then directly uses that
value to decide whether to apply linked-issue vs needs-triage.

.github/workflows/pr-triage.yml[85-92]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`LABEL_COUNT` is derived from `gh issue view ... || echo "0"`, so any failure (network/API issues, rate limiting, temporary GitHub outage) is treated as “issue has 0 labels,” which drives the workflow to apply `needs-triage`.
### Issue Context
This makes the workflow silently degrade and can flip labels incorrectly, reducing trust in the automation.
### Fix Focus Areas
- .github/workflows/pr-triage.yml[85-92]
### Suggested fix
- Capture the exit code of `gh issue view` and distinguish:
- success + 0 labels (legit)
- failure to fetch issue metadata (error)
- On failure, either:
- report a neutral/failure check output explaining the metadata fetch failed and to retry, and avoid changing labels, or
- implement a small retry with backoff before giving up.
- Log stderr (or a sanitized error) so maintainers can diagnose why labeling didn’t happen.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


12. pr-triage.yml adds comment banners 📘 Rule violation ⚙ Maintainability
Description
The new workflow introduces multiple banner-style comments (e.g., all-caps security banner and `##
... ##` section headers) that add noise and are stylistically inconsistent with existing workflows.
This conflicts with the requirement to avoid AI-like/extra commentary in changes.
Code

.github/workflows/pr-triage.yml[R1-3]

Evidence
PR Compliance ID 4 requires avoiding extra/AI-like commentary. The added workflow includes a
top-level security banner and multiple markdown-like section headers inside the bash script, which
are not necessary for functionality and add stylistic noise.

Rule 4: Remove AI-generated noise
.github/workflows/pr-triage.yml[1-3]
.github/workflows/pr-triage.yml[50-50]
.github/workflows/pr-triage.yml[76-76]
.github/workflows/pr-triage.yml[94-94]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new workflow adds banner-style comments (security disclaimer header and `## ... ##` section headers) that increase noise and can be perceived as AI-generated commentary.
## Issue Context
Existing workflows in this repo generally avoid large banner/disclaimer blocks and markdown-like section headers inside scripts.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[1-3]
- .github/workflows/pr-triage.yml[50-50]
- .github/workflows/pr-triage.yml[76-76]
- .github/workflows/pr-triage.yml[94-94]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


13. Duplicate label never cleared ✓ Resolved 🐞 Bug ☼ Reliability
Description
If the PR already has the possible-duplicate label, the workflow exits early and never
re-evaluates duplicates, so the label/comment can become stale when the PR body changes to a
different issue. Additionally, when no issue reference is present, the workflow exits without
removing an existing possible-duplicate label.
Code

.github/workflows/pr-triage.yml[R95-97]

Evidence
The workflow explicitly exits early when it detects possible-duplicate, preventing any
recomputation or cleanup, and the no-issue path exits after only toggling
needs-triage/linked-issue with no attempt to remove possible-duplicate.

.github/workflows/pr-triage.yml[77-81]
.github/workflows/pr-triage.yml[95-97]
.github/workflows/pr-triage.yml[107-112]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The duplicate-detection logic can leave `possible-duplicate` stuck on a PR because it exits early when the label is present and never removes the label when the PR no longer qualifies.
## Issue Context
- When `HAS_DUPE_LABEL` is `true`, the script `exit 0`s before recomputing duplicates.
- When no issue reference is present, the script also `exit 0`s after applying `needs-triage`/removing `linked-issue`, but does not remove `possible-duplicate`.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[77-81]
- .github/workflows/pr-triage.yml[95-112]
## Suggested fix
1. Remove the early-exit optimization:
- Do not `exit 0` solely because `possible-duplicate` is already set.
2. After computing `DUPES`:
- If `DUPES` is empty, remove the `possible-duplicate` label (and optionally avoid commenting).
3. In the no-issue-reference path:
- Also remove the `possible-duplicate` label since the PR is no longer tied to an issue for duplicate detection.
4. Ensure label removals are non-fatal (e.g., `|| true`) so transient API/permission issues don’t break the triage run.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


14. Dupe scan misses valid links ✓ Resolved 🐞 Bug ≡ Correctness
Description
The workflow accepts issue references via full issue URLs and past-tense keyword variants (e.g.,
"Closed #123"), but duplicate detection only searches open PRs for the exact phrases
"Fixes/Closes/Resolves #N". This will miss duplicates that reference the same issue using URL form
or other accepted variants, reducing the workflow’s stated duplicate-detection effectiveness.
Code

.github/workflows/pr-triage.yml[R96-100]

Evidence
The extraction step explicitly supports URL-based issue references and multiple close/resolve
variants, but the duplicate detection step only searches for three present-tense keyword phrases, so
duplicates using other accepted formats won’t be found.

.github/workflows/pr-triage.yml[50-56]
.github/workflows/pr-triage.yml[96-100]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Duplicate detection searches only for three exact keyword strings, but issue extraction accepts additional forms (URLs and close/resolve variants). This mismatch causes duplicates to be missed.
## Issue Context
- Extraction regex matches both `#NNNN` and `https://github.com/typeorm/typeorm/issues/NNNN`, and accepts `close[sd]?` / `resolve[sd]?` variants.
- Duplicate search only looks for the exact strings `"Fixes #N"`, `"Closes #N"`, `"Resolves #N"`.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[50-56]
- .github/workflows/pr-triage.yml[96-100]
## Suggested fix approach
- Either:
1) Expand the duplicate search to include URL-form searches and the additional accepted keyword variants (e.g., `Close`, `Closed`, `Resolve`, `Resolved`), or
2) Tighten the extraction regex to only accept the exact keyword forms you’re going to search for.
- If you keep URL support in extraction, add a corresponding `gh pr list --search` clause for `"https://github.com/typeorm/typeorm/issues/${FIRST_ISSUE}"` (and/or other common URL formats) so the features stay consistent.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


15. Dupes skipped on PR edits ✓ Resolved 🐞 Bug ≡ Correctness
Description
Duplicate detection runs only when the PR action is "opened", so if a contributor adds the closing
keyword/issue link later via an edit (a common flow after a triage reminder), duplicate detection
will never run for that PR. This can silently miss duplicates even when the final PR body contains a
valid issue reference.
Code

.github/workflows/pr-triage.yml[R93-95]

Evidence
The workflow subscribes to edited events but explicitly exits before running duplicate detection
unless the action is opened, preventing duplicate checks after later PR-body edits.

.github/workflows/pr-triage.yml[7-12]
.github/workflows/pr-triage.yml[93-95]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow exits before the duplicate check for any action other than `opened`, so duplicates are not checked when the PR body is updated later to add an issue reference.
## Issue Context
`pull_request_target` triggers on both `opened` and `edited`, but the script gates duplicate detection to `opened` only.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[7-12]
- .github/workflows/pr-triage.yml[93-95]
## Suggested fix approach
- Consider running the duplicate check on `edited` as well, at least when an issue reference is present.
- To avoid repeat comments, gate commenting behind a label (e.g., only comment if `possible-duplicate` label not already set) or check for an existing bot comment before posting a new one.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


16. Label failures abort job ✓ Resolved 🐞 Bug ☼ Reliability
Description
With set -euo pipefail, if both gh pr edit attempts in apply_label() fail, the entire script
exits non-zero, potentially turning the triage job red after it already created a success/failure
check-run. This makes the workflow brittle to label/permission/API errors and can prevent subsequent
steps (like duplicate comments) from running.
Code

.github/workflows/pr-triage.yml[R69-73]

Evidence
The script enables set -euo pipefail, and apply_label() has no non-fatal guard if both `gh pr
edit` attempts fail; in that case the non-zero return aborts the job.

.github/workflows/pr-triage.yml[37-37]
.github/workflows/pr-triage.yml[69-73]
.github/workflows/pr-triage.yml[82-91]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`apply_label()` is executed under `set -e`, and it does not have a final fallback/guard if label edits fail. If both `gh pr edit` commands fail, the job fails even though the check-run may already have been posted.
## Issue Context
The workflow’s primary purpose is to report a check-run result; label edits are secondary and should not typically prevent the check from being reported/kept green.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[37-37]
- .github/workflows/pr-triage.yml[69-73]
- .github/workflows/pr-triage.yml[75-92]
## Suggested fix approach
- Make label edits best-effort:
- Add a final `|| true` inside `apply_label()` so failures do not terminate the script, and/or
- Wrap calls to `apply_label` like `apply_label ... || true`.
- Optionally log a warning to stdout/stderr when labeling fails so maintainers can diagnose without failing the entire workflow.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

17. Duplicate list join missing spaces 🐞 Bug ⚙ Maintainability ⭐ New
Description
DUPE_LIST tries to join duplicate PR numbers with a comma+space, but tr '\n' ', ' maps newlines
to only a comma, resulting in output like #12,#34 without spaces. This reduces the readability of
the duplicate warning comment.
Code

.github/workflows/pr-triage.yml[108]

+            DUPE_LIST=$(echo "$DUPES" | sed 's/^/#/' | tr '\n' ', ' | sed 's/,$//')
Evidence
The current pipeline uses tr with a single input character (newline) and a two-character output
set (comma+space), so only the comma can be emitted.

.github/workflows/pr-triage.yml[107-109]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`DUPE_LIST` is built with `tr '\n' ', '`, but `tr` does 1:1 character translation, so it cannot emit a two-character delimiter (`, `).

### Issue Context
This impacts only the human-facing comment body.

### Fix Focus Areas
- .github/workflows/pr-triage.yml[107-113]

### Suggested fix
Replace the `tr` join with a join that can emit `, `, e.g. using `awk`:
```bash
DUPE_LIST=$(echo "$DUPES" | sed 's/^/#/' | awk 'BEGIN{first=1}{if(!first)printf ", "; printf $0; first=0}END{print ""}')
```
(or an equivalent `sed`/`paste` approach that guarantees `, ` separators).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


18. Template indentation may misrender 🐞 Bug ⚙ Maintainability
Description
The PR template checklist item continuation line is indented enough that GitHub-flavored Markdown
can render it as a code block inside the task list item, reducing readability/copyability of the
intended keywords. This can lead to contributors pasting the backticks verbatim or missing the
instruction.
Code

.github/PULL_REQUEST_TEMPLATE.md[R35-36]

Evidence
The template uses a task list item followed by a heavily indented continuation line containing the
keyword examples, which is the pattern that can trigger code-block rendering in GFM when indentation
is 4+ spaces within list contexts.

.github/PULL_REQUEST_TEMPLATE.md[34-37]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The continuation line under the checklist item is indented by multiple spaces, which may render as a code block within the list item.
## Issue Context
This is purely a formatting/readability concern in the PR template.
## Fix Focus Areas
- .github/PULL_REQUEST_TEMPLATE.md[34-37]
## Suggested change
Reduce indentation to a normal list continuation (commonly 2 spaces), or put the examples on the same line (or use a nested list) to ensure consistent rendering in GitHub Markdown.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Previous review results

Review updated until commit c198037

Results up to commit N/A


🐞 Bugs (11) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0)


Action required
1. Wrong exemption message 🐞 Bug ≡ Correctness
Description
FAIL_SUMMARY claims maintainers are exempt via skip-issue-check, but the job if: only exempts
Bot users and PRs that already have the label; maintainers will still be checked/fail unless someone
manually adds the label. This mismatch will confuse users/maintainers about why the check ran and
how to bypass it.
Code

.github/workflows/pr-triage.yml[R19-48]

+    if: >-
+      github.repository == 'typeorm/typeorm' &&
+      github.event.pull_request.user.type != 'Bot' &&
+      !contains(github.event.pull_request.labels.*.name, 'skip-issue-check')
+    runs-on: ubuntu-latest
+    permissions:
+      pull-requests: write
+      issues: read
+      checks: write
+    steps:
+      - name: Triage PR
+        env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          PR_NUMBER: ${{ github.event.pull_request.number }}
+          PR_BODY: ${{ github.event.pull_request.body }}
+          HEAD_SHA: ${{ github.event.pull_request.head.sha }}
+          EVENT_ACTION: ${{ github.event.action }}
+        run: |
+          set -euo pipefail
+
+          REPO="typeorm/typeorm"
+          CHECK_NAME="pr-triage / issue-link"
+          LABEL_LINKED="linked-issue"
+          LABEL_TRIAGE="needs-triage"
+          LABEL_DUPE="possible-duplicate"
+          FAIL_TITLE="No issue reference found"
+          FAIL_SUMMARY="Link this PR to an issue by adding one of: \
+          \`Fixes #NNNN\`, \`Closes #NNNN\`, or \`Resolves #NNNN\` \
+          to your PR description. If no issue exists, please create one first. \
+          Maintainers and bots are exempt via the \`skip-issue-check\` label."
Evidence
The job condition does not check maintainer/author association, while the failure message explicitly
claims maintainers are exempt.

.github/workflows/pr-triage.yml[19-22]
.github/workflows/pr-triage.yml[45-48]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow failure summary states that “Maintainers and bots are exempt via the `skip-issue-check` label,” but the workflow does not implement a maintainer exemption in the job condition. This is a factual mismatch between behavior and messaging.
## Issue Context
- Job-level `if:` currently checks only repository, PR author `user.type != 'Bot'`, and absence of `skip-issue-check`.
- `FAIL_SUMMARY` claims maintainers are exempt.
## Fix Focus Areas
Choose one:
1) **Fix behavior**: implement maintainer exemption (e.g., allow `author_association` of `MEMBER`/`OWNER`/`COLLABORATOR`).
2) **Fix messaging**: update `FAIL_SUMMARY` to remove/adjust the maintainer exemption claim, keeping only what’s true.
- .github/workflows/pr-triage.yml[19-48]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Duplicate check-runs created 🐞 Bug ☼ Reliability
Description
report_check() always creates a new check-run via POST; when the workflow runs on edited events
this can generate multiple check-runs with the same name for the same HEAD SHA. This leads to
noisy/stale check entries and can leave earlier conclusions visible even after the PR body is
corrected.
Code

.github/workflows/pr-triage.yml[R60-68]

+          report_check() {
+            gh api "repos/${REPO}/check-runs" --method POST \
+              -f name="$CHECK_NAME" \
+              -f head_sha="$HEAD_SHA" \
+              -f status="completed" \
+              -f conclusion="$1" \
+              -f "output[title]=$2" \
+              -f "output[summary]=$3"
+          }
Evidence
The workflow is triggered on PR edits, and the function that reports results always POSTs a new
check-run with a constant name rather than updating an existing one.

.github/workflows/pr-triage.yml[8-12]
.github/workflows/pr-triage.yml[40-41]
.github/workflows/pr-triage.yml[60-68]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow posts a brand new check-run every time it runs (`POST /check-runs`) instead of updating an existing check-run for the same `name` + `head_sha`. Because the workflow runs on `pull_request_target.edited`, edits can create repeated/stale check-runs.
## Issue Context
- Trigger includes `edited`.
- `report_check()` only does a POST.
## Fix Focus Areas
- Find existing check-run ID for `CHECK_NAME` on `HEAD_SHA` and `PATCH /check-runs/{check_run_id}` instead of POST when one exists.
- (Alternative) Use commit status API (`repos/.../statuses/{sha}`) with a stable context name, if you don’t need rich check-run output.
- .github/workflows/pr-triage.yml[8-12]
- .github/workflows/pr-triage.yml[60-68]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Unsafe PR body parsing 🐞 Bug ☼ Reliability
Description
The workflow parses PR_BODY via echo "$PR_BODY", but echo can treat leading -n/-e as
options and (depending on shell) process escapes, so some PR descriptions can be
transformed/truncated before the issue-link regex runs. This can cause missed/incorrect issue
detection and therefore incorrect check-run conclusions and labels.
Code

.github/workflows/pr-triage.yml[R52-58]

Evidence
The issue-reference extraction pipeline is fed exclusively by echo "$PR_BODY", making parsing
behavior dependent on echo’s option/escape handling rather than preserving the PR body verbatim.

.github/workflows/pr-triage.yml[52-58]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow uses `echo "$PR_BODY"` to feed PR text into the issue-reference extraction pipeline. `echo` is not reliable for arbitrary/untrusted content because it may interpret leading `-n`/`-e` as options and can mangle content, which can break matching and labeling.
## Issue Context
This runs under `pull_request_target`, so PR authors fully control `PR_BODY` content.
## Fix Focus Areas
- Replace `echo "$PR_BODY"` with a safe, no-surprises primitive such as `printf '%s\n' "$PR_BODY"` (or a heredoc).
### Suggested patch sketch

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (3)
4. Issue regex false positives 🐞 Bug ≡ Correctness
Description
The issue-reference extraction regex has no word boundaries around the closing keywords, so it can
match keywords embedded inside larger words (e.g., "unfixes #123" matches "fixes #123"), incorrectly
marking a PR as linked. This weakens the enforcement signal and can drive incorrect
labeling/duplicate checks.
Code

.github/workflows/pr-triage.yml[53]

Evidence
The workflow uses a PCRE alternation for closing keywords without \b boundaries, so the engine can
start a match at the fixes substring within a longer token as long as it is followed by whitespace
and an issue reference.

.github/workflows/pr-triage.yml[50-57]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The grep regex used to detect closing keywords (`fix/close/resolve`) is missing word boundaries, allowing matches inside longer words (e.g., `unfixes #123`). This can incorrectly treat a PR as having a valid closing keyword.
## Issue Context
The match is performed with `grep -ioP` and then digits are extracted; any false-positive keyword match will be treated as an issue reference.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[50-57]
## Suggested change
Update the regex to require keyword boundaries, e.g. `\b(?:fix(?:es)?|close[sd]?|resolve[sd]?)\b`, and optionally allow punctuation like `:` after the keyword if you want to support `Fixes: #123`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Missing synchronize trigger 🐞 Bug ☼ Reliability
Description
The workflow triggers only on pull_request_target opened/edited, so pushing new commits to an
existing PR (synchronize) will not rerun triage and will not create a check-run for the new HEAD
SHA. This leaves the latest commit without the "pr-triage / issue-link" status and can make the
gating signal stale/inconsistent across commits.
Code

.github/workflows/pr-triage.yml[R7-12]

Evidence
The workflow’s trigger list omits synchronize, yet the script posts a check-run tied to
github.event.pull_request.head.sha, so any new commit SHA will not receive this check unless the
body is edited again. A comparable workflow in the repo includes synchronize for
pull_request_target PR checks.

.github/workflows/pr-triage.yml[7-12]
.github/workflows/pr-triage.yml[30-35]
.github/workflows/pr-triage.yml[59-66]
.github/workflows/pull-request.yml[3-9]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`pr-triage.yml` creates a check-run bound to the PR head SHA, but the workflow is not triggered on `pull_request_target:synchronize` (new commits pushed). This means updated PR commits won’t get the triage check-run/label updates.
## Issue Context
- The workflow posts check-runs using `head_sha=$HEAD_SHA`.
- On commit pushes, `github.event.pull_request.head.sha` changes, but the workflow does not run.
- In this repo, other `pull_request_target` workflows include `synchronize`.
## Fix Focus Areas
- .github/workflows/pr-triage.yml[7-12]
- .github/workflows/pr-triage.yml[30-35]
- .github/workflows/pr-triage.yml[59-66]
- .github/workflows/pull-request.yml[3-9]
## Proposed fix
Add `synchronize` to the `pull_request_target.types` list so the workflow re-evaluates and reports status on every new PR head commit.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. Invalid issue marked success 🐞 Bug ≡ Correctness
Description
The workflow posts a successful check-run as soon as it finds a Fixes/Closes/Resolves number,
before verifying that the referenced issue exists or is readable. As a result, a PR body like `Fixes
#99999999 can receive a green check even though the subsequent gh issue view` fails and the PR is
effectively unverified.
Code

[.github/workflows/pr-triage.yml[R83-87]](https://g...

@smith-xyz

Copy link
Copy Markdown
Collaborator Author

bugs from qodo addressed, rest is noise. But marking for discussion in any case.

@smith-xyz
smith-xyz force-pushed the ci/pr-triage-workflow branch 3 times, most recently from 480ba4a to f556b3f Compare May 15, 2026 19:36
@smith-xyz
smith-xyz force-pushed the ci/pr-triage-workflow branch from 3a21bde to b354b35 Compare May 29, 2026 16:19
@smith-xyz
smith-xyz force-pushed the ci/pr-triage-workflow branch 2 times, most recently from e7cb858 to 3a21bde Compare June 8, 2026 15:09
@smith-xyz
smith-xyz force-pushed the ci/pr-triage-workflow branch from 3a21bde to c198037 Compare June 8, 2026 15:12
@smith-xyz
smith-xyz enabled auto-merge (squash) June 8, 2026 15:12
@smith-xyz
smith-xyz merged commit b6b64e4 into typeorm:master Jun 8, 2026
13 checks passed
@github-actions github-actions Bot added this to the 1.0 milestone Jun 8, 2026
@smith-xyz

Copy link
Copy Markdown
Collaborator Author

going to merge this - if it works well great, if not we can remove.

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

Development

Successfully merging this pull request may close these issues.

3 participants