Skip to content

Commit eb6dc28

Browse files
chore: sync actions from [email protected] (#179)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 3fac1cf commit eb6dc28

133 files changed

Lines changed: 2223 additions & 771 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎setup/js/add_comment.cjs‎

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const { getMessages } = require("./messages_core.cjs");
2020
const { getBodyHeader } = require("./messages_header.cjs");
2121
const { sanitizeContent } = require("./sanitize_content.cjs");
2222
const { MAX_COMMENT_LENGTH, MAX_MENTIONS, MAX_LINKS, enforceCommentLimits } = require("./comment_limit_helpers.cjs");
23-
const { resolveTopLevelDiscussionCommentId } = require("./github_api_helpers.cjs");
23+
const { createDiscussionComment, resolveTopLevelDiscussionCommentId } = require("./github_api_helpers.cjs");
2424
const { logStagedPreviewInfo } = require("./staged_preview.cjs");
2525
const { ERR_NOT_FOUND } = require("./error_codes.cjs");
2626
const { isPayloadUserBot } = require("./resolve_mentions.cjs");
@@ -379,33 +379,7 @@ async function commentOnDiscussion(github, owner, repo, discussionNumber, messag
379379
const discussionUrl = repository.discussion.url;
380380

381381
// 2. Add comment (with optional replyToId for threading)
382-
const mutation = replyToId
383-
? /* GraphQL */ `
384-
mutation ($dId: ID!, $body: String!, $replyToId: ID!) {
385-
addDiscussionComment(input: { discussionId: $dId, body: $body, replyToId: $replyToId }) {
386-
comment {
387-
id
388-
url
389-
}
390-
}
391-
}
392-
`
393-
: /* GraphQL */ `
394-
mutation ($dId: ID!, $body: String!) {
395-
addDiscussionComment(input: { discussionId: $dId, body: $body }) {
396-
comment {
397-
id
398-
url
399-
}
400-
}
401-
}
402-
`;
403-
404-
const variables = { dId: discussionId, body: message, ...(replyToId ? { replyToId } : {}) };
405-
406-
const result = await github.graphql(mutation, variables);
407-
408-
const comment = result.addDiscussionComment.comment;
382+
const comment = await createDiscussionComment(github, discussionId, message, replyToId);
409383

410384
return {
411385
id: comment.id,

‎setup/js/add_reaction.cjs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ async function main() {
3030
core.info(`Adding reaction: ${reaction}`);
3131

3232
// Validate reaction type
33-
const validReactions = Object.keys(REACTION_MAP);
34-
if (!validReactions.includes(reaction)) {
35-
core.setFailed(`${ERR_VALIDATION}: Invalid reaction type: ${reaction}. Valid reactions are: ${validReactions.join(", ")}`);
33+
if (!Object.prototype.hasOwnProperty.call(REACTION_MAP, reaction)) {
34+
core.setFailed(`${ERR_VALIDATION}: Invalid reaction type: ${reaction}. Valid reactions are: ${Object.keys(REACTION_MAP).join(", ")}`);
3635
return;
3736
}
3837

‎setup/js/add_reaction_and_edit_comment.cjs‎

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const { generateWorkflowIdMarker } = require("./generate_footer.cjs");
77
const { sanitizeContent } = require("./sanitize_content.cjs");
88
const { ERR_API, ERR_NOT_FOUND, ERR_VALIDATION } = require("./error_codes.cjs");
99
const { buildWorkflowRunUrl } = require("./workflow_metadata_helpers.cjs");
10-
const { resolveTopLevelDiscussionCommentId } = require("./github_api_helpers.cjs");
10+
const { createDiscussionComment, resolveTopLevelDiscussionCommentId } = require("./github_api_helpers.cjs");
1111
const { resolveInvocationContext } = require("./invocation_context_helpers.cjs");
12-
const { addReaction, addDiscussionReaction, getDiscussionNodeId } = require("./add_reaction.cjs");
12+
const { addReaction, addDiscussionReaction, getDiscussionNodeId, REACTION_MAP } = require("./add_reaction.cjs");
1313

1414
/**
1515
* Event type descriptions for comment messages
@@ -25,7 +25,7 @@ const EVENT_TYPE_DESCRIPTIONS = {
2525
};
2626

2727
/** Valid GitHub reaction types */
28-
const VALID_REACTIONS = Object.freeze(["+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", "eyes"]);
28+
const VALID_REACTIONS = Object.freeze(Object.keys(REACTION_MAP));
2929

3030
/**
3131
* Resolve the reaction and comment API endpoints for a given event.
@@ -140,7 +140,14 @@ async function resolveEventEndpoints(eventName, owner, repo, payload) {
140140
async function main() {
141141
const reaction = process.env.GH_AW_REACTION || "eyes";
142142
const commandsJSON = process.env.GH_AW_COMMANDS;
143-
const command = commandsJSON ? (JSON.parse(commandsJSON)[0] ?? null) : null; // Only present for command workflows
143+
let command = null; // Only present for command workflows
144+
if (commandsJSON) {
145+
try {
146+
command = JSON.parse(commandsJSON)[0] ?? null;
147+
} catch (err) {
148+
throw new Error("Failed to parse GH_AW_COMMANDS: " + getErrorMessage(err), { cause: err });
149+
}
150+
}
144151
const invocationContext = resolveInvocationContext(context);
145152
const runUrl = buildWorkflowRunUrl(context, invocationContext.workflowRepo);
146153

@@ -250,19 +257,7 @@ async function addCommentWithWorkflowLink(endpoint, runUrl, eventName, invocatio
250257
// For discussion_comment events, thread the reply under the triggering comment.
251258
// GitHub Discussions only supports two nesting levels, so resolve the top-level parent node ID.
252259
const replyToId = eventName === "discussion_comment" ? await resolveTopLevelDiscussionCommentId(github, eventPayload?.comment?.node_id) : null;
253-
const mutation = replyToId
254-
? `mutation($dId: ID!, $body: String!, $replyToId: ID!) {
255-
addDiscussionComment(input: { discussionId: $dId, body: $body, replyToId: $replyToId }) {
256-
comment { id url }
257-
}
258-
}`
259-
: `mutation($dId: ID!, $body: String!) {
260-
addDiscussionComment(input: { discussionId: $dId, body: $body }) {
261-
comment { id url }
262-
}
263-
}`;
264-
const result = await github.graphql(mutation, { dId: discussionId, body: commentBody, ...(replyToId ? { replyToId } : {}) });
265-
const comment = result.addDiscussionComment.comment;
260+
const comment = await createDiscussionComment(github, discussionId, commentBody, replyToId);
266261
setCommentOutputs(comment.id, comment.url, eventRepo);
267262
return;
268263
}

‎setup/js/apply_safe_outputs_replay.cjs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ async function downloadAgentArtifact(runId, destDir, repoSlug) {
100100
*/
101101
function buildHandlerConfigFromOutput(agentOutputFile) {
102102
const content = fs.readFileSync(agentOutputFile, "utf8");
103-
const validatedOutput = JSON.parse(content);
103+
let validatedOutput;
104+
try {
105+
validatedOutput = JSON.parse(content);
106+
} catch (err) {
107+
throw new Error("Failed to parse agent output file " + agentOutputFile + ": " + getErrorMessage(err), { cause: err });
108+
}
104109

105110
if (!validatedOutput.items || !Array.isArray(validatedOutput.items)) {
106111
core.info("No items found in agent output; handler config will be empty");

‎setup/js/artifact_client.cjs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const { Readable } = require("stream");
1515
const { pipeline } = require("stream/promises");
1616
const { spawnSync } = require("child_process");
1717

18+
const { getErrorMessage } = require("./error_helpers.cjs");
19+
1820
const DEFAULT_RETRY_ATTEMPTS = 5;
1921
const RETRY_DELAY_MS = 5000;
2022
const RESULTS_SCOPE_PREFIX = "Actions.Results:";
@@ -33,7 +35,13 @@ function decodeJWTPayload(token) {
3335
}
3436
const payload = parts[1].replace(/-/g, "+").replace(/_/g, "/");
3537
const padded = payload + "=".repeat((4 - (payload.length % 4 || 4)) % 4);
36-
return JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
38+
let parsed;
39+
try {
40+
parsed = JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
41+
} catch (err) {
42+
throw new Error("Failed to parse JWT payload: " + getErrorMessage(err), { cause: err });
43+
}
44+
return parsed;
3745
}
3846

3947
function getBackendIdsFromRuntimeToken() {

‎setup/js/assign_copilot_to_created_issues.cjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function main() {
5454
const repoSlug = parts[0];
5555
const issueNumber = parseInt(parts[1], 10);
5656

57-
if (isNaN(issueNumber) || issueNumber <= 0) {
57+
if (Number.isNaN(issueNumber) || issueNumber <= 0) {
5858
core.warning(`Invalid issue number in entry: ${entry}`);
5959
continue;
6060
}

‎setup/js/assign_milestone.cjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ async function main(config = {}) {
183183

184184
let milestoneNumber = Number(item.milestone_number);
185185
const milestoneTitle = item.milestone_title || null;
186-
const hasMilestoneNumber = !isNaN(milestoneNumber) && milestoneNumber > 0;
186+
const hasMilestoneNumber = !Number.isNaN(milestoneNumber) && milestoneNumber > 0;
187187

188188
// Validate that at least one of milestone_number or milestone_title is provided
189189
if (!hasMilestoneNumber && !milestoneTitle) {

‎setup/js/assign_to_agent.cjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function createAssignToAgentGitHubClient(config) {
5454
async function main(config = {}) {
5555
// Parse configuration (replaces env vars from the old standalone step)
5656
const maxCount = parseInt(String(config.max ?? "1"), 10);
57-
if (isNaN(maxCount) || maxCount < 1) {
57+
if (Number.isNaN(maxCount) || maxCount < 1) {
5858
throw new Error(`Invalid max value: ${config.max}. Must be a positive integer`);
5959
}
6060
const defaultAgent = String(config.name ?? "copilot").trim();
@@ -299,7 +299,7 @@ async function main(config = {}) {
299299
const issueNumber = type === "issue" ? number : null;
300300
const pullNumber = type === "pull request" ? number : null;
301301

302-
if (isNaN(number) || number <= 0) {
302+
if (Number.isNaN(number) || number <= 0) {
303303
const error = `Invalid ${type} number: ${number}`;
304304
core.error(error);
305305
_allResults.push({ issue_number: issueNumber, pull_number: pullNumber, agent: agentName, owner: effectiveOwner, repo: effectiveRepo, success: false, error });

‎setup/js/autofix_code_scanning_alert.cjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async function main(config = {}) {
6464

6565
// Parse alert number
6666
const alertNumber = parseInt(String(message.alert_number), 10);
67-
if (isNaN(alertNumber) || alertNumber <= 0) {
67+
if (Number.isNaN(alertNumber) || alertNumber <= 0) {
6868
core.warning(`Invalid alert_number: ${message.alert_number}`);
6969
return { success: false, error: `Invalid alert_number: ${message.alert_number}` };
7070
}

0 commit comments

Comments
 (0)