Skip to content

[code-simplifier] refactor: dedupe isRestEndpoint helper into github_api_helpers.cjs - #49261

Merged
pelikhan merged 4 commits into
mainfrom
code-simplifier/dedupe-isrestendpoint-c9d34ff9b0e34ad3
Jul 31, 2026
Merged

[code-simplifier] refactor: dedupe isRestEndpoint helper into github_api_helpers.cjs#49261
pelikhan merged 4 commits into
mainfrom
code-simplifier/dedupe-isrestendpoint-c9d34ff9b0e34ad3

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Summary

Deduplicates the isRestEndpoint type guard function, which was previously defined identically in two handler files, into a single shared implementation in github_api_helpers.cjs.

Changes

  • actions/setup/js/github_api_helpers.cjs: Added the isRestEndpoint type guard (checks that a value is an object with route and params properties) and exported it from the module.
  • actions/setup/js/add_reaction_and_edit_comment.cjs: Removed the local duplicate isRestEndpoint definition; now imports it from github_api_helpers.cjs.
  • actions/setup/js/add_workflow_run_comment.cjs: Removed the local duplicate isRestEndpoint definition; now imports it from github_api_helpers.cjs.

Notes

  • A follow-up commit (eecb5a279) relocated the new function's placement within github_api_helpers.cjs to restore correct JSDoc-to-function association for resolveTopLevelDiscussionCommentId.
  • Behavior is unchanged; this is a pure refactor with no breaking changes.

Impact

  • Breaking: No
  • Risk: Low — logic is identical, only relocated and shared.

Generated by PR Description Updater for #49261 · auto · 30.5 AIC · ⊞ 6.8K ·

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review July 31, 2026 05:19
Copilot AI review requested due to automatic review settings July 31, 2026 05:19
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

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

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

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

No ADR enforcement needed: PR 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 31, 2026

Copy link
Copy Markdown
Contributor Author

Test Quality Sentinel completed test quality analysis.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

PR Code Quality Reviewer completed the code quality review.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

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.

Pull request overview

Centralizes the duplicated REST endpoint type guard in the shared GitHub API helper module.

Changes:

  • Exports isRestEndpoint from github_api_helpers.cjs.
  • Replaces duplicate implementations with shared imports.
  • One JSDoc placement issue requires correction.
Show a summary per file
File Description
actions/setup/js/github_api_helpers.cjs Adds and exports the shared type guard.
actions/setup/js/add_workflow_run_comment.cjs Imports the shared helper.
actions/setup/js/add_reaction_and_edit_comment.cjs Imports the shared helper.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread actions/setup/js/github_api_helpers.cjs Outdated
Comment on lines +156 to +160
/**
* Type guard for a resolved REST endpoint descriptor, shared by handlers that
* choose between a REST call ({route, params}) and a GraphQL/discussion path.
* @param {unknown} endpoint
* @returns {endpoint is { route: string, params: Record<string, unknown> }}

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Skills-Based Review 🧠

Applied /codebase-design — requesting one fix before merge.

📋 Key Themes & Highlights

Issue

  • Orphaned JSDoc: inserting isRestEndpoint between the existing resolveTopLevelDiscussionCommentId JSDoc block and its function body causes JS tooling to attribute those docs to the wrong function. See inline comment for the fix.

Positive Highlights

  • ✅ Clean deduplication — identical function bodies collapsed into a single canonical location
  • ✅ Correct module: github_api_helpers.cjs is the right home for this type guard
  • ✅ Export added in alphabetical order
  • ✅ PR is well-scoped with no behavior change and passing tests

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 21.3 AIC · ⊞ 7K
Comment /matt to run again

Comment thread actions/setup/js/github_api_helpers.cjs Outdated
* @param {string|null|undefined} commentNodeId - The node_id of the triggering comment
* @returns {Promise<string|null|undefined>} The node ID to use as replyToId (parent if reply, otherwise the original)
*/
/**

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/codebase-design] The JSDoc block for resolveTopLevelDiscussionCommentId (lines 146–155) is now orphaned — isRestEndpoint was inserted between it and the function it documents. JS tooling (IDEs, JSDoc, TypeDoc) will associate those @param/@returns docs with isRestEndpoint instead.

💡 Fix: reorder so each JSDoc immediately precedes its function
/**
 * Type guard for a resolved REST endpoint descriptor ...
 * `@param` {unknown} endpoint
 * `@returns` {endpoint is { route: string, params: Record<string, unknown> }}
 */
function isRestEndpoint(endpoint) { ... }

/**
 * Resolves the top-level parent comment node ID ...
 * `@param` {Object} github
 * `@param` {string|null|undefined} commentNodeId
 * `@returns` {Promise<string|null|undefined>}
 */
