Skip to content

Commit

Permalink
Merge pull request #32 from codacy/meta/update-jira-actions-2020-08-5…
Browse files Browse the repository at this point in the history
…_12-50

meta: Update the common files from meta-repo
  • Loading branch information
machadoit authored Aug 5, 2020
2 parents 9c9c325 + bc1b4fc commit 1ecde92
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/comment_issue.yml
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/[email protected]
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/[email protected]
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/[email protected]
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}
86 changes: 86 additions & 0 deletions .github/workflows/create_issue.yml
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/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]
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 }})'
})
79 changes: 79 additions & 0 deletions .github/workflows/create_issue_on_label.yml
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/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]
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 }})'
})

0 comments on commit 1ecde92

Please sign in to comment.