Skip to content

Deduplicate discussion comment mutation flow across comment actions#43482

Open
pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/duplicate-code-discussion-comment-flow
Open

Deduplicate discussion comment mutation flow across comment actions#43482
pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/duplicate-code-discussion-comment-flow

Conversation

Copilot AI commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Two comment workflows implemented the same discussion-comment creation path independently (discussion lookup, optional replyToId, addDiscussionComment mutation, metadata extraction), creating drift risk in threaded reply behavior and output shaping.

  • Extract shared discussion comment creation primitive

    • Added createDiscussionComment(github, discussionId, body, replyToId?) in actions/setup/js/github_api_helpers.cjs.
    • Centralizes GraphQL mutation construction for both top-level and threaded discussion comments.
  • Refactor existing callers to reuse shared flow

    • actions/setup/js/add_comment.cjs now delegates discussion comment creation to the shared helper after discussion resolution.
    • actions/setup/js/add_reaction_and_edit_comment.cjs now uses the same helper for discussion/discussion_comment follow-up comment creation.
  • Keep workflow-specific behavior at call sites

    • Reply-target resolution (resolveTopLevelDiscussionCommentId) and body assembly remain in each workflow module.
    • Only mutation assembly/execution + created comment metadata extraction moved to shared code.
// Shared helper usage in both flows
const comment = await createDiscussionComment(github, discussionId, commentBody, replyToId);
// comment => { id, url }

Copilot AI linked an issue Jul 5, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Refactor discussion comment mutation flow to eliminate duplicate code Deduplicate discussion comment mutation flow across comment actions Jul 5, 2026
Copilot AI requested a review from pelikhan July 5, 2026 06:48
@pelikhan pelikhan marked this pull request as ready for review July 5, 2026 07:01
Copilot AI review requested due to automatic review settings July 5, 2026 07:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

No code to review: PR #43482 contains exactly one commit ('Initial plan') with zero file changes. All files on the branch (github_api_helpers.cjs, add_comment.cjs, add_reaction_and_edit_comment.cjs) have identical SHAs to main. The PR body describes planned work that has not yet been implemented. There is no diff to analyze.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #43482 does not have the 'implementation' label and has 0 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR (#43482: 'Deduplicate discussion comment mutation flow across comment actions'). The PR metadata shows 0 additions/deletions with no test files in the diff. Test Quality Sentinel skipped.

@github-actions github-actions Bot mentioned this pull request Jul 5, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /codebase-design and /tdd — this PR is in the planning stage (0 changed files; only an "Initial plan" commit). This review covers the design described in the PR body and the existing code the plan targets.

📋 Key Design Observations

Design Decision: Shared Primitive Signature

The plan proposes createDiscussionComment(github, discussionId, body, replyToId?) where the caller pre-resolves the discussion node ID. The two existing callers have different starting points today:

  • add_comment.cjs uses commentOnDiscussion(owner, repo, discussionNumber, ...) — resolves the node ID internally and returns { id, html_url, discussion_url }. The discussion_url is needed for caller output.
  • add_reaction_and_edit_comment.cjs already holds discussionId (from getDiscussionNodeId in add_reaction.cjs) and only needs { id, url } downstream.

Having callers pre-resolve the ID is a good choice for testability (the shared primitive can be tested without mocking the lookup query), but the plan should explicitly state this contract.

Return Value Shape Divergence

add_comment.cjs needs discussion_url in the result; the other caller does not. The shared helper should document which shape it returns and whether callers are expected to ignore unneeded fields, or whether discussion_url needs to be obtained separately (e.g., by the ID-resolution step that already runs in commentOnDiscussion).

getDiscussionNodeId Is a Third Duplication Site

add_reaction.cjs exports getDiscussionNodeId using the same discussion(number: $num) { id } query that commentOnDiscussion in add_comment.cjs runs inline. The plan addresses mutation duplication but not lookup duplication. Moving getDiscussionNodeId to github_api_helpers.cjs and having add_reaction.cjs re-export or import from there would complete the deduplication.

Error Contract Not Specified

commentOnDiscussion throws ERR_NOT_FOUND when the discussion is missing. The inline path in add_reaction_and_edit_comment.cjs wraps the whole comment-creation block in a catch that logs a warning rather than rethrowing. The shared helper plan should specify whether the primitive throws (callers decide on recovery) or swallows errors — the two callers currently diverge.

Positive Aspects

  • ✅ Correct scope: isolating the addDiscussionComment mutation assembly is the right deduplication unit.
  • ✅ Keeping resolveTopLevelDiscussionCommentId and body assembly at call sites is correct — those are workflow-specific.
  • ✅ Placing the new helper in github_api_helpers.cjs is consistent with module structure.
🧪 TDD — Write These Tests Before Implementing

