Skip to content

Commit 5fcc686

Browse files
authored
Merge pull request #33 from codacy/meta/update-jira-actions-2020-08-6_16-00
meta: No longer runs failing worflows for comments on pull requests
2 parents 1ecde92 + eb0ea38 commit 5fcc686

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

.github/workflows/comment_issue.yml

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,66 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313

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
1519
if: env.JIRA_CREATE_COMMENT_AUTO == 'true'
20+
id: github_issue_type
21+
uses: actions/[email protected]
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+
uses: actions/[email protected]
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'
1658
id: login
1759
uses: atlassian/[email protected]
1860
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 }}
1963
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
2064
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
2165
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
2266

2367
- 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'
2569
id: extract_jira_number
2670
uses: actions/[email protected]
2771
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 }}
2874
JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }}
2975
GITHUB_TITLE: ${{ github.event.issue.title }}
3076
with:
@@ -34,9 +80,12 @@ jobs:
3480
result-encoding: string
3581

3682
- 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'
3884
id: add_comment_jira_issue
3985
uses: atlassian/[email protected]
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 }}
4089
with:
4190
issue: ${{ steps.extract_jira_number.outputs.result }}
4291
comment: |

.github/workflows/create_issue.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313

14+
- name: Start workflow if JIRA_CREATE_ISSUE_AUTO is enabled
15+
if: env.JIRA_CREATE_ISSUE_AUTO == 'true'
16+
run: echo "Starting workflow"
17+
1418
- name: Jira Login
1519
if: env.JIRA_CREATE_ISSUE_AUTO == 'true'
1620
id: login
@@ -35,7 +39,7 @@ jobs:
3539
_[Github permalink |${{ github.event.issue.html_url }}]_
3640
{panel}
3741
38-
- name: Update Jira issue
42+
- name: Update Jira issue if JIRA_UPDATE_ISSUE_BODY is defined
3943
if: env.JIRA_CREATE_ISSUE_AUTO == 'true' && env.JIRA_UPDATE_ISSUE_BODY != ''
4044
env:
4145
JIRA_UPDATE_ISSUE_BODY: ${{ secrets.JIRA_UPDATE_ISSUE_BODY }}

.github/workflows/create_issue_on_label.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313

14+
- name: Start workflow if GitHub issue is tagged with JIRA_ISSUE_LABEL
15+
if: github.event.label.name == env.JIRA_ISSUE_LABEL
16+
run: echo "Starting workflow"
17+
1418
- name: Jira Login
1519
if: github.event.label.name == env.JIRA_ISSUE_LABEL
1620
id: login
@@ -35,7 +39,7 @@ jobs:
3539
_[Github permalink |${{ github.event.issue.html_url }}]_
3640
{panel}
3741
38-
- name: Update Jira issue
42+
- name: Update Jira issue if JIRA_UPDATE_ISSUE_BODY is defined
3943
if: github.event.label.name == env.JIRA_ISSUE_LABEL && env.JIRA_UPDATE_ISSUE_BODY != ''
4044
env:
4145
JIRA_UPDATE_ISSUE_BODY: ${{ secrets.JIRA_UPDATE_ISSUE_BODY }}
@@ -76,4 +80,3 @@ jobs:
7680
repo: context.repo.repo,
7781
body: 'Internal ticket created : [${{ steps.create_jira_issue.outputs.issue }}](${{ secrets.JIRA_BASE_URL }}/browse/${{ steps.create_jira_issue.outputs.issue }})'
7882
})
79-

0 commit comments

Comments
 (0)