Skip to content

Commit a5d8b7d

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

70 files changed

Lines changed: 999 additions & 263 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/action_setup_otlp.cjs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ const { getActionInput } = require("./action_input_utils.cjs");
4040
*/
4141
function writeEnvLine(filePath, key, value, logLabel, fileLabel) {
4242
if (!filePath || !value) return;
43-
appendFileSync(filePath, `${key}=${value}\n`);
44-
console.log(`[otlp] ${logLabel} written to ${fileLabel}`);
43+
try {
44+
appendFileSync(filePath, `${key}=${value}\n`);
45+
console.log(`[otlp] ${logLabel} written to ${fileLabel}`);
46+
} catch {
47+
/* ignore */
48+
}
4549
}
4650

4751
/**

‎setup/js/add_labels.cjs‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ const main = createCountGatedHandler({
4444
handlerType: HANDLER_TYPE,
4545
setup: async (config, maxCount, isStaged) => {
4646
const { allowed: allowedLabels = [], blocked: blockedPatterns = [] } = config;
47-
const issueIntentEnabled = config.issue_intent === true;
47+
const issueIntentEnabled = config.issue_intent !== false;
48+
const issueIntentStrict = config.issue_intent === true; // strict mode: plain-string labels rejected, metadata required
4849
const requiredLabels = Array.isArray(config.required_labels) ? config.required_labels : [];
4950
const requiredTitlePrefix = config.required_title_prefix || "";
5051
const { defaultTargetRepo, allowedRepos } = resolveTargetRepoConfig(config);
@@ -98,6 +99,24 @@ const main = createCountGatedHandler({
9899
let requestedLabelNames;
99100
try {
100101
const requestedLabelInputs = normalizeIssueIntentLabelInputs(requestedLabels);
102+
103+
// In strict mode (issue_intent: true), reject plain string labels — metadata is required
104+
if (issueIntentStrict) {
105+
const plainStringLabels = requestedLabelInputs.filter(label => typeof label === "string");
106+
if (plainStringLabels.length > 0) {
107+
const error = `Plain string label names are not permitted when issue_intent is explicitly enabled. Provide label objects with a "name" field and intent metadata (rationale, confidence). Plain labels: ${plainStringLabels.map(l => JSON.stringify(l)).join(", ")}`;
108+
core.warning(error);
109+
return { success: false, error };
110+
}
111+
// In strict mode, objects without rationale and confidence are also rejected
112+
const missingMetadataLabels = requestedLabelInputs.filter(label => typeof label === "object" && (!label.rationale || !label.confidence));
113+
if (missingMetadataLabels.length > 0) {
114+
const error = `Label objects must include both "rationale" and "confidence" when issue_intent is explicitly enabled. Missing metadata on: ${missingMetadataLabels.map(l => JSON.stringify(l.name)).join(", ")}`;
115+
core.warning(error);
116+
return { success: false, error };
117+
}
118+
}
119+
101120
requestedLabelNames = requestedLabelInputs.map(label => {
102121
if (typeof label === "string") {
103122
return label;

‎setup/js/add_reaction.cjs‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function main() {
4141
const { owner, repo } = invocationContext.eventRepo;
4242
const payload = invocationContext.eventPayload;
4343

44-
/** @type {string | null} */
44+
/** @type {{ route: string, params: Record<string, unknown> } | null} */
4545
const reactionEndpoint = resolveRestEndpoint(eventName, owner, repo, payload);
4646

4747
if (reactionEndpoint === null) {
@@ -52,22 +52,22 @@ async function main() {
5252
return;
5353
}
5454

55-
core.info(`Adding reaction to: ${reactionEndpoint}`);
55+
core.info(`Adding reaction to: ${reactionEndpoint.route}`);
5656
try {
57-
await addReaction(reactionEndpoint, reaction);
57+
await addReaction(reactionEndpoint.route, reactionEndpoint.params, reaction);
5858
} catch (error) {
5959
handleReactionError(error);
6060
}
6161
}
6262

