diff --git a/actions/setup/js/add_reaction_and_edit_comment.cjs b/actions/setup/js/add_reaction_and_edit_comment.cjs index 2afd53e5f58..4773b8aa7b4 100644 --- a/actions/setup/js/add_reaction_and_edit_comment.cjs +++ b/actions/setup/js/add_reaction_and_edit_comment.cjs @@ -7,7 +7,7 @@ const { generateWorkflowIdMarker } = require("./generate_footer.cjs"); const { sanitizeContent } = require("./sanitize_content.cjs"); const { ERR_API, ERR_NOT_FOUND, ERR_VALIDATION } = require("./error_codes.cjs"); const { buildWorkflowRunUrl, EVENT_TYPE_DESCRIPTIONS } = require("./workflow_metadata_helpers.cjs"); -const { createDiscussionComment, resolveTopLevelDiscussionCommentId } = require("./github_api_helpers.cjs"); +const { createDiscussionComment, isRestEndpoint, resolveTopLevelDiscussionCommentId } = require("./github_api_helpers.cjs"); const { resolveInvocationContext } = require("./invocation_context_helpers.cjs"); const { addReaction, addDiscussionReaction, getDiscussionNodeId, REACTION_MAP } = require("./add_reaction.cjs"); @@ -18,14 +18,6 @@ const VALID_REACTIONS = Object.freeze(Object.keys(REACTION_MAP)); * @typedef {{ route: string, params: Record }} RestEndpoint */ -/** - * @param {unknown} endpoint - * @returns {endpoint is RestEndpoint} - */ -function isRestEndpoint(endpoint) { - return typeof endpoint === "object" && endpoint !== null && "route" in endpoint && "params" in endpoint; -} - /** * @param {unknown} endpoint * @param {string} endpointName diff --git a/actions/setup/js/add_workflow_run_comment.cjs b/actions/setup/js/add_workflow_run_comment.cjs index 192e8fb556e..e37e5c9e3d7 100644 --- a/actions/setup/js/add_workflow_run_comment.cjs +++ b/actions/setup/js/add_workflow_run_comment.cjs @@ -9,17 +9,9 @@ const { ERR_NOT_FOUND, ERR_VALIDATION } = require("./error_codes.cjs"); const { getMessages } = require("./messages_core.cjs"); const { parseBoolTemplatable } = require("./templatable.cjs"); const { buildWorkflowRunUrl, EVENT_TYPE_DESCRIPTIONS } = require("./workflow_metadata_helpers.cjs"); -const { resolveTopLevelDiscussionCommentId } = require("./github_api_helpers.cjs"); +const { isRestEndpoint, resolveTopLevelDiscussionCommentId } = require("./github_api_helpers.cjs"); const { resolveInvocationContext } = require("./invocation_context_helpers.cjs"); -/** - * @param {unknown} endpoint - * @returns {endpoint is { route: string, params: Record }} - */ -function isRestEndpoint(endpoint) { - return typeof endpoint === "object" && endpoint !== null && "route" in endpoint && "params" in endpoint; -} - /** * @typedef {{ owner: string, repo: string }} RepoRef * @typedef {{ id: string, url: string, repo: RepoRef }} CommentMetadata diff --git a/actions/setup/js/github_api_helpers.cjs b/actions/setup/js/github_api_helpers.cjs index 7f4020ef363..413e6341716 100644 --- a/actions/setup/js/github_api_helpers.cjs +++ b/actions/setup/js/github_api_helpers.cjs @@ -177,6 +177,16 @@ async function resolveTopLevelDiscussionCommentId(github, commentNodeId) { } } +/** + * 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 }} + */ +function isRestEndpoint(endpoint) { + return typeof endpoint === "object" && endpoint !== null && "route" in endpoint && "params" in endpoint; +} + /** * Create a discussion comment with optional threaded reply target. * @param {Object} github - GitHub API client (must support graphql) @@ -217,6 +227,7 @@ module.exports = { createDiscussionComment, fetchAllRepoLabels, getFileContent, + isRestEndpoint, logGraphQLError, resolveTopLevelDiscussionCommentId, };