Skip to content

test PR pipeline for JIRA synchronisation (EIM-130) #9

test PR pipeline for JIRA synchronisation (EIM-130)

test PR pipeline for JIRA synchronisation (EIM-130) #9

Workflow file for this run

name: Pull Request Jira Integration
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
update-jira:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract Jira ticket ID
id: extract-ticket
env:
JIRA_PROJECT: EIM
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
PR_BODY="${{ github.event.pull_request.body }}"
# Look for Jira ticket pattern (e.g., EIM-123) in title and body
TICKET_PATTERN="${{ env.JIRA_PROJECT }}-[0-9]+"
TITLE_TICKET=$(echo "$PR_TITLE" | grep -oE "$TICKET_PATTERN" || echo "")
BODY_TICKET=$(echo "$PR_BODY" | grep -oE "$TICKET_PATTERN" || echo "")
TICKET_ID="$TITLE_TICKET"
if [ -z "$TICKET_ID" ]; then
TICKET_ID="$BODY_TICKET"
fi
if [ -z "$TICKET_ID" ]; then
echo "No Jira ticket ID found in PR title or description"
exit 1
fi
echo "ticket_id=$TICKET_ID"
echo "ticket_id=$TICKET_ID" >> $GITHUB_OUTPUT
- name: Comment on Jira ticket
env:
JIRA_BASE_URL: ${{ secrets.JIRA_URL }}
JIRA_USER: ${{ secrets.JIRA_USER }}
JIRA_PASS: ${{ secrets.JIRA_PASS }}
TICKET_ID: ${{ steps.extract-ticket.outputs.ticket_id }}
run: |
# Prepare the JSON payload for the comment
COMMENT_DATA=$(cat <<EOF
{
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Pull Request Update:\n- Title: ${{ github.event.pull_request.title }}\n- URL: ${{ github.event.pull_request.html_url }}\n- Status: ${{ github.event.pull_request.state }}\n- Last Updated: ${{ github.event.pull_request.updated_at }}"
}
]
}
]
}
}
EOF
)
# Send the request to Jira API
curl -X POST \
--url "${JIRA_BASE_URL}/rest/api/3/issue/${TICKET_ID}/comment" \
--user "${JIRA_USER}:${JIRA_PASS}" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data "$COMMENT_DATA" \
--fail