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@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@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 "::set-output name=type::Invalid" else # Properly labeled GH issues are assigned the standard "GH Issue" type upon creation. echo "::set-output name=type::GH Issue" fi - name: Set labels id: set-ticket-labels run: | if [[ "${{ contains(github.event.issue.labels.*.name, 'bug') }}" == "true" ]]; then echo "::set-output name=labels::[\"bug\"]" elif [[ "${{ contains(github.event.issue.labels.*.name, 'enhancement') }}" == "true" ]]; then echo "::set-output name=labels::[\"enhancement\"]" else echo "::set-output name=labels::[]" 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@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 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}})