Skip to content

Commit ed3fc12

Browse files
SNOW-242502 added jira auto closure (#205)
1 parent 6615f51 commit ed3fc12

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
on:
2+
push
3+
4+
name: Test Transition Issue
5+
6+
jobs:
7+
test-transition-issue:
8+
name: Transition Issue
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@master
13+
14+
- name: Login
15+
uses: atlassian/gajira-login@master
16+
env:
17+
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
18+
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
19+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
20+
21+
- name: Create new issue
22+
id: create
23+
uses: atlassian/gajira-create@master
24+
with:
25+
project: GA
26+
issuetype: Build
27+
summary: |
28+
Build completed for ${{ github.repository }}
29+
description: |
30+
Compare branch|${{ github.event.compare }} # https://developer.github.com/v3/activity/events/types/#webhook-payload-example-31
31+
32+
33+
- name: Transition issue
34+
uses: ./
35+
with:
36+
issue: ${{ steps.create.outputs.issue }}
37+
transition: "To Do"
38+
39+
- name: Transition issue
40+
uses: ./
41+
with:
42+
issue: ${{ steps.create.outputs.issue }}
43+
transition: "In progress"
44+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const _ = require('lodash')
2+
const Jira = require('./common/net/Jira')
3+
4+
module.exports = class {
5+
constructor({githubEvent, argv, config}) {
6+
this.Jira = new Jira({
7+
baseUrl: config.baseUrl,
8+
token: config.token,
9+
email: config.email,
10+
})
11+
12+
this.config = config
13+
this.argv = argv
14+
this.githubEvent = githubEvent
15+
}
16+
17+
async execute() {
18+
const {argv} = this
19+
20+
const issueId = argv.issue
21+
22+
await this.Jira.transitionIssue(issueId, {
23+
update: {
24+
comment: [
25+
{add: {body: "Closed on GitHub"}}
26+
]
27+
},
28+
fields: {
29+
customfield_12860: {id: "11506"},
30+
customfield_13132: {id: "12467"},
31+
customfield_10800: {id: "-1"},
32+
customfield_12500: {id: "11302"},
33+
customfield_12400: {id: "-1"},
34+
resolution: {name: "Done"}
35+
},
36+
transition: {id: "71"}
37+
})
38+
39+
const transitionedIssue = await this.Jira.getIssue(issueId)
40+
41+
console.log(`Changed ${issueId} status to : ${_.get(transitionedIssue, 'fields.status.name')} .`)
42+
console.log(`Link to issue: ${this.config.baseUrl}/browse/${issueId}`)
43+
44+
return {}
45+
}
46+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Jira Issue Transition
2+
description: Change status of specific Jira issue
3+
branding:
4+
icon: 'chevron-right'
5+
color: 'blue'
6+
inputs:
7+
issue:
8+
description: Key of the issue to be transitioned
9+
required: true
10+
runs:
11+
using: 'node12'
12+
main: './dist/index.js'

.github/actions/gajira-close/dist/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/jira_close.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Jira closure
2+
3+
on:
4+
issues:
5+
types: [closed, deleted]
6+
7+
jobs:
8+
close-issue:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
- name: Jira login
14+
uses: atlassian/gajira-login@master
15+
env:
16+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
17+
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
18+
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
19+
- name: Extract issue from title
20+
id: extract
21+
env:
22+
TITLE: "${{ github.event.issue.title }}"
23+
run: |
24+
jira=$(echo -n $TITLE | awk '{print $1}' | sed -e 's/://')
25+
echo ::set-output name=jira::$jira
26+
- name: Close issue
27+
uses: ./.github/actions/gajira-close
28+
if: startsWith(steps.extract.outputs.jira, 'SNOW-')
29+
with:
30+
issue: "${{ steps.extract.outputs.jira }}"

0 commit comments

Comments
 (0)