Repository navigation
ci: label PRs that add a skill duplicating an open PR - #362
ayobamiseun wants to merge 2 commits into
Conversation
Adds a standalone pull_request_target workflow that detects when a PR adds a skills/<name>/SKILL.md that another open PR also adds, toggles the 'duplicate' label accordingly, and writes the colliding PR links to the job summary. Metadata-only: it never checks out or runs PR head code. Name-collision only, non-blocking, per the scope in addyosmani#315/addyosmani#313. Closes addyosmani#315
bb28db9 to
43be0b6
Compare
|
Really solid PR. The Two things I validated while reviewing, plus a maintainability suggestion. Detection scope is correct. The Suggestion: extract the detection logic into a committed, testable script. You already ran the exact logic locally via Minor hardening (optional, pre-merge):
None of this blocks; the workflow is mergeable as-is. The label-asymmetry and |
- Self-heal when the 'duplicate' label is missing: on addLabels failure, create the label (ignoring already-exists 422) and retry. - HTML-escape PR titles and skill names in the job-summary table.
|
Thanks for the careful review — both hardenings applied in 160dcad:
On extracting the detection logic into a committed, testable script: I considered it and decided to keep the workflow self-contained, at least in this PR. Loading a module (or invoking a script) requires adding a checkout step to a |
|
This is carefully done, and I appreciate the explicit note about never checking out PR head code, since that's the exact footgun with pull_request_target. It also lines up with the anti-duplication work we've been doing. The only reason I'm not merging on the spot is that any workflow with that trigger gets my own eyes on the permissions before it lands. Give me a beat to review it properly. |
|
Sounds good, take your time. To make the security pass quick, the full surface is: |
addyosmani
left a comment
There was a problem hiding this comment.
Want this. It automates the exact duplicate-skill problem I keep catching by hand, and it's done safely: pull_request_target with no checkout of fork code, just metadata plus a label. Approving.
|
This is still open at 7 weeks and Flagging that because it may just have been lost rather than deliberately held. Same shape as #444, which sat approved for three weeks with zero check runs. A gap worth knowing about, with me as the worked exampleI read the script rather than the description, and the scope limit is explicit and deliberate: const SKILL_RE = /^skills\/([^/]+)\/SKILL\.md$/;
...
.filter((f) => f.status === 'added')Added skill directories, name collisions only — exactly as the comment says and as #313 scoped it. No complaint about that. But the duplicate I personally caused in this repo would have been invisible to it. #505 and #428 both modified From today's open PRs the same-file convergence is easy to see: #428, #444 and #498 all touch OfferThe extension is small and belongs in your script rather than a second workflow — a second labeler competing with this one would be its own near-duplicate cluster, which would be a poor joke. Roughly: alongside Happy to push that to your branch, or to open it as a follow-up once this merges — your call, and this is your PR. I'd rather ask than start writing. For what it's worth I'd merge this as-is first: the skill-name axis is the higher-frequency case, and the modified-file axis is strictly additive. |
abhisheksharma2411
left a comment
There was a problem hiding this comment.
This is well-built, and the security posture is right — the comment explaining why pull_request_target is safe here (never checks out head code) is the part people usually leave out, and it's the part that stops someone adding a checkout step in six months. Scoping to status: 'added' so edits to an existing skill are never flagged is the correct call too.
I checked the pinning before raising it: the repo's other workflows use actions/checkout@v6 and actions/setup-node@v6, so github-script@v7 matches the house convention. Not a finding.
Three things, one of which I think is worth addressing before merge.
1. Only one PR of a colliding pair ever gets the label. Every write in the script targets issue_number: prNumber — the PR that triggered the run. So if #400 opens first and #410 opens later adding the same skill, #410's run sees #400 and labels #410. #400 is never labeled, because its own run happened before #410 existed.
That undercuts the stated purpose. The label is meant to be a filterable reviewer signal via is:pr is:open label:duplicate, but that filter returns the later half of each pair only — a reviewer sees #410 and has to open it to discover #400 exists. The pair is the useful unit, and half of it is missing from the query.
Labeling both sides when a collision is found would fix it, at the cost of the workflow writing to a PR other than the one that triggered it. Given pull-requests: write is already held that's not a new permission, but it is a scope change worth being deliberate about.
2. Stale labels, which you've flagged, bite harder because of #1. The body notes the label clears only when the PR is pushed again. Combined with the above: when #410 is merged, #400 was never labeled so nothing is stale there — but when a third PR collides and then closes, the survivor keeps duplicate indefinitely with nothing to collide with. A reviewer filtering on the label then can't distinguish live collisions from resolved ones, which is the same failure the label exists to prevent.
A schedule: sweep that re-evaluates open labeled PRs, or handling pull_request_target: closed to re-run collision checks on the PRs that referenced it, would close it. Either is a follow-up, not a blocker.
3. The API cost is O(open PRs) per event, and this repo is at 60. Each run does one listFiles for the triggering PR, then pulls.list, then one paginated listFiles per other open PR — so ~62 calls minimum right now, more with pagination on large PRs. That's per opened/synchronize/reopened, so a contributor pushing five times to one PR costs ~300 calls, and GITHUB_TOKEN is limited to roughly 1,000 requests/hour per repository shared with every other workflow.
The early exit when ours.size === 0 is what saves this — most PRs here don't add a skill, so they cost 1 call and stop. Worth stating that explicitly in the header comment, because it's the load-bearing property and it isn't obvious. If it ever becomes a problem, filtering the open-PR list by pr.changed_files or by a skill label before fanning out would cut it further.
None of these are correctness bugs in what's written — the script does what it says. #1 is the one I'd want resolved, since it's the difference between the label being a reliable filter and being a hint.
|
@addyosmani, a nudge on this one. You approved it in August, and it still merges cleanly, but it never landed: |
Summary
Implements #315: a deterministic CI complement to the CONTRIBUTING pre-flight checks (#313). A new standalone workflow flags when a PR adds a
skills/<name>/SKILL.mdthat another open PR also adds:duplicatelabel and writes the colliding PR links + skill names to the job summary.is:pr is:open label:duplicate— not a merge gate.Closes #315
Scope (as decided in #315 / #313)
status: added) — editing an existingskills/<name>/SKILL.mdis a legitimate change and is never flagged.Security
Runs on
pull_request_targetso it can label fork PRs (a plainpull_requestrun has a read-only token there). This is safe because the job never checks out or executes PR head code — it only reads PR metadata via the API (actions/github-script) and toggles a label. A comment at the top of the workflow warns future editors not to add a checkout. Permissions are pinned to the minimum:pull-requests: write,contents: read. Per-PRconcurrencygroup withcancel-in-progressavoids label races on rapid pushes.Evidence: dry-run against the live open-PR list
I ran the exact detection logic (same regex, same
status == "added"filter) locally viagh apiagainst all 89 currently open PRs:skills/<name>/SKILL.md.skills/assistant/SKILL.mdis added by fix: rename /review to /code-review and delegate persona framework to skill #181, fix(hooks): resolve security eval and session-start output schema #117, Wire agent personas into their corresponding skills #62, and Add observability-and-monitoring skill #61 — each of these would get theduplicatelabel with the others linked in its job summary.llm-cost-optimizationvs Add evaluating-llm-output skill #286evaluating-llm-output, or the several accessibility proposals feat: add accessibility-engineering skill #261/feat: add new skills, agent personas, and LLM integration checklist #254) are correctly not flagged, matching the name-collision-only scope.Dry-run output
Note: a
pull_request_targetworkflow always runs the base repo's version, so it can't be exercised from a fork before merge — the dry-run above stands in for that. API cost is modest (onelistFilesper open PR, only when the triggering PR actually adds a skill).Known limitations (by design / follow-ups)
synchronize. Re-evaluating all open PRs onclosedevents would fix this and can be a small follow-up if wanted.duplicatelabel existing (it does in GitHub repos by default, per the issue).