Skip to content

Jira Integration: Create Task from Issue #2

Jira Integration: Create Task from Issue

Jira Integration: Create Task from Issue #2

name: "Jira Integration: Create Task from Issue"
on:
issues:
types: [opened]
jobs:
create-jira-task:
name: Create Jira Task
runs-on: ubuntu-latest
steps:
- name: Extract issue type from labels
id: extract-type
run: |
# Extract issue type from GitHub labels
ISSUE_TYPE="Bug" # Default type
LABELS="${{ join(github.event.issue.labels.*.name, ',') }}"
if [[ "$LABELS" == *"bug"* ]] || [[ "$LABELS" == *"Bug"* ]]; then
ISSUE_TYPE="Bug"
elif [[ "$LABELS" == *"feature"* ]] || [[ "$LABELS" == *"Feature"* ]] || [[ "$LABELS" == *"enhancement"* ]]; then
ISSUE_TYPE="Story"
elif [[ "$LABELS" == *"task"* ]] || [[ "$LABELS" == *"Task"* ]]; then
ISSUE_TYPE="Task"
fi
echo "issue_type=$ISSUE_TYPE" >> $GITHUB_OUTPUT
echo "labels=$LABELS" >> $GITHUB_OUTPUT
- name: Create Jira Task
run: |
# Create Jira issue using REST API
# Create a temporary file for the JSON payload to handle proper escaping
cat > /tmp/jira_payload.json << 'EOF'
{
"fields": {
"project": {
"key": "${{ secrets.JIRA_PROJECT_KEY }}"
},
"issuetype": {
"name": "${{ steps.extract-type.outputs.issue_type }}"
},
"summary": "[xperience-by-kentico-tag-manager] ${{ github.event.issue.title }}",
"assignee": {
"accountId": "${{ secrets.JIRA_ASSIGNEE_ACCOUNT_ID }}"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "GitHub Issue created by: ${{ github.event.issue.user.login }}\nRepository: ${{ github.repository }}\nIssue URL: ${{ github.event.issue.html_url }}\nLabels: ${{ steps.extract-type.outputs.labels }}\n\n---\n\n"
}
]
}
]
}
}
}
EOF
# Add the issue body as a separate paragraph to avoid JSON escaping issues
# Use jq to properly escape and add the issue body
ISSUE_BODY=$(echo '${{ github.event.issue.body }}' | jq -Rs .)
# Update the JSON payload with the properly escaped issue body
jq --argjson body "$ISSUE_BODY" \
'.fields.description.content += [{"type": "paragraph", "content": [{"type": "text", "text": $body}]}]' \
/tmp/jira_payload.json > /tmp/jira_payload_final.json
# Make the API call with the properly formatted JSON
curl -X POST \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-u "${{ secrets.JIRA_USER_EMAIL }}:${{ secrets.JIRA_API_TOKEN }}" \
-d @/tmp/jira_payload_final.json \
"${{ secrets.JIRA_BASE_URL }}/rest/api/3/issue"