Skip to content

Commit c8022b0

Browse files
simplify: extract buildAllowedFieldSet helper and format replay one-liner (#42410)
1 parent 5febd95 commit c8022b0

2 files changed

Lines changed: 26 additions & 31 deletions

File tree

actions/setup/js/allowed_issue_fields.cjs

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ const { ERR_VALIDATION } = require("./error_codes.cjs");
99
* @returns {string[]}
1010
*/
1111
function parseAllowedIssueFields(value) {
12-
if (value == null || value === "") {
13-
return [];
14-
}
12+
if (value == null || value === "") return [];
1513
const raw = Array.isArray(value) ? value : String(value).split(",");
16-
const uniqueFields = new Set();
17-
for (const item of raw) {
18-
const normalized = String(item).trim();
19-
if (normalized) {
20-
uniqueFields.add(normalized);
21-
}
22-
}
23-
return [...uniqueFields];
14+
return [...new Set(raw.map(item => String(item).trim()).filter(Boolean))];
15+
}
16+
17+
/**
18+
* Build a lowercased Set from allowedFields.
19+
* Returns null when no restriction applies (empty list, non-array, or wildcard "*").
20+
* @param {string[]} allowedFields
21+
* @returns {Set<string>|null}
22+
*/
23+
function buildAllowedFieldSet(allowedFields) {
24+
if (!Array.isArray(allowedFields) || allowedFields.length === 0 || allowedFields.includes("*")) return null;
25+
return new Set(allowedFields.map(f => f.toLowerCase()));
2426
}
2527

2628
/**
@@ -30,14 +32,10 @@ function parseAllowedIssueFields(value) {
3032
* @returns {void}
3133
*/
3234
function validateAllowedIssueFieldName(fieldName, allowedFields) {
33-
if (!fieldName) {
34-
return;
35-
}
36-
if (!Array.isArray(allowedFields) || allowedFields.length === 0 || allowedFields.includes("*")) {
37-
return;
38-
}
39-
const allowedFieldSet = new Set(allowedFields.map(field => field.toLowerCase()));
40-
if (!allowedFieldSet.has(fieldName.toLowerCase())) {
35+
if (!fieldName) return;
36+
const fieldSet = buildAllowedFieldSet(allowedFields);
37+
if (!fieldSet) return;
38+
if (!fieldSet.has(fieldName.toLowerCase())) {
4139
throw new Error(`${ERR_VALIDATION}: issue field "${fieldName}" is not in the allowed-fields list: ${allowedFields.join(", ")}`);
4240
}
4341
}
@@ -49,18 +47,11 @@ function validateAllowedIssueFieldName(fieldName, allowedFields) {
4947
* @returns {void}
5048
*/
5149
function validateAllowedIssueFields(issueFields, allowedFields) {
52-
if (!Array.isArray(issueFields) || issueFields.length === 0) {
53-
return;
54-
}
55-
if (!Array.isArray(allowedFields) || allowedFields.length === 0) {
56-
return;
57-
}
58-
const allowedFieldSet = new Set(allowedFields.map(field => field.toLowerCase()));
59-
if (allowedFieldSet.has("*")) {
60-
return;
61-
}
50+
if (!Array.isArray(issueFields) || issueFields.length === 0) return;
51+
const fieldSet = buildAllowedFieldSet(allowedFields);
52+
if (!fieldSet) return;
6253
for (const field of issueFields) {
63-
if (!allowedFieldSet.has(field.name.toLowerCase())) {
54+
if (!fieldSet.has(field.name.toLowerCase())) {
6455
throw new Error(`${ERR_VALIDATION}: issue field "${field.name}" is not in the allowed-fields list: ${allowedFields.join(", ")}`);
6556
}
6657
}

actions/setup/js/apply_safe_outputs_replay.cjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ function buildHandlerConfigFromOutput(agentOutputFile) {
108108
}
109109

110110
// Normalize type: convert dashes to underscores (mirrors safe_outputs_append.cjs)
111-
const config = Object.fromEntries(validatedOutput.items.filter(item => item.type && typeof item.type === "string").map(item => [item.type.replace(/-/g, "_"), {}]));
111+
const config = Object.fromEntries(
112+
validatedOutput.items
113+
.filter(item => item.type && typeof item.type === "string")
114+
.map(item => [item.type.replace(/-/g, "_"), {}])
115+
);
112116

113117
core.info(`Handler config built from ${validatedOutput.items.length} item(s): ${Object.keys(config).join(", ")}`);
114118
return config;

0 commit comments

Comments
 (0)