Add Jira sync action (#373)
This commit is contained in:
parent
cfe3bccf8e
commit
d2c5ff8fcc
1 changed files with 88 additions and 0 deletions
88
.github/workflows/jira.yaml
vendored
Normal file
88
.github/workflows/jira.yaml
vendored
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [opened, closed, deleted, reopened]
|
||||||
|
pull_request_target:
|
||||||
|
types: [opened, closed, reopened]
|
||||||
|
issue_comment: # Also triggers when commenting on a PR from the conversation view
|
||||||
|
types: [created]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
name: Jira Sync
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sync:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Jira sync
|
||||||
|
steps:
|
||||||
|
- name: Check if community user
|
||||||
|
if: github.event.action == 'opened'
|
||||||
|
id: vault-team-role
|
||||||
|
run: |
|
||||||
|
TEAM=vault
|
||||||
|
ROLE="$(hub api orgs/hashicorp/teams/${TEAM}/memberships/${{ github.actor }} | jq -r '.role | select(.!=null)')"
|
||||||
|
if [[ -n ${ROLE} ]]; then
|
||||||
|
echo "Actor ${{ github.actor }} is a ${TEAM} team member, skipping ticket creation"
|
||||||
|
else
|
||||||
|
echo "Actor ${{ github.actor }} is not a ${TEAM} team member"
|
||||||
|
fi
|
||||||
|
echo "::set-output name=role::${ROLE}"
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.JIRA_SYNC_GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Login
|
||||||
|
uses: atlassian/gajira-login@v2.0.0
|
||||||
|
env:
|
||||||
|
JIRA_BASE_URL: ${{ secrets.JIRA_SYNC_BASE_URL }}
|
||||||
|
JIRA_USER_EMAIL: ${{ secrets.JIRA_SYNC_USER_EMAIL }}
|
||||||
|
JIRA_API_TOKEN: ${{ secrets.JIRA_SYNC_API_TOKEN }}
|
||||||
|
|
||||||
|
- name: Set ticket type
|
||||||
|
if: github.event.action == 'opened' && !steps.vault-team-role.outputs.role
|
||||||
|
id: set-ticket-type
|
||||||
|
run: |
|
||||||
|
if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
|
||||||
|
echo "::set-output name=type::PR"
|
||||||
|
else
|
||||||
|
echo "::set-output name=type::ISS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Create ticket
|
||||||
|
if: github.event.action == 'opened' && !steps.vault-team-role.outputs.role
|
||||||
|
uses: tomhjp/gh-action-jira-create@v0.1.0
|
||||||
|
with:
|
||||||
|
project: VAULT
|
||||||
|
issuetype: "GH Issue"
|
||||||
|
summary: "${{ github.event.repository.name }} [${{ steps.set-ticket-type.outputs.type }} #${{ github.event.issue.number || github.event.pull_request.number }}]: ${{ github.event.issue.title || github.event.pull_request.title }}"
|
||||||
|
description: "${{ github.event.issue.body || github.event.pull_request.body }}\n\n_Created from GitHub Action for ${{ github.event.issue.html_url || github.event.pull_request.html_url }}, from ${{ github.actor }}_"
|
||||||
|
# customfield_10089 is Issue Link custom field
|
||||||
|
# customfield_10091 is team custom field
|
||||||
|
extraFields: '{"fixVersions": [{"name": "TBD"}], "customfield_10091": ["ecosystem"], "customfield_10089": "${{ github.event.issue.html_url || github.event.pull_request.html_url }}"}'
|
||||||
|
|
||||||
|
- name: Search
|
||||||
|
if: github.event.action != 'opened'
|
||||||
|
id: search
|
||||||
|
uses: tomhjp/gh-action-jira-search@v0.2.1
|
||||||
|
with:
|
||||||
|
# cf[10089] is Issue Link custom field
|
||||||
|
jql: 'project = "VAULT" and issuetype = "GH Issue" and cf[10089]="${{ github.event.issue.html_url || github.event.pull_request.html_url }}"'
|
||||||
|
|
||||||
|
- name: Sync comment
|
||||||
|
if: github.event.action == 'created' && steps.search.outputs.issue
|
||||||
|
uses: atlassian/gajira-comment@v2.0.1
|
||||||
|
with:
|
||||||
|
issue: ${{ steps.search.outputs.issue }}
|
||||||
|
comment: "${{ github.actor }} ${{ github.event.review.state || 'commented' }}:\n\n${{ github.event.comment.body || github.event.review.body }}\n\n${{ github.event.comment.html_url || github.event.review.html_url }}"
|
||||||
|
|
||||||
|
- name: Close ticket
|
||||||
|
if: (github.event.action == 'closed' || github.event.action == 'deleted') && steps.search.outputs.issue
|
||||||
|
uses: atlassian/gajira-transition@v2.0.1
|
||||||
|
with:
|
||||||
|
issue: ${{ steps.search.outputs.issue }}
|
||||||
|
transition: Done
|
||||||
|
|
||||||
|
- name: Reopen ticket
|
||||||
|
if: github.event.action == 'reopened' && steps.search.outputs.issue
|
||||||
|
uses: atlassian/gajira-transition@v2.0.1
|
||||||
|
with:
|
||||||
|
issue: ${{ steps.search.outputs.issue }}
|
||||||
|
transition: "To Do"
|
Loading…
Reference in a new issue