2023-03-22 13:17:19 +00:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-12-14 20:07:10 +00:00
|
|
|
on:
|
|
|
|
pull_request_target:
|
|
|
|
types: [opened, closed, reopened]
|
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
name: Jira Community PR Sync
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
sync:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
name: Jira sync
|
|
|
|
steps:
|
|
|
|
- name: Login
|
2024-05-14 19:49:03 +00:00
|
|
|
uses: atlassian/gajira-login@45fd029b9f1d6d8926c6f04175aa80c0e42c9026 # v3.0.1
|
2022-12-14 20:07:10 +00:00
|
|
|
env:
|
|
|
|
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
|
|
|
|
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
|
|
|
|
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
|
|
|
|
|
|
|
|
- name: Set ticket type
|
|
|
|
id: set-ticket-type
|
|
|
|
run: |
|
2022-12-15 21:32:46 +00:00
|
|
|
echo "TYPE=GH Issue" >> $GITHUB_OUTPUT
|
2022-12-14 20:07:10 +00:00
|
|
|
|
|
|
|
- name: Set ticket labels
|
|
|
|
if: github.event.action == 'opened'
|
|
|
|
id: set-ticket-labels
|
|
|
|
run: |
|
|
|
|
LABELS="["
|
|
|
|
if [[ "${{ contains(github.event.issue.labels.*.name, 'type/bug') }}" == "true" ]]; then LABELS+="\"type/bug\", "; fi
|
|
|
|
if [[ "${{ contains(github.event.issue.labels.*.name, 'type/enhancement') }}" == "true" ]]; then LABELS+="\"type/enhancement\", "; fi
|
|
|
|
if [[ ${#LABELS} != 1 ]]; then LABELS=${LABELS::-2}"]"; else LABELS+="]"; fi
|
|
|
|
echo "LABELS=${LABELS}" >> $GITHUB_OUTPUT
|
|
|
|
|
|
|
|
- name: Check if team member
|
|
|
|
if: github.event.action == 'opened'
|
|
|
|
id: is-team-member
|
|
|
|
run: |
|
|
|
|
TEAM=consul
|
2023-10-05 22:56:20 +00:00
|
|
|
ROLE="$(gh api orgs/hashicorp/teams/${TEAM}/memberships/${{ github.actor }} | jq -r '.role | select(.!=null)')"
|
2022-12-14 20:07:10 +00:00
|
|
|
if [[ -n ${ROLE} ]]; then
|
|
|
|
echo "Actor ${{ github.actor }} is a ${TEAM} team member"
|
|
|
|
echo "MESSAGE=true" >> $GITHUB_OUTPUT
|
2023-03-09 22:29:39 +00:00
|
|
|
elif [[ "${{ contains(github.actor, 'hc-github-team-consul-core') }}" == "true" ]]; then
|
|
|
|
echo "Actor ${{ github.actor }} is a ${TEAM} team member"
|
|
|
|
echo "MESSAGE=true" >> $GITHUB_OUTPUT
|
|
|
|
elif [[ "${{ contains(github.actor, 'dependabot') }}" == "true" ]]; then
|
|
|
|
echo "Actor ${{ github.actor }} is a ${TEAM} team member"
|
|
|
|
echo "MESSAGE=true" >> $GITHUB_OUTPUT
|
2022-12-14 20:07:10 +00:00
|
|
|
else
|
|
|
|
echo "Actor ${{ github.actor }} is NOT a ${TEAM} team member"
|
|
|
|
echo "MESSAGE=false" >> $GITHUB_OUTPUT
|
|
|
|
fi
|
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.JIRA_SYNC_GITHUB_TOKEN }}
|
|
|
|
|
|
|
|
- name: Create ticket if an issue is filed, or if PR not by a team member is opened
|
|
|
|
if: ( github.event.action == 'opened' && steps.is-team-member.outputs.MESSAGE == 'false' )
|
2023-06-13 17:00:55 +00:00
|
|
|
uses: tomhjp/gh-action-jira-create@3ed1789cad3521292e591a7cfa703215ec1348bf # v0.2.1
|
2022-12-14 20:07:10 +00:00
|
|
|
with:
|
|
|
|
project: NET
|
|
|
|
issuetype: "${{ steps.set-ticket-type.outputs.TYPE }}"
|
|
|
|
summary: "${{ github.event.repository.name }} [${{ steps.set-ticket-type.outputs.TYPE }} #${{ github.event.pull_request.number }}]: ${{ github.event.pull_request.title }}"
|
|
|
|
description: "${{ github.event.issue.body || github.event.pull_request.body }}\n\n_Created in GitHub by ${{ github.actor }}._"
|
|
|
|
# customfield_10089 is "Issue Link", customfield_10371 is "Source" (use JIRA API to retrieve)
|
|
|
|
extraFields: '{ "customfield_10089": "${{ github.event.pull_request.html_url }}",
|
2024-05-03 18:07:12 +00:00
|
|
|
"customfield_10371": { "value": "GitHub" },
|
2022-12-14 20:07:10 +00:00
|
|
|
"components": [{ "name": "${{ github.event.repository.name }}" }],
|
|
|
|
"labels": ${{ steps.set-ticket-labels.outputs.LABELS }} }'
|
|
|
|
env:
|
|
|
|
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
|
|
|
|
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
|
|
|
|
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
|
2023-03-20 16:27:29 +00:00
|
|
|
|
|
|
|
# Education Jira
|
|
|
|
- name: Create ticket in Education board an issue is filed, or if PR not by a team member is opened
|
2023-03-27 15:40:08 +00:00
|
|
|
if: github.event.action == 'opened' && steps.is-team-member.outputs.MESSAGE == 'false' && contains(github.event.issue.labels.*.name, 'type/docs')
|
2023-06-13 17:00:55 +00:00
|
|
|
uses: tomhjp/gh-action-jira-create@3ed1789cad3521292e591a7cfa703215ec1348bf # v0.2.1
|
2023-03-20 16:27:29 +00:00
|
|
|
with:
|
|
|
|
project: CE
|
2023-03-23 16:00:38 +00:00
|
|
|
issuetype: "${{ steps.set-ticket-type.outputs.TYPE }}"
|
2023-03-27 15:40:08 +00:00
|
|
|
summary: "${{ github.event.repository.name }} [${{ steps.set-ticket-type.outputs.TYPE }} #${{ github.event.pull_request.number }}]: ${{ github.event.pull_request.title }}"
|
2023-03-20 17:01:56 +00:00
|
|
|
description: "GitHub URL: ${{ github.event.issue.html_url || github.event.pull_request.html_url }}\n\n${{ github.event.issue.body || github.event.pull_request.body }}\n\n_Created in GitHub by ${{ github.actor }}._"
|
2023-03-20 16:27:29 +00:00
|
|
|
# customfield_10089 is "Issue Link", customfield_10371 is "Source" (use JIRA API to retrieve)
|
2023-03-20 17:19:43 +00:00
|
|
|
extraFields: '{ "components": [{ "name": "${{ github.event.repository.name }}" }] }'
|
2022-12-14 20:07:10 +00:00
|
|
|
|
|
|
|
- name: Search
|
|
|
|
if: github.event.action != 'opened'
|
|
|
|
id: search
|
2023-06-13 17:00:55 +00:00
|
|
|
uses: tomhjp/gh-action-jira-search@04700b457f317c3e341ce90da5a3ff4ce058f2fa # v0.2.2
|
2022-12-14 20:07:10 +00:00
|
|
|
with:
|
|
|
|
# cf[10089] is Issue Link (use JIRA API to retrieve)
|
|
|
|
jql: 'issuetype = "${{ steps.set-ticket-type.outputs.TYPE }}" 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
|
2023-06-13 17:00:55 +00:00
|
|
|
uses: tomhjp/gh-action-jira-comment@6eb6b9ead70221916b6badd118c24535ed220bd9 # v0.2.0
|
2022-12-14 20:07:10 +00:00
|
|
|
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
|
2024-05-14 19:49:03 +00:00
|
|
|
uses: atlassian/gajira-transition@38fc9cd61b03d6a53dd35fcccda172fe04b36de3 # v3.0.1
|
2022-12-14 20:07:10 +00:00
|
|
|
with:
|
|
|
|
issue: ${{ steps.search.outputs.issue }}
|
|
|
|
transition: "Closed"
|
|
|
|
|
|
|
|
- name: Reopen ticket
|
|
|
|
if: github.event.action == 'reopened' && steps.search.outputs.issue
|
2024-05-14 19:49:03 +00:00
|
|
|
uses: atlassian/gajira-transition@38fc9cd61b03d6a53dd35fcccda172fe04b36de3 # v3.0.1
|
2022-12-14 20:07:10 +00:00
|
|
|
with:
|
|
|
|
issue: ${{ steps.search.outputs.issue }}
|
|
|
|
transition: "To Do"
|