-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from codacy/meta/update-jira-github-actions
feature: Add Jira GitHub actions from codacy-meta-repo
- Loading branch information
Showing
3 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Comment issue on Jira | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
jira: | ||
env: | ||
JIRA_CREATE_COMMENT_AUTO: ${{ secrets.JIRA_CREATE_COMMENT_AUTO }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Jira Login | ||
if: env.JIRA_CREATE_COMMENT_AUTO == 'true' | ||
id: login | ||
uses: atlassian/gajira-login@v2.0.0 | ||
env: | ||
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | ||
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | ||
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | ||
|
||
- name: Extract Jira number | ||
if: env.JIRA_CREATE_COMMENT_AUTO == 'true' | ||
id: extract_jira_number | ||
uses: actions/github-script@v2.0.0 | ||
env: | ||
JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }} | ||
GITHUB_TITLE: ${{ github.event.issue.title }} | ||
with: | ||
script: | | ||
const jiraTaskRegex = new RegExp(`\\\[(${process.env.JIRA_PROJECT}-[0-9]+?)\\\]`) | ||
return process.env.GITHUB_TITLE.match(jiraTaskRegex)[1] | ||
result-encoding: string | ||
|
||
- name: Jira Add comment on issue | ||
if: env.JIRA_CREATE_COMMENT_AUTO == 'true' | ||
id: add_comment_jira_issue | ||
uses: atlassian/gajira-comment@v2.0.0 | ||
with: | ||
issue: ${{ steps.extract_jira_number.outputs.result }} | ||
comment: | | ||
GitHub Comment : ${{ github.event.comment.user.login }} | ||
{quote}${{ github.event.comment.body }}{quote} | ||
---- | ||
{panel} | ||
_[Github permalink |${{ github.event.comment.html_url }}]_ | ||
{panel} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
name: Create issue on Jira | ||
|
||
on: | ||
issues: | ||
types: [opened] | ||
|
||
jobs: | ||
jira: | ||
env: | ||
JIRA_CREATE_ISSUE_AUTO: ${{ secrets.JIRA_CREATE_ISSUE_AUTO }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Jira Login | ||
if: env.JIRA_CREATE_ISSUE_AUTO == 'true' | ||
id: login | ||
uses: atlassian/gajira-login@v2.0.0 | ||
env: | ||
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | ||
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | ||
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | ||
|
||
- name: Jira Create issue | ||
if: env.JIRA_CREATE_ISSUE_AUTO == 'true' | ||
id: create_jira_issue | ||
uses: atlassian/gajira-create@v2.0.0 | ||
with: | ||
project: ${{ secrets.JIRA_PROJECT }} | ||
issuetype: ${{ secrets.JIRA_ISSUE_TYPE }} | ||
summary: "[GH#${{ github.event.issue.number }}] ${{ github.event.issue.title }}" | ||
description: | | ||
${{ github.event.issue.body }} | ||
---- | ||
{panel} | ||
_[Github permalink |${{ github.event.issue.html_url }}]_ | ||
{panel} | ||
- name: Update Jira issue | ||
if: env.JIRA_CREATE_ISSUE_AUTO == 'true' && env.JIRA_UPDATE_ISSUE_BODY != '' | ||
env: | ||
JIRA_UPDATE_ISSUE_BODY: ${{ secrets.JIRA_UPDATE_ISSUE_BODY }} | ||
run: > | ||
curl | ||
-u ${{ secrets.JIRA_USER_EMAIL }}:${{ secrets.JIRA_API_TOKEN }} | ||
-X PUT | ||
-H 'Content-Type: application/json' | ||
-d '${{ env.JIRA_UPDATE_ISSUE_BODY }}' | ||
${{ secrets.JIRA_BASE_URL }}/rest/api/2/issue/${{ steps.create_jira_issue.outputs.issue }} | ||
- name: Update GitHub issue | ||
if: env.JIRA_CREATE_ISSUE_AUTO == 'true' | ||
uses: actions/github-script@v2.0.0 | ||
env: | ||
JIRA_ISSUE_NUMBER: ${{ steps.create_jira_issue.outputs.issue }} | ||
GITHUB_ORIGINAL_TITLE: ${{ github.event.issue.title }} | ||
JIRA_ISSUE_LABEL: ${{ secrets.JIRA_ISSUE_LABEL }} | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const newTitle = `[${process.env.JIRA_ISSUE_NUMBER}] ${process.env.GITHUB_ORIGINAL_TITLE}` | ||
github.issues.update({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
title: newTitle | ||
}) | ||
github.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: [process.env.JIRA_ISSUE_LABEL] | ||
}) | ||
- name: Add comment after sync | ||
if: env.JIRA_CREATE_ISSUE_AUTO == 'true' | ||
uses: actions/github-script@v2.0.0 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
github.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: 'Internal ticket created : [${{ steps.create_jira_issue.outputs.issue }}](${{ secrets.JIRA_BASE_URL }}/browse/${{ steps.create_jira_issue.outputs.issue }})' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Create issue on Jira when labeled with JIRA_ISSUE_LABEL | ||
|
||
on: | ||
issues: | ||
types: [labeled] | ||
|
||
jobs: | ||
jira: | ||
env: | ||
JIRA_ISSUE_LABEL: ${{ secrets.JIRA_ISSUE_LABEL }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Jira Login | ||
if: github.event.label.name == env.JIRA_ISSUE_LABEL | ||
id: login | ||
uses: atlassian/gajira-login@v2.0.0 | ||
env: | ||
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | ||
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | ||
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | ||
|
||
- name: Jira Create issue | ||
if: github.event.label.name == env.JIRA_ISSUE_LABEL | ||
id: create_jira_issue | ||
uses: atlassian/gajira-create@v2.0.0 | ||
with: | ||
project: ${{ secrets.JIRA_PROJECT }} | ||
issuetype: ${{ secrets.JIRA_ISSUE_TYPE }} | ||
summary: "[GH#${{ github.event.issue.number }}] ${{ github.event.issue.title }}" | ||
description: | | ||
${{ github.event.issue.body }} | ||
---- | ||
{panel} | ||
_[Github permalink |${{ github.event.issue.html_url }}]_ | ||
{panel} | ||
- name: Update Jira issue | ||
if: github.event.label.name == env.JIRA_ISSUE_LABEL && env.JIRA_UPDATE_ISSUE_BODY != '' | ||
env: | ||
JIRA_UPDATE_ISSUE_BODY: ${{ secrets.JIRA_UPDATE_ISSUE_BODY }} | ||
run: > | ||
curl | ||
-u ${{ secrets.JIRA_USER_EMAIL }}:${{ secrets.JIRA_API_TOKEN }} | ||
-X PUT | ||
-H 'Content-Type: application/json' | ||
-d '${{ env.JIRA_UPDATE_ISSUE_BODY }}' | ||
${{ secrets.JIRA_BASE_URL }}/rest/api/2/issue/${{ steps.create_jira_issue.outputs.issue }} | ||
- name: Change Title | ||
if: github.event.label.name == env.JIRA_ISSUE_LABEL | ||
uses: actions/github-script@v2.0.0 | ||
env: | ||
JIRA_ISSUE_NUMBER: ${{ steps.create_jira_issue.outputs.issue }} | ||
GITHUB_ORIGINAL_TITLE: ${{ github.event.issue.title }} | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const newTitle = `[${process.env.JIRA_ISSUE_NUMBER}] ${process.env.GITHUB_ORIGINAL_TITLE}` | ||
github.issues.update({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
title: newTitle | ||
}) | ||
- name: Add comment after sync | ||
if: github.event.label.name == env.JIRA_ISSUE_LABEL | ||
uses: actions/github-script@v2.0.0 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
github.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: 'Internal ticket created : [${{ steps.create_jira_issue.outputs.issue }}](${{ secrets.JIRA_BASE_URL }}/browse/${{ steps.create_jira_issue.outputs.issue }})' | ||
}) | ||