Skip to content

Create Branch from Issue #39

Create Branch from Issue

Create Branch from Issue #39

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_USER_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 }}"
ISSUE_ASSIGNEE="${{ github.event.issue.assignee.login }}"
JIRA_ASSIGNEE_ID=$(curl -s -u $JIRA_USER_EMAIL:$JIRA_API_TOKEN "$JIRA_BASE_URL/rest/api/3/user/search?query=$ISSUE_ASSIGNEE" | jq -r '.[0].accountId')
RESPONSE=$(curl -s -u $JIRA_USER_EMAIL:$JIRA_API_TOKEN -X POST -H "Content-Type: application/json" \
--data '{
"fields": {
"project": {"key": "'$JIRA_PROJECT_KEY'"},
"summary": "'$ISSUE_TITLE'",
"description": "'$ISSUE_BODY'",
"issuetype": {"name": "Task"},
"assignee": {"id": "'$JIRA_ASSIGNEE_ID'"}
}
}' "$JIRA_BASE_URL/rest/api/3/issue/")
echo "Jira API response: $RESPONSE"
- name: Create branch for the issue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |

Check failure on line 42 in .github/workflows/create-jira-issue.yml

View workflow run for this annotation

GitHub Actions / Create Jira Issue and Sync with GitHub

Invalid workflow file

The workflow is not valid. .github/workflows/create-jira-issue.yml (Line: 42, Col: 14): Unexpected symbol: '|'. Located at position 26 within expression: github.event.issue.title | slugify
ISSUE_NUMBER=${{ github.event.issue.number }}
ISSUE_TITLE="${{ github.event.issue.title | slugify }}"
BRANCH_NAME="feature/${{ github.event.issue.labels[0].name | slugify }}/${ISSUE_NUMBER}-${ISSUE_TITLE}"
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:[email protected]/${{ 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_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
run: |
JIRA_ISSUE_KEY="${{ github.event.issue.labels[0].name }}"
NEW_ASSIGNEE="${{ github.event.issue.assignee.login }}"
JIRA_ASSIGNEE_ID=$(curl -s -u $JIRA_USER_EMAIL:$JIRA_API_TOKEN "$JIRA_BASE_URL/rest/api/3/user/search?query=$NEW_ASSIGNEE" | jq -r '.[0].accountId')
curl -s -u $JIRA_USER_EMAIL:$JIRA_API_TOKEN -X PUT -H "Content-Type: application/json" \
--data '{"update": {"assignee": [{"set": {"id": "'$JIRA_ASSIGNEE_ID'"}}]}}' "$JIRA_BASE_URL/rest/api/3/issue/$JIRA_ISSUE_KEY"