From 1afc243acd7a1bbf45f8b3c7dd9b0a891483acf3 Mon Sep 17 00:00:00 2001 From: Petr Gadorek Date: Thu, 6 Feb 2025 12:01:48 +0100 Subject: [PATCH] test PR pipeline for JIRA synchronisation (EIM-130) --- .github/workflows/pr-jira-sync.yml | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/pr-jira-sync.yml diff --git a/.github/workflows/pr-jira-sync.yml b/.github/workflows/pr-jira-sync.yml new file mode 100644 index 0000000..0ef59ac --- /dev/null +++ b/.github/workflows/pr-jira-sync.yml @@ -0,0 +1,65 @@ +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" >> $GITHUB_OUTPUT + + - name: Process Jira token + id: process-token + run: | + # Remove 'token:' prefix if it exists + RAW_TOKEN='${{ secrets.JIRA_PASS }}' + CLEAN_TOKEN=$(echo "$RAW_TOKEN" | sed 's/^token://') + echo "clean_token=$CLEAN_TOKEN" >> $GITHUB_OUTPUT + + - name: Login to Jira + uses: atlassian/gajira-login@v3 + env: + JIRA_BASE_URL: ${{ secrets.JIRA_URL }} + JIRA_USER_EMAIL: ${{ secrets.JIRA_USER }} + JIRA_API_TOKEN: ${{ steps.process-token.outputs.clean_token }} + + - name: Comment on Jira ticket + uses: atlassian/gajira-comment@v3 + with: + issue: ${{ steps.extract-ticket.outputs.ticket_id }} + comment: | + Pull Request Update: + - Title: ${{ github.event.pull_request.title }} + - Description: ${{ github.event.pull_request.body }} + - URL: ${{ github.event.pull_request.html_url }} + - Status: ${{ github.event.pull_request.state }} + - Last Updated: ${{ github.event.pull_request.updated_at }}