6363
/**
64-
* Resolve the REST API endpoint for non-discussion events.
64+
* Resolve the REST API route and params for non-discussion events.
6565
* Returns null for discussion/discussion_comment/pull_request_review/unsupported events (handled separately).
6666
* @param {string} eventName
6767
* @param {string} owner
6868
* @param {string} repo
6969
* @param {Record<string, any>} payload
70-
* @returns {string | null}
70+
* @returns {{ route: string, params: Record<string, unknown> } | null}
7171
*/
7272
function resolveRestEndpoint(eventName, owner, repo, payload) {
7373
switch (eventName) {
@@ -77,7 +77,7 @@ function resolveRestEndpoint(eventName, owner, repo, payload) {
7777
core.setFailed(`${ERR_NOT_FOUND}: Issue number not found in event payload`);
7878
return null;
7979
}
80-
return `/repos/${owner}/${repo}/issues/${issueNumber}/reactions`;
80+
return { route: "POST /repos/{owner}/{repo}/issues/{issue_number}/reactions", params: { owner, repo, issue_number: issueNumber } };
8181
}
8282

8383
case "issue_comment": {
@@ -86,7 +86,7 @@ function resolveRestEndpoint(eventName, owner, repo, payload) {
8686
core.setFailed(`${ERR_VALIDATION}: Comment ID not found in event payload`);
8787
return null;
8888
}
89-
return `/repos/${owner}/${repo}/issues/comments/${commentId}/reactions`;
89+
return { route: "POST /repos/{owner}/{repo}/issues/comments/{comment_id}/reactions", params: { owner, repo, comment_id: commentId } };
9090
}
9191

9292
case "pull_request": {
@@ -96,7 +96,7 @@ function resolveRestEndpoint(eventName, owner, repo, payload) {
9696
return null;
9797
}
9898
// PRs are "issues" for the reactions endpoint
99-
return `/repos/${owner}/${repo}/issues/${prNumber}/reactions`;
99+
return { route: "POST /repos/{owner}/{repo}/issues/{issue_number}/reactions", params: { owner, repo, issue_number: prNumber } };
100100
}
101101

102102
case "pull_request_review_comment": {
@@ -105,7 +105,7 @@ function resolveRestEndpoint(eventName, owner, repo, payload) {
105105
core.setFailed(`${ERR_VALIDATION}: Review comment ID not found in event payload`);
106106
return null;
107107
}
108-
return `/repos/${owner}/${repo}/pulls/comments/${reviewCommentId}/reactions`;
108+
return { route: "POST /repos/{owner}/{repo}/pulls/comments/{comment_id}/reactions", params: { owner, repo, comment_id: reviewCommentId } };
109109
}
110110

111111
case "pull_request_review":
@@ -186,11 +186,13 @@ function handleReactionError(error) {
186186

187187
/**
188188
* Add a reaction to a GitHub issue, PR, or comment using REST API
189-
* @param {string} endpoint - The GitHub API endpoint to add the reaction to
189+
* @param {string} route - The typed GitHub API route string (e.g. "POST /repos/{owner}/{repo}/issues/{issue_number}/reactions")
190+
* @param {Record<string, unknown>} params - The route parameters (owner, repo, issue_number, etc.)
190191
* @param {string} reaction - The reaction type to add
191192
*/
192-
async function addReaction(endpoint, reaction) {
193-
const response = await github.request(`POST ${endpoint}`, {
193+
async function addReaction(route, params, reaction) {
194+
const response = await github.request(route, {
195+
...params,
194196
content: reaction,
195197
headers: {
196198
Accept: "application/vnd.github+json",

‎setup/js/add_reaction_and_edit_comment.cjs‎

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,39 @@ const EVENT_TYPE_DESCRIPTIONS = {
2727
/** Valid GitHub reaction types */
2828
const VALID_REACTIONS = Object.freeze(Object.keys(REACTION_MAP));
2929

30+
/**
31+
* @typedef {{ route: string, params: Record<string, unknown> }} RestEndpoint
32+
*/
33+
34+
/**
35+
* @param {unknown} endpoint
36+
* @returns {endpoint is RestEndpoint}
37+
*/
38+
function isRestEndpoint(endpoint) {
39+
return typeof endpoint === "object" && endpoint !== null && "route" in endpoint && "params" in endpoint;
40+
}
41+
42+
/**
43+
* @param {unknown} endpoint
44+
* @param {string} endpointName
45+
* @param {string} eventName
46+
* @returns {RestEndpoint}
47+
*/
48+
function expectRestEndpoint(endpoint, endpointName, eventName) {
49+
if (!isRestEndpoint(endpoint)) {
50+
throw new Error(`${ERR_VALIDATION}: Unexpected ${endpointName} endpoint shape for event: ${eventName}`);
51+
}
52+
return endpoint;
53+
}
54+
3055
/**
3156
* Resolve the reaction and comment API endpoints for a given event.
3257
* Returns null (after calling core.setFailed) when the event or payload is invalid.
3358
* @param {string} eventName - The GitHub event name
3459
* @param {string} owner - Repository owner
3560
* @param {string} repo - Repository name
3661
* @param {Record<string, any>} payload - The event payload
37-
* @returns {Promise<{reactionEndpoint: string, commentUpdateEndpoint: string} | null>}
62+
* @returns {Promise<{reactionEndpoint: { route: string, params: Record<string, unknown> } | string, commentUpdateEndpoint: { route: string, params: Record<string, unknown> } | string} | null>}
3863
*/
3964
async function resolveEventEndpoints(eventName, owner, repo, payload) {
4065
switch (eventName) {
@@ -45,8 +70,8 @@ async function resolveEventEndpoints(eventName, owner, repo, payload) {
4570
return null;
4671
}
4772
return {
48-
reactionEndpoint: `/repos/${owner}/${repo}/issues/${issueNumber}/reactions`,
49-
commentUpdateEndpoint: `/repos/${owner}/${repo}/issues/${issueNumber}/comments`,
73+
reactionEndpoint: { route: "POST /repos/{owner}/{repo}/issues/{issue_number}/reactions", params: { owner, repo, issue_number: issueNumber } },
74+
commentUpdateEndpoint: { route: "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", params: { owner, repo, issue_number: issueNumber } },
5075
};
5176
}
5277

@@ -62,9 +87,9 @@ async function resolveEventEndpoints(eventName, owner, repo, payload) {
6287
return null;
6388
}
6489
return {
65-
reactionEndpoint: `/repos/${owner}/${repo}/issues/comments/${commentId}/reactions`,
90+
reactionEndpoint: { route: "POST /repos/{owner}/{repo}/issues/comments/{comment_id}/reactions", params: { owner, repo, comment_id: commentId } },
6691
// Create new comment on the issue itself, not on the comment
67-
commentUpdateEndpoint: `/repos/${owner}/${repo}/issues/${issueNumber}/comments`,
92+
commentUpdateEndpoint: { route: "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", params: { owner, repo, issue_number: issueNumber } },
6893
};
6994
}
7095

@@ -76,8 +101,8 @@ async function resolveEventEndpoints(eventName, owner, repo, payload) {
76101
}
77102
// PRs are "issues" for the reactions endpoint
78103
return {
79-
reactionEndpoint: `/repos/${owner}/${repo}/issues/${prNumber}/reactions`,
80-
commentUpdateEndpoint: `/repos/${owner}/${repo}/issues/${prNumber}/comments`,
104+
reactionEndpoint: { route: "POST /repos/{owner}/{repo}/issues/{issue_number}/reactions", params: { owner, repo, issue_number: prNumber } },
105+
commentUpdateEndpoint: { route: "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", params: { owner, repo, issue_number: prNumber } },
81106
};
82107
}
83108

@@ -93,9 +118,9 @@ async function resolveEventEndpoints(eventName, owner, repo, payload) {
93118
return null;
94119
}
95120
return {
96-
reactionEndpoint: `/repos/${owner}/${repo}/pulls/comments/${reviewCommentId}/reactions`,
121+
reactionEndpoint: { route: "POST /repos/{owner}/{repo}/pulls/comments/{comment_id}/reactions", params: { owner, repo, comment_id: reviewCommentId } },
97122
// Create new comment on the PR itself (using issues endpoint since PRs are issues)
98-
commentUpdateEndpoint: `/repos/${owner}/${repo}/issues/${prNumber}/comments`,
123+
commentUpdateEndpoint: { route: "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", params: { owner, repo, issue_number: prNumber } },
99124
};
100125
}
101126

@@ -171,16 +196,20 @@ async function main() {
171196

172197
const { reactionEndpoint, commentUpdateEndpoint } = endpoints;
173198

174-
core.info(`Reaction API endpoint: ${reactionEndpoint}`);
199+
core.info(`Reaction API endpoint: ${typeof reactionEndpoint === "object" ? reactionEndpoint.route : reactionEndpoint}`);
175200

176-
// For discussions, reactionEndpoint is a node ID (GraphQL), otherwise it's a REST API path
201+
// For discussions, reactionEndpoint is a node ID (GraphQL), otherwise it's a typed REST route
177202
if (eventName === "discussion" || eventName === "discussion_comment") {
203+
if (typeof reactionEndpoint !== "string") {
204+
throw new Error(`${ERR_VALIDATION}: Unexpected reaction endpoint shape for event: ${eventName}`);
205+
}
178206
await addDiscussionReaction(reactionEndpoint, reaction);
179207
} else {
180-
await addReaction(reactionEndpoint, reaction);
208+
const { route, params } = expectRestEndpoint(reactionEndpoint, "reaction", eventName);
209+
await addReaction(route, params, reaction);
181210
}
182211

183-
core.info(`Comment endpoint: ${commentUpdateEndpoint}`);
212+
core.info(`Comment endpoint: ${typeof commentUpdateEndpoint === "object" ? commentUpdateEndpoint.route : commentUpdateEndpoint}`);
184213
await addCommentWithWorkflowLink(commentUpdateEndpoint, runUrl, eventName, invocationContext);
185214
} catch (error) {
186215
if (isLockedError(error)) {
@@ -211,7 +240,7 @@ function setCommentOutputs(commentId, commentUrl, eventRepo = context.repo) {
211240

212241
/**
213242
* Add a comment with a workflow run link
214-
* @param {string} endpoint - The GitHub API endpoint to create the comment (or special format for discussions)
243+
* @param {{ route: string, params: Record<string, unknown> } | string} endpoint - Typed route info for REST events, or special format string for discussions
215244
* @param {string} runUrl - The URL of the workflow run
216245
* @param {string} eventName - The event type (to determine the comment text)
217246
* @param {{
@@ -251,6 +280,9 @@ async function addCommentWithWorkflowLink(endpoint, runUrl, eventName, invocatio
251280
const commentBody = commentParts.join("\n\n");
252281

253282
if (eventName === "discussion" || eventName === "discussion_comment") {
283+
if (typeof endpoint !== "string") {
284+
throw new Error(`${ERR_VALIDATION}: Unexpected comment endpoint shape for event: ${eventName}`);
285+
}
254286
// Parse discussion number from special format: "discussion:NUMBER" or "discussion_comment:NUMBER:COMMENT_ID"
255287
const discussionNumber = parseInt(endpoint.split(":")[1], 10);
256288
const discussionId = await getDiscussionNodeId(eventRepo.owner, eventRepo.repo, discussionNumber);
@@ -262,8 +294,10 @@ async function addCommentWithWorkflowLink(endpoint, runUrl, eventName, invocatio
262294
return;
263295
}
264296

265-
// Create a new comment for non-discussion events
266-
const createResponse = await github.request(`POST ${endpoint}`, {
297+
// Create a new comment for non-discussion events using typed route
298+
const { route, params } = expectRestEndpoint(endpoint, "comment", eventName);
299+
const createResponse = await github.request(route, {
300+
...params,
267301
body: commentBody,
268302
headers: {
269303
Accept: "application/vnd.github+json",
@@ -278,4 +312,4 @@ async function addCommentWithWorkflowLink(endpoint, runUrl, eventName, invocatio
278312
}
279313
}
280314

281-
module.exports = { main, addCommentWithWorkflowLink, resolveEventEndpoints, VALID_REACTIONS, addReaction, addDiscussionReaction };
315+
module.exports = { main, addCommentWithWorkflowLink, resolveEventEndpoints, VALID_REACTIONS, addReaction, addDiscussionReaction, expectRestEndpoint };

‎setup/js/add_workflow_run_comment.cjs‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ const { buildWorkflowRunUrl } = require("./workflow_metadata_helpers.cjs");
1212
const { resolveTopLevelDiscussionCommentId } = require("./github_api_helpers.cjs");
1313
const { resolveInvocationContext } = require("./invocation_context_helpers.cjs");
1414

15+
/**
16+
* @param {unknown} endpoint
17+
* @returns {endpoint is { route: string, params: Record<string, unknown> }}
18+
*/
19+
function isRestEndpoint(endpoint) {
20+
return typeof endpoint === "object" && endpoint !== null && "route" in endpoint && "params" in endpoint;
21+
}
22+
1523
/**
1624
* @typedef {{ owner: string, repo: string }} RepoRef
1725
* @typedef {{ id: string, url: string, repo: RepoRef }} CommentMetadata
@@ -285,7 +293,7 @@ async function createOrReuseStatusComment(rawContext = context) {
285293
reportCommentError(rawContext, `${ERR_NOT_FOUND}: Issue number not found in event payload`);
286294
return null;
287295
}
288-
commentEndpoint = `/repos/${owner}/${repo}/issues/${number}/comments`;
296+
commentEndpoint = { route: "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", params: { owner, repo, issue_number: number } };
289297
break;
290298
}
291299

@@ -298,7 +306,7 @@ async function createOrReuseStatusComment(rawContext = context) {
298306
reportCommentError(rawContext, `${ERR_NOT_FOUND}: Pull request number not found in event payload`);
299307
return null;
300308
}
301-
commentEndpoint = `/repos/${owner}/${repo}/issues/${number}/comments`;
309+
commentEndpoint = { route: "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", params: { owner, repo, issue_number: number } };
302310
break;
303311
}
304312

@@ -328,7 +336,7 @@ async function createOrReuseStatusComment(rawContext = context) {
328336
return null;
329337
}
330338

331-
core.info(`Creating comment on: ${commentEndpoint}`);
339+
core.info(`Creating comment on: ${typeof commentEndpoint === "object" ? commentEndpoint.route : commentEndpoint}`);
332340
return addCommentWithWorkflowLink(commentEndpoint, runUrl, eventName, invocationContext);
333341
}
334342

@@ -409,7 +417,7 @@ async function postDiscussionComment(discussionNumber, commentBody, replyToNodeI
409417

410418
/**
411419
* Add a comment with a workflow run link
412-
* @param {string} endpoint - The GitHub API endpoint to create the comment (or special format for discussions)
420+
* @param {{ route: string, params: Record<string, unknown> } | string} endpoint - Typed route info for REST events, or special format string for discussions ("discussion:NUMBER" or "discussion_comment:NUMBER:COMMENT_ID")
413421
* @param {string} runUrl - The URL of the workflow run
414422
* @param {string} eventName - The event type (to determine the comment text)
415423
* @param {{
@@ -426,12 +434,18 @@ async function addCommentWithWorkflowLink(endpoint, runUrl, eventName, invocatio
426434
const commentBody = buildCommentBody(eventName, runUrl);
427435

428436
if (eventName === "discussion") {
437+
if (typeof endpoint !== "string") {
438+
throw new Error(`${ERR_VALIDATION}: Unexpected comment endpoint shape for event: ${eventName}`);
439+
}
429440
// Parse discussion number from special format: "discussion:NUMBER"
430441
const discussionNumber = parseInt(endpoint.split(":")[1], 10);
431442
return postDiscussionComment(discussionNumber, commentBody, null, eventRepo);
432443
}
433444

434445
if (eventName === "discussion_comment") {
446+
if (typeof endpoint !== "string") {
447+
throw new Error(`${ERR_VALIDATION}: Unexpected comment endpoint shape for event: ${eventName}`);
448+
}
435449
// Parse discussion number from special format: "discussion_comment:NUMBER:COMMENT_ID"
436450
const discussionNumber = parseInt(endpoint.split(":")[1], 10);
437451

@@ -440,8 +454,13 @@ async function addCommentWithWorkflowLink(endpoint, runUrl, eventName, invocatio
440454
return postDiscussionComment(discussionNumber, commentBody, commentNodeId, eventRepo);
441455
}
442456

443-
// Create a new comment for non-discussion events
444-
const createResponse = await github.request("POST " + endpoint, {
457+
// Create a new comment for non-discussion events using typed route
458+
if (!isRestEndpoint(endpoint)) {
459+
throw new Error(`${ERR_VALIDATION}: Unexpected comment endpoint shape for event: ${eventName}`);
460+
}
461+
const { route, params } = endpoint;
462+
const createResponse = await github.request(route, {
463+
...params,
445464
body: commentBody,
446465
headers: { Accept: "application/vnd.github+json" },
447466
});

0 commit comments

Comments
 (0)