Skip to content

Commit c0a9c69

Browse files
authoredOct 20, 2020
Merge pull request #16 from atlassian/feature/custom-field-support
add support for customfields
2 parents 2c65559 + b0f1d88 commit c0a9c69

File tree

7 files changed

+69
-6
lines changed

7 files changed

+69
-6
lines changed
 

‎.github/workflows/create.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ jobs:
2727
summary: |
2828
Build completed for ${{ github.repository }}
2929
description: |
30-
Compare branch|${{ github.event.compare }} # https://developer.github.com/v3/activity/events/types/#webhook-payload-example-31
30+
Compare branch|${{ github.event.compare }} # https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/webhook-events-and-payloads
31+
fields: '{"customfield_10171": "field value from actions. Please do not remove"}'
3132

3233
- name: Log created issue
3334
run: echo "Issue ${{ steps.create.outputs.issue }} was created"

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ For examples on how to use this, check out the [gajira-demo](https://github.com/
1919
Build completed for ${{ github.repository }}
2020
description: |
2121
Compare branch
22+
fields: '{"customfield_10171": "test"}'
2223

2324
- name: Log created issue
2425
run: echo "Issue ${{ steps.create.outputs.issue }} was created"
@@ -35,6 +36,7 @@ For examples on how to use this, check out the [gajira-demo](https://github.com/
3536
- `issuetype` (required) - Type of the issue to be created. Example: 'Incident'
3637
- `summary` (required) - Issue summary
3738
- `description` - Issue description
39+
- `fields` - Additional fields in JSON format
3840

3941
### Outputs
4042
- `issue` - Key of the newly created issue

‎__tests__/create.js

+57-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,63 @@ const issuetypeName = 'TESTISSUETYPE'
1414

1515
const { mocks } = require('./helpers')
1616

17-
test(`Should create simple issue with interpolated event field in summary and description`, async () => {
17+
test(`Should create issue with customfield`, async () => {
18+
const action = new Action({
19+
argv: {
20+
project: projectKey,
21+
issuetype: issuetypeName,
22+
summary: 'This is summary ref/head/blah',
23+
description: 'This is description ref/head/blah',
24+
fields: '{"customfield_10171" : "test"}',
25+
},
26+
config,
27+
})
28+
29+
const createMetaRequest = nock(baseUrl)
30+
.get('/rest/api/2/issue/createmeta')
31+
.query({
32+
expand: 'projects.issuetypes.fields',
33+
projectKeys: 'TESTPROJECT',
34+
issuetypeNames: 'TESTISSUETYPE',
35+
})
36+
.reply(200, mocks.jira.responses.createMeta)
37+
38+
let createIssueRequestBody = {}
39+
const createIssueRequest = nock(baseUrl)
40+
.post('/rest/api/2/issue')
41+
.reply(200, (url, body) => {
42+
createIssueRequestBody = body
43+
44+
return {
45+
key: 'TESTPROJECT-2',
46+
}
47+
})
48+
49+
await createMetaRequest
50+
await createIssueRequest
51+
52+
const result = await action.execute()
53+
54+
expect(createIssueRequestBody).toEqual({
55+
fields: {
56+
project: {
57+
key: projectKey,
58+
},
59+
issuetype: {
60+
name: issuetypeName,
61+
},
62+
summary: 'This is summary ref/head/blah',
63+
description: 'This is description ref/head/blah',
64+
customfield_10171: 'test',
65+
},
66+
})
67+
68+
expect(result).toEqual({
69+
issue: 'TESTPROJECT-2',
70+
})
71+
})
72+
73+
test(`Should create simple issue without customfield`, async () => {
1874
const action = new Action({
1975
argv: {
2076
project: projectKey,

‎action.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ module.exports = class {
6161
})
6262
}
6363

64-
// TODO fields
6564
if (argv.fields) {
6665
providedFields = [...providedFields, ...this.transformFields(argv.fields)]
6766
}
@@ -79,7 +78,9 @@ module.exports = class {
7978
return { issue: issue.key }
8079
}
8180

82-
transformFields (fields) {
81+
transformFields (fieldsString) {
82+
const fields = JSON.parse(fieldsString)
83+
8384
return Object.keys(fields).map(fieldKey => ({
8485
key: fieldKey,
8586
value: fields[fieldKey],

‎action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ inputs:
1616
description:
1717
description: Issue description
1818
required: false
19+
fields:
20+
description: Additional fields in JSON format
21+
required: false
1922
outputs:
2023
issue:
2124
description: Key of the newly created issue

‎dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function parseArgs () {
4949
issuetype: core.getInput('issuetype'),
5050
summary: core.getInput('summary'),
5151
description: core.getInput('description'),
52-
fields: false, // TODO
52+
fields: core.getInput('fields'),
5353
}
5454
}
5555

0 commit comments

Comments
 (0)
Failed to load comments.