async function resolveTopLevelDiscussionCommentId(github, commentNodeId) { ... }

@copilot please address this.

@github-actions

Copy link
Copy Markdown
Contributor Author

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

The isRestEndpoint function was inserted between the existing JSDoc block (lines 148–155) and resolveTopLevelDiscussionCommentId, severing the doc from the function it describes. Tools like TypeScript, IDEs, and doc generators will now associate the orphaned JSDoc with isRestEndpoint instead of resolveTopLevelDiscussionCommentId, leaving resolveTopLevelDiscussionCommentId undocumented.

The new isRestEndpoint function (with its own JSDoc) should be placed after resolveTopLevelDiscussionCommentId, or the existing JSDoc block should remain immediately above its function.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 20.4 AIC · ⊞ 5.3K ·

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Review: dedupe isRestEndpoint — one blocking issue

Overall: The refactor is correct — the function body is identical across both callers and the shared placement in github_api_helpers.cjs is the right home for it. However there is one structural bug introduced by the insertion order.

Blocking issue: isRestEndpoint was inserted between the JSDoc block that documents resolveTopLevelDiscussionCommentId and the function itself (lines 155→156→162). This severs the doc comment from its function; TypeScript language services and doc generators will incorrectly attribute it to isRestEndpoint.

Fix: move isRestEndpoint + its JSDoc to after resolveTopLevelDiscussionCommentId, just before the module.exports block, or swap the order so the existing JSDoc sits immediately above its function.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 20.4 AIC · ⊞ 5.3K

Comment thread actions/setup/js/github_api_helpers.cjs Outdated
* @param {unknown} endpoint
* @returns {endpoint is { route: string, params: Record<string, unknown> }}
*/
function isRestEndpoint(endpoint) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

JSDoc detachment bug: The isRestEndpoint function was inserted immediately after the closing */ of the resolveTopLevelDiscussionCommentId JSDoc block, disconnecting that doc from its function. TypeScript/IDEs will associate the stray JSDoc (lines 148–155) with isRestEndpoint instead of resolveTopLevelDiscussionCommentId.

Fix: move isRestEndpoint (and its own JSDoc) to after resolveTopLevelDiscussionCommentId, or keep the existing doc immediately above its function.

@copilot please address this.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Verdict: approve with a minor doc-placement nit

Clean, faithful dedup of isRestEndpoint into the shared helpers module — no behavior change, exports updated correctly.

Themes
  • The moved function's logic is byte-for-byte identical to both prior copies (verified `typeof === "object" && !== null && "route" in && "params" in" checks match).
  • One low-severity issue: the pre-existing JSDoc for resolveTopLevelDiscussionCommentId was left above the newly inserted isRestEndpoint, orphaning both functions' documentation. Flagged inline.
  • No correctness, security, or performance concerns in the diff.

🔎 Code quality review by PR Code Quality Reviewer · auto · 63.5 AIC · ⊞ 7.8K
Comment /review to run again

Comment thread actions/setup/js/github_api_helpers.cjs Outdated
* @param {string|null|undefined} commentNodeId - The node_id of the triggering comment
* @returns {Promise<string|null|undefined>} The node ID to use as replyToId (parent if reply, otherwise the original)
*/
/**

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

JSDoc placement bug: the pre-existing doc comment for resolveTopLevelDiscussionCommentId now sits above the new isRestEndpoint function instead of its intended target.

💡 Details

The comment block describing commentNodeId/return value was left directly above the inserted isRestEndpoint function, so isRestEndpoint inherits an unrelated JSDoc (talking about github/commentNodeId params it does not have), while resolveTopLevelDiscussionCommentId loses its own documentation entirely. This breaks IDE tooltips/intellisense for both functions.

Fix: move the new isRestEndpoint JSDoc above its own function, and keep the old JSDoc directly above resolveTopLevelDiscussionCommentId.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

…CommentId by relocating isRestEndpoint

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

@copilot run pr-finisher skill

Fixed in the latest commit. Moved isRestEndpoint (with its JSDoc) to after resolveTopLevelDiscussionCommentId, so each JSDoc block is immediately followed by its corresponding function declaration. All 124 tests pass.

Copilot AI requested a review from pelikhan July 31, 2026 05:47
@pelikhan
pelikhan merged commit 74168bf into main Jul 31, 2026
8 checks passed
@pelikhan
pelikhan deleted the code-simplifier/dedupe-isrestendpoint-c9d34ff9b0e34ad3 branch July 31, 2026 05:52
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v0.84.1

@github-actions github-actions Bot mentioned this pull request Jul 31, 2026
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.

3 participants