Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 5 additions & 55 deletions actions/setup/js/close_issue.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const { resolveTargetRepoConfig, resolveAndValidateRepo, validateRepo } = require("./repo_helpers.cjs");
const { createAuthenticatedGitHubClient } = require("./handler_auth.cjs");
const { ERR_NOT_FOUND } = require("./error_codes.cjs");
const { getIssueDetails, addIssueThreadComment, closeIssue: closeIssueRest } = require("./close_rest_helpers.cjs");
const { createCloseEntityHandler, buildCommentBody, ISSUE_CONFIG } = require("./close_entity_helpers.cjs");
const { loadTemporaryIdMapFromResolved, resolveRepoIssueTarget } = require("./temporary_id.cjs");
const { getErrorMessage } = require("./error_helpers.cjs");
Expand Down Expand Up @@ -107,48 +107,6 @@ async function markIssueAsDuplicate(github, duplicateNodeId, canonicalOwner, can
);
}

/**
* Get issue details using REST API
* @param {any} github - GitHub REST API instance
* @param {string} owner - Repository owner
* @param {string} repo - Repository name
* @param {number} issueNumber - Issue number
* @returns {Promise<{number: number, title: string, labels: Array<{name: string}>, html_url: string, state: string}>} Issue details
*/
async function getIssueDetails(github, owner, repo, issueNumber) {
const { data: issue } = await github.rest.issues.get({
owner,
repo,
issue_number: issueNumber,
});

if (!issue) {
throw new Error(`${ERR_NOT_FOUND}: Issue #${issueNumber} not found in ${owner}/${repo}`);
}

return issue;
}

/**
* Add comment to a GitHub Issue using REST API
* @param {any} github - GitHub REST API instance
* @param {string} owner - Repository owner
* @param {string} repo - Repository name
* @param {number} issueNumber - Issue number
* @param {string} message - Comment body
* @returns {Promise<{id: number, html_url: string}>} Comment details
*/
async function addIssueComment(github, owner, repo, issueNumber, message) {
const { data: comment } = await github.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: message,
});

return comment;
}

/**
* Close a GitHub Issue using REST API
* @param {any} github - GitHub REST API instance
Expand All @@ -159,13 +117,7 @@ async function addIssueComment(github, owner, repo, issueNumber, message) {
* @returns {Promise<{number: number, html_url: string, title: string, node_id: string}>} Issue details
*/
async function closeIssue(github, owner, repo, issueNumber, stateReason, intentMetadata, useIssueIntent) {
const baseParams = {
owner,
repo,
issue_number: issueNumber,
state: "closed",
state_reason: (stateReason || "COMPLETED").toLowerCase(),
};
const normalizedStateReason = (stateReason || "COMPLETED").toLowerCase();

const hasIntentMetadata = Boolean(intentMetadata && Object.keys(intentMetadata).length > 0);
if (useIssueIntent && hasIntentMetadata) {
Expand All @@ -175,17 +127,15 @@ async function closeIssue(github, owner, repo, issueNumber, stateReason, intentM
repo,
issue_number: issueNumber,
state: { value: "closed", ...intentMetadata },
state_reason: baseParams.state_reason,
state_reason: normalizedStateReason,
});
return issue;
} catch (error) {
core.warning(`Issue-intent close path unavailable, falling back to legacy close path: ${getErrorMessage(error)}`);
}
}

const { data: issue } = await github.rest.issues.update(baseParams);

return issue;
return await closeIssueRest(github, owner, repo, issueNumber, normalizedStateReason);
}

