blob: e0e82a97f0118361951a3de01b4bdefdf6b4d8d5 [file] [log] [blame]
on:
issues:
types: [labeled]
permissions:
contents: read
name: JIRA Sync
jobs:
sync:
name: Sync to JIRA
permissions:
issues: write # for actions-ecosytem/action-create-comment
runs-on: ubuntu-latest
steps:
- name: Login
uses: atlassian/gajira-login@45fd029b9f1d6d8926c6f04175aa80c0e42c9026 # v3.0.1
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
- name: Search
if: github.event.action == 'labeled'
id: search
uses: tomhjp/gh-action-jira-search@04700b457f317c3e341ce90da5a3ff4ce058f2fa # v0.2.2
with:
# cf[10089] is Issue Link (use JIRA API to retrieve)
jql: 'project = "HPR" AND cf[10089] = "${{ github.event.issue.html_url }}"'
- name: Set type
id: set-ticket-type
run: |
# Questions are not tracked in JIRA at this time.
if [[ "${{ contains(github.event.issue.labels.*.name, 'question') }}" == "true" ]]; then
echo "type=Invalid" >> $GITHUB_OUTPUT
else
# Properly labeled GH issues are assigned the standard "GH Issue" type upon creation.
echo "type=GH Issue" >> $GITHUB_OUTPUT
fi
- name: Set labels
id: set-ticket-labels
run: |
if [[ "${{ contains(github.event.issue.labels.*.name, 'bug') }}" == "true" ]]; then
echo "labels=[\"bug\"]" >> $GITHUB_OUTPUT
elif [[ "${{ contains(github.event.issue.labels.*.name, 'enhancement') }}" == "true" ]]; then
echo "labels=[\"enhancement\"]" >> $GITHUB_OUTPUT
else
echo "labels=[]" >> $GITHUB_OUTPUT
fi
- name: Validate ticket
if: steps.set-ticket-type.outputs.type == 'Invalid'
run: |
echo "Questions are not being synced to JIRA at this time."
echo "If the issue is a bug or an enhancement please remove the question label and reapply the 'sync to jira' label."
- name: Create ticket
id: create-ticket
if: steps.search.outputs.issue == '' && github.event.label.name == 'sync to jira' && steps.set-ticket-type.outputs.type != 'Invalid'
uses: atlassian/gajira-create@59e177c4f6451399df5b4911c2211104f171e669 # v3.0.1
with:
project: HPR
issuetype: "${{ steps.set-ticket-type.outputs.type }}"
summary: "${{ github.event.repository.name }}: ${{ github.event.issue.title }}"
description: "${{ github.event.issue.body }}\n\n_Created from GitHub by ${{ github.actor }}._"
# The field customfield_10089 refers to the Issue Link field in JIRA.
fields: '{ "customfield_10089": "${{ github.event.issue.html_url }}",
"components": [{ "name": "OSS" }],
"labels": ${{ steps.set-ticket-labels.outputs.labels }} }'
- name: Add tracking comment
if: steps.create-ticket.outputs.issue != '' && steps.set-ticket-type.outputs.type != 'Invalid'
uses: actions-ecosystem/action-create-comment@v1.0.0 # TSCCR: no entry for repository "actions-ecosystem/action-create-comment"
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
body: |
This issue has been synced to JIRA for planning.
JIRA ID: [${{ steps.create-ticket.outputs.issue }}](https://hashicorp.atlassian.net/browse/${{steps.create-ticket.outputs.issue}})