Skip to content

Commit a656bef

Browse files
More explicit parsing, logging & error throwing for fetch_custom_fields_if_defined step (#12)
🙏
1 parent 14fa935 commit a656bef

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

action.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,28 @@ runs:
5454
return ""
5555
}
5656
return ',"customfield_10001" : "' + teamId + '"'
57-
5857
- name: Fetch CUSTOM_FIELDS if defined
5958
id: fetch_custom_fields_if_defined
6059
uses: actions/github-script@v6
6160
with:
6261
result-encoding: string
6362
script: |
64-
const customFields = "${{ inputs.CUSTOM_FIELDS }}"
65-
if (customFields) {
66-
return ',' + customFields
63+
const rawCustomFields = `${{ inputs.CUSTOM_FIELDS }}`.trim();
64+
if (rawCustomFields) {
65+
try {
66+
const inputToParse = rawCustomFields.startsWith('{') ? rawCustomFields : `{${rawCustomFields}}`;
67+
const parsedCustomFields = JSON.parse(inputToParse);
68+
console.log(`Parsed CUSTOM_FIELDS: ${JSON.stringify(parsedCustomFields)}`);
69+
return ',' + Object.entries(parsedCustomFields)
70+
.map(([key, value]) => `"${key}": "${value}"`)
71+
.join(', ');
72+
} catch (error) {
73+
throw new Error(
74+
`Invalid CUSTOM_FIELDS format: '${rawCustomFields}'. Must be either a valid JSON object or key-value pairs in JSON format.`
75+
);
76+
}
6777
}
68-
return ""
78+
return '';
6979
- name: Create Jira issue
7080
id: create_jira_issue
7181
uses: atlassian/gajira-create@v2.0.1

0 commit comments

Comments
 (0)