Create Branch from Issue #41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create Jira Issue and Sync with GitHub | |
on: | |
issues: | |
types: [opened, assigned, unassigned] | |
jobs: | |
create_jira_issue: | |
if: github.event_name == 'issues' && github.event.action == 'opened' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Create Jira issue | |
env: | |
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | |
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | |
JIRA_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | |
JIRA_PROJECT_KEY: ${{ secrets.JIRA_PROJECT_KEY }} | |
run: | | |
ISSUE_TITLE="${{ github.event.issue.title }}" | |
ISSUE_BODY="${{ github.event.issue.body }}" | |
SANITIZED_TITLE=$(echo "$ISSUE_TITLE" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^a-zA-Z0-9]/-/g' | sed -e 's/--*/-/g') | |
PREFIX=$(echo "${{ github.event.issue.labels.*.name }}" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^a-zA-Z0-9]/-/g' | sed -e 's/--*/-/g') | |
BRANCH_NAME="feature/$PREFIX/$SANITIZED_TITLE-${{ github.event.issue.number }}" | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git checkout -b "$BRANCH_NAME" | |
git push "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" "$BRANCH_NAME" | |
sync_assignee: | |
if: github.event_name == 'issues' && (github.event.action == 'assigned' || github.event.action == 'unassigned') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Sync Jira assignee | |
env: | |
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | |
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | |
JIRA_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | |
run: | | |
ISSUE_ASSIGNEE="${{ github.event.issue.assignee.login }}" | |
JIRA_ASSIGNEE_ID=$(curl -s -u $JIRA_EMAIL:$JIRA_API_TOKEN "$JIRA_BASE_URL/rest/api/3/user/search?query=$ISSUE_ASSIGNEE" | jq -r '.[0].accountId') | |
curl -s -u $JIRA_EMAIL:$JIRA_API_TOKEN -X PUT -H "Content-Type: application/json" \ | |
--data '{"update": {"assignee": [{"set": {"accountId": "$JIRA_ASSIGNEE_ID"}}]}}' "$JIRA_BASE_URL/rest/api/3/issue/${{ env.JIRA_ISSUE_KEY }}" |