In github_api_helpers.test.cjs:

  1. createDiscussionComment — no replyToId → calls 2-variable mutation form, returns { id, url }
  2. createDiscussionComment — with replyToId → calls 3-variable mutation form
  3. createDiscussionCommentreplyToId: null treated same as omitted (no extra variable)
  4. Error propagation: when github.graphql rejects, the error propagates to the caller

Regression checks in callers:

  • add_comment.cjs discussion path still produces discussion_url in its result
  • add_reaction_and_edit_comment.cjs discussion path still calls setCommentOutputs with the correct id and url

Recommendations Before Implementing

  1. Document the ID contract — state that callers must pass a pre-resolved GraphQL node ID, not a numeric discussion number.
  2. Agree on the return shape{ id, url } or { id, html_url, discussion_url }. If discussion_url is needed, either the helper returns it or it comes from the ID-resolution step.
  3. Migrate getDiscussionNodeId to github_api_helpers.cjs — completes the deduplication and removes a second duplicated GraphQL query.
  4. Specify the error contract — throw on API failure (recommended; callers handle recovery) or swallow and log?
  5. Write the TDD tests above before coding — this ensures no behavioral regression across both callers.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 80.2 AIC · ⌖ 5.54 AIC · ⊞ 6.6K
Comment /matt to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: Deduplicate Discussion Comment Mutation Flow

Status: This PR contains only an "Initial plan" commit with 0 changed files — no implementation yet.

The proposed refactoring is well-reasoned. Below are design issues to address during implementation.


Key issues to address

  1. Interface mismatch between the two callers

    • add_reaction_and_edit_comment.cjs already has a pre-resolved discussionId (node ID from getDiscussionNodeId). The proposed createDiscussionComment(github, discussionId, body, replyToId?) fits naturally here.
    • add_comment.cjscommentOnDiscussion() takes (github, owner, repo, discussionNumber, message, replyToId) and resolves the node ID internally — querying both id and url. Refactoring it to use the shared helper will require an extra step to preserve the discussionUrl needed for the return value { id, html_url, discussion_url }.
  2. Return type difference

    The proposed helper returns { id, url } (raw GraphQL shape). commentOnDiscussion() returns { id, html_url, discussion_url }. Callers in add_comment.cjs depend on html_url for logging and discussion_url in the return data. The wrapper must map urlhtml_url and carry discussion_url separately.

  3. github is ambient in add_reaction_and_edit_comment.cjs

    That file currently uses the github global injected by github-script. The shared helper signature createDiscussionComment(github, ...) is correct, but the add_reaction caller must pass the global github explicitly — wire this consistently.

  4. getDiscussionNodeId only fetches id, not url

    add_reaction_and_edit_comment.cjs calls getDiscussionNodeId() which only queries the id. The shared helper returning { id, url } is fine here since only those fields go to setCommentOutputs. Confirm add_comment.cjs reconstructs discussion_url from a separate query or field.

  5. No test changes noted

    add_comment.test.cjs and add_reaction_and_edit_comment.test.cjs should verify the shared helper is called correctly. The PR description does not mention tests.


Suggested shared helper:

// github_api_helpers.cjs
async function createDiscussionComment(github, discussionId, body, replyToId) { ... }
// returns { id: string, url: string }

Then commentOnDiscussion() in add_comment.cjs delegates:

const comment = await createDiscussionComment(github, discussionId, message, replyToId);
return { id: comment.id, html_url: comment.url, discussion_url: discussionUrl };

The refactoring goal is correct. Address the type-mapping and test coverage gaps, then this will be a clean improvement.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 125.6 AIC · ⌖ 6.18 AIC · ⊞ 4.8K

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

🤖 PR Triage — Run #7

Field Value
Category refactor
Risk 🟢 low
Score 12 / 100
Action close

Score breakdown: impact 0 + urgency 10 + quality 2

This PR has 0 files changed (empty diff). The refactor intent (deduplicating discussion comment mutation flow into github_api_helpers.cjs) did not produce any file changes. Recommend closing — reopen once changes are committed.

Generated by 🔧 PR Triage Agent · 56.3 AIC · ⌖ 8.84 AIC · ⊞ 5.5K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, review the remaining feedback, ensure the branch is current, and rerun checks.

Generated by 👨‍🍳 PR Sous Chef · 16.1 AIC · ⌖ 6.23 AIC · ⊞ 4.6K ·
Comment /souschef to run again

Copilot AI and others added 2 commits July 5, 2026 10:06
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, review the remaining feedback, ensure the branch is current, and rerun checks.

...

Implemented the requested PR-finisher pass. The deduplication changes are now on the branch in commit 9b36240 (plus follow-up validation commit 7466cd0). I reviewed remaining in-scope feedback, confirmed the branch is current with base (mergeable_state: unstable due checks), and reran local checks (make fmt, make lint, make test-unit, make test, make recompile) along with parallel_validation (Code Review + CodeQL).

Copilot AI requested a review from gh-aw-bot July 5, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code: Discussion Comment Mutation Flow

4 participants