Skip to content

Commit

Permalink
Merge pull request #16 from atlassian/feature/custom-field-support
Browse files Browse the repository at this point in the history
add support for customfields
  • Loading branch information
rudzon authored Oct 20, 2020
2 parents 2c65559 + b0f1d88 commit c0a9c69
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ jobs:
summary: |
Build completed for ${{ github.repository }}
description: |
Compare branch|${{ github.event.compare }} # https://developer.github.com/v3/activity/events/types/#webhook-payload-example-31
Compare branch|${{ github.event.compare }} # https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/webhook-events-and-payloads
fields: '{"customfield_10171": "field value from actions. Please do not remove"}'

- name: Log created issue
run: echo "Issue ${{ steps.create.outputs.issue }} was created"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ For examples on how to use this, check out the [gajira-demo](https://github.com/
Build completed for ${{ github.repository }}
description: |
Compare branch
fields: '{"customfield_10171": "test"}'

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

### Outputs
- `issue` - Key of the newly created issue
Expand Down
58 changes: 57 additions & 1 deletion __tests__/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,63 @@ const issuetypeName = 'TESTISSUETYPE'

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

test(`Should create simple issue with interpolated event field in summary and description`, async () => {
test(`Should create issue with customfield`, async () => {
const action = new Action({
argv: {
project: projectKey,
issuetype: issuetypeName,
summary: 'This is summary ref/head/blah',
description: 'This is description ref/head/blah',
fields: '{"customfield_10171" : "test"}',
},
config,
})

const createMetaRequest = nock(baseUrl)
.get('/rest/api/2/issue/createmeta')
.query({
expand: 'projects.issuetypes.fields',
projectKeys: 'TESTPROJECT',
issuetypeNames: 'TESTISSUETYPE',
})
.reply(200, mocks.jira.responses.createMeta)

let createIssueRequestBody = {}
const createIssueRequest = nock(baseUrl)
.post('/rest/api/2/issue')
.reply(200, (url, body) => {
createIssueRequestBody = body

return {
key: 'TESTPROJECT-2',
}
})

await createMetaRequest
await createIssueRequest

const result = await action.execute()

expect(createIssueRequestBody).toEqual({
fields: {
project: {
key: projectKey,
},
issuetype: {
name: issuetypeName,
},
summary: 'This is summary ref/head/blah',
description: 'This is description ref/head/blah',
customfield_10171: 'test',
},
})

expect(result).toEqual({
issue: 'TESTPROJECT-2',
})
})

test(`Should create simple issue without customfield`, async () => {
const action = new Action({
argv: {
project: projectKey,
Expand Down
5 changes: 3 additions & 2 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ module.exports = class {
})
}

// TODO fields
if (argv.fields) {
providedFields = [...providedFields, ...this.transformFields(argv.fields)]
}
Expand All @@ -79,7 +78,9 @@ module.exports = class {
return { issue: issue.key }
}

transformFields (fields) {
transformFields (fieldsString) {
const fields = JSON.parse(fieldsString)

return Object.keys(fields).map(fieldKey => ({
key: fieldKey,
value: fields[fieldKey],
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ inputs:
description:
description: Issue description
required: false
fields:
description: Additional fields in JSON format
required: false
outputs:
issue:
description: Key of the newly created issue
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function parseArgs () {
issuetype: core.getInput('issuetype'),
summary: core.getInput('summary'),
description: core.getInput('description'),
fields: false, // TODO
fields: core.getInput('fields'),
}
}

Expand Down

0 comments on commit c0a9c69

Please sign in to comment.