/**
Expand Down Expand Up @@ -302,7 +252,7 @@ async function main(config = {}) {
return buildCommentBody(sanitizedBody, triggeringIssueNumber, triggeringPRNumber);
},

addComment: addIssueComment,
addComment: addIssueThreadComment,

closeEntity(github, owner, repo, entityNumber, item) {
// Determine effective state_reason, validating against permitted values when applicable.
Expand Down
32 changes: 11 additions & 21 deletions actions/setup/js/close_older_issues.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// <reference types="@actions/github-script" />

const { sanitizeContent } = require("./sanitize_content.cjs");
const { addIssueThreadComment, closeIssue } = require("./close_rest_helpers.cjs");
const { closeOlderEntities, MAX_CLOSE_COUNT: SHARED_MAX_CLOSE_COUNT } = require("./close_older_entities.cjs");
const { searchOlderEntitiesByMarker } = require("./close_older_search_helpers.cjs");

Expand Down Expand Up @@ -81,19 +82,14 @@ async function addIssueComment(github, owner, repo, issueNumber, message) {
core.info(`Adding comment to issue #${issueNumber} in ${owner}/${repo}`);
core.info(` Comment length: ${message.length} characters`);

const result = await github.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: sanitizeContent(message),
});
const comment = await addIssueThreadComment(github, owner, repo, issueNumber, sanitizeContent(message));

core.info(` ✓ Comment created successfully with ID: ${result.data.id}`);
core.info(` Comment URL: ${result.data.html_url}`);
core.info(` ✓ Comment created successfully with ID: ${comment.id}`);
core.info(` Comment URL: ${comment.html_url}`);

return {
id: result.data.id,
html_url: result.data.html_url,
id: comment.id,
html_url: comment.html_url,
};
}

Expand All @@ -108,20 +104,14 @@ async function addIssueComment(github, owner, repo, issueNumber, message) {
async function closeIssueAsNotPlanned(github, owner, repo, issueNumber) {
core.info(`Closing issue #${issueNumber} in ${owner}/${repo} as "not planned"`);

const result = await github.rest.issues.update({
owner,
repo,
issue_number: issueNumber,
state: "closed",
state_reason: "not_planned",
});
const issue = await closeIssue(github, owner, repo, issueNumber, "not_planned");

core.info(` ✓ Issue #${result.data.number} closed successfully`);
core.info(` Issue URL: ${result.data.html_url}`);
core.info(` ✓ Issue #${issue.number} closed successfully`);
core.info(` Issue URL: ${issue.html_url}`);

return {
number: result.data.number,
html_url: result.data.html_url,
number: issue.number,
html_url: issue.html_url,
};
}

Expand Down
31 changes: 11 additions & 20 deletions actions/setup/js/close_older_pull_requests.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// <reference types="@actions/github-script" />

const { sanitizeContent } = require("./sanitize_content.cjs");
const { addIssueThreadComment, closePullRequest: closePullRequestRest } = require("./close_rest_helpers.cjs");
const { closeOlderEntities, MAX_CLOSE_COUNT: SHARED_MAX_CLOSE_COUNT } = require("./close_older_entities.cjs");
const { searchOlderEntitiesByMarker } = require("./close_older_search_helpers.cjs");

Expand Down Expand Up @@ -78,19 +79,14 @@ async function addPullRequestComment(github, owner, repo, prNumber, message) {
core.info(`Adding comment to pull request #${prNumber} in ${owner}/${repo}`);
core.info(` Comment length: ${message.length} characters`);

const result = await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: sanitizeContent(message),
});
const comment = await addIssueThreadComment(github, owner, repo, prNumber, sanitizeContent(message));

core.info(` ✓ Comment created successfully with ID: ${result.data.id}`);
core.info(` Comment URL: ${result.data.html_url}`);
core.info(` ✓ Comment created successfully with ID: ${comment.id}`);
core.info(` Comment URL: ${comment.html_url}`);

return {
id: result.data.id,
html_url: result.data.html_url,
id: comment.id,
html_url: comment.html_url,
};
}

Expand All @@ -105,19 +101,14 @@ async function addPullRequestComment(github, owner, repo, prNumber, message) {
async function closePullRequest(github, owner, repo, prNumber) {
core.info(`Closing pull request #${prNumber} in ${owner}/${repo}`);

const result = await github.rest.pulls.update({
owner,
repo,
pull_number: prNumber,
state: "closed",
});
const pr = await closePullRequestRest(github, owner, repo, prNumber);

core.info(` ✓ Pull request #${result.data.number} closed successfully`);
core.info(` Pull request URL: ${result.data.html_url}`);
core.info(` ✓ Pull request #${pr.number} closed successfully`);
core.info(` Pull request URL: ${pr.html_url}`);

return {
number: result.data.number,
html_url: result.data.html_url,
number: pr.number,
html_url: pr.html_url,
};
}

Expand Down
65 changes: 2 additions & 63 deletions actions/setup/js/close_pull_request.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,14 @@
/// <reference types="@actions/github-script" />

const { createAuthenticatedGitHubClient } = require("./handler_auth.cjs");
const { ERR_NOT_FOUND } = require("./error_codes.cjs");
const { getPullRequestDetails, addIssueThreadComment, closePullRequest } = require("./close_rest_helpers.cjs");
const { createCloseEntityHandler, checkLabelFilter, buildCommentBody, PULL_REQUEST_CONFIG } = require("./close_entity_helpers.cjs");
const { resolveTargetRepoConfig, resolveAndValidateRepo } = require("./repo_helpers.cjs");

/**
* @typedef {import('./types/handler-factory').HandlerFactoryFunction} HandlerFactoryFunction
*/

/**
* Get pull request details using REST API
* @param {any} github - GitHub REST API instance
* @param {string} owner - Repository owner
* @param {string} repo - Repository name
* @param {number} prNumber - Pull request number
* @returns {Promise<{number: number, title: string, labels: Array<{name: string}>, html_url: string, state: string}>} Pull request details
*/
async function getPullRequestDetails(github, owner, repo, prNumber) {
const { data: pr } = await github.rest.pulls.get({
owner,
repo,
pull_number: prNumber,
});

if (!pr) {
throw new Error(`${ERR_NOT_FOUND}: Pull request #${prNumber} not found in ${owner}/${repo}`);
}

return pr;
}

/**
* Add comment to a GitHub Pull Request using REST API
* @param {any} github - GitHub REST API instance
* @param {string} owner - Repository owner
* @param {string} repo - Repository name
* @param {number} prNumber - Pull request number
* @param {string} message - Comment body
* @returns {Promise<{id: number, html_url: string}>} Comment details
*/
async function addPullRequestComment(github, owner, repo, prNumber, message) {
const { data: comment } = await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: message,
});

return comment;
}

/**
* Close a GitHub Pull Request using REST API
* @param {any} github - GitHub REST API instance
* @param {string} owner - Repository owner
* @param {string} repo - Repository name
* @param {number} prNumber - Pull request number
* @returns {Promise<{number: number, html_url: string, title: string}>} Pull request details
*/
async function closePullRequest(github, owner, repo, prNumber) {
const { data: pr } = await github.rest.pulls.update({
owner,
repo,
pull_number: prNumber,
state: "closed",
});

return pr;
}

/**
* Handler factory for close-pull-request safe outputs
* @type {HandlerFactoryFunction}
Expand Down Expand Up @@ -142,7 +81,7 @@ async function main(config = {}) {
return buildCommentBody(sanitizedBody, triggeringIssueNumber, triggeringPRNumber);
},

addComment: addPullRequestComment,
addComment: addIssueThreadComment,

closeEntity(github, owner, repo, prNumber) {
core.info(`Closing PR #${prNumber} in ${owner}/${repo}`);
Expand Down
Loading
Loading