@@ -11,20 +11,66 @@ jobs:
11
11
runs-on : ubuntu-latest
12
12
steps :
13
13
14
- - name : Jira Login
14
+ - name : Start workflow if JIRA_CREATE_COMMENT_AUTO is enabled
15
+ if : env.JIRA_CREATE_COMMENT_AUTO == 'true'
16
+ run : echo "Starting workflow"
17
+
18
+ - name : Check GitHub Issue type
15
19
if : env.JIRA_CREATE_COMMENT_AUTO == 'true'
20
+ id : github_issue_type
21
+
22
+ with :
23
+ result-encoding : string
24
+ script : |
25
+ // An Issue can be a pull request, you can identify pull requests by the pull_request key
26
+ const pullRequest = ${{ toJson(github.event.issue.pull_request) }}
27
+ if(pullRequest) {
28
+ return "pull-request"
29
+ } else {
30
+ return "issue"
31
+ }
32
+
33
+ - name : Check if GitHub Issue has JIRA_ISSUE_LABEL
34
+ if : env.JIRA_CREATE_COMMENT_AUTO == 'true'
35
+ id : github_issue_has_jira_issue_label
36
+
37
+ env :
38
+ JIRA_ISSUE_LABEL : ${{ secrets.JIRA_ISSUE_LABEL }}
39
+ with :
40
+ result-encoding : string
41
+ script : |
42
+ const labels = ${{ toJson(github.event.issue.labels) }}
43
+ if(labels.find(label => label.name == process.env.JIRA_ISSUE_LABEL)) {
44
+ return "true"
45
+ } else {
46
+ return "false"
47
+ }
48
+
49
+ - name : Continue workflow only for Issues (not Pull Requests) tagged with JIRA_ISSUE_LABEL
50
+ if : env.JIRA_CREATE_COMMENT_AUTO == 'true' && env.GITHUB_ISSUE_TYPE == 'issue' && env.GITHUB_ISSUE_HAS_JIRA_ISSUE_LABEL == 'true'
51
+ env :
52
+ GITHUB_ISSUE_TYPE : ${{ steps.github_issue_type.outputs.result }}
53
+ GITHUB_ISSUE_HAS_JIRA_ISSUE_LABEL : ${{ steps.github_issue_has_jira_issue_label.outputs.result }}
54
+ run : echo "GitHub Issue is tracked on Jira, eligilbe to be commented"
55
+
56
+ - name : Jira Login
57
+ if : env.JIRA_CREATE_COMMENT_AUTO == 'true' && env.GITHUB_ISSUE_TYPE == 'issue' && env.GITHUB_ISSUE_HAS_JIRA_ISSUE_LABEL == 'true'
16
58
id : login
17
59
18
60
env :
61
+ GITHUB_ISSUE_TYPE : ${{ steps.github_issue_type.outputs.result }}
62
+ GITHUB_ISSUE_HAS_JIRA_ISSUE_LABEL : ${{ steps.github_issue_has_jira_issue_label.outputs.result }}
19
63
JIRA_BASE_URL : ${{ secrets.JIRA_BASE_URL }}
20
64
JIRA_USER_EMAIL : ${{ secrets.JIRA_USER_EMAIL }}
21
65
JIRA_API_TOKEN : ${{ secrets.JIRA_API_TOKEN }}
22
66
23
67
- name : Extract Jira number
24
- if : env.JIRA_CREATE_COMMENT_AUTO == 'true'
68
+ if : env.JIRA_CREATE_COMMENT_AUTO == 'true' && env.GITHUB_ISSUE_TYPE == 'issue' && env.GITHUB_ISSUE_HAS_JIRA_ISSUE_LABEL == 'true'
25
69
id : extract_jira_number
26
70
27
71
env :
72
+ GITHUB_ISSUE_TYPE : ${{ steps.github_issue_type.outputs.result }}
73
+ GITHUB_ISSUE_HAS_JIRA_ISSUE_LABEL : ${{ steps.github_issue_has_jira_issue_label.outputs.result }}
28
74
JIRA_PROJECT : ${{ secrets.JIRA_PROJECT }}
29
75
GITHUB_TITLE : ${{ github.event.issue.title }}
30
76
with :
34
80
result-encoding : string
35
81
36
82
- name : Jira Add comment on issue
37
- if : env.JIRA_CREATE_COMMENT_AUTO == 'true'
83
+ if : env.JIRA_CREATE_COMMENT_AUTO == 'true' && env.GITHUB_ISSUE_TYPE == 'issue' && env.GITHUB_ISSUE_HAS_JIRA_ISSUE_LABEL == 'true'
38
84
id : add_comment_jira_issue
39
85
86
+ env :
87
+ GITHUB_ISSUE_TYPE : ${{ steps.github_issue_type.outputs.result }}
88
+ GITHUB_ISSUE_HAS_JIRA_ISSUE_LABEL : ${{ steps.github_issue_has_jira_issue_label.outputs.result }}
40
89
with :
41
90
issue : ${{ steps.extract_jira_number.outputs.result }}
42
91
comment : |
0 commit comments