Skip to content

Commit

Permalink
add assignees to jira ticket workflow 3
Browse files Browse the repository at this point in the history
  • Loading branch information
“Dafydd committed Oct 31, 2024
1 parent dd17fda commit 08009e7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
37 changes: 30 additions & 7 deletions .github/workflows/create_jira_tickets.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
#!/bin/bash

# Escape double quotes in ISSUE_TITLE and ISSUE_BODY
# ESCAPED_TITLE=$(echo "$ISSUE_TITLE" | sed 's/"/\\"/g')
# ESCAPED_BODY=$(echo "$ISSUE_BODY" | sed 's/"/\\"/g')

# Escape double quotes in ISSUE_TITLE
ESCAPED_TITLE="${ISSUE_TITLE//\"/\\\"}"

# Escape double quotes and newlines in ISSUE_BODY
ESCAPED_BODY="${ISSUE_BODY//\"/\\\"}"
ESCAPED_BODY="${ESCAPED_BODY//$'\n'/\\n}"
#ESCAPED_BODY="${ESCAPED_BODY//$'\n'/\\n}"

# Use readarray to populate TASKS array directly from matching lines in ISSUE_BODY
readarray -t TASKS < <(echo "$ISSUE_BODY" | grep -E '^- \[[ x]\] ')

# Create the JSON payload directly
cat > payload.json <<EOF
# Trim and set GITHUB_ASSIGNEE_USERNAME if needed
GITHUB_ASSIGNEE_USERNAME=$(echo "$GITHUB_ASSIGNEE_USERNAME" | xargs)

# Map GitHub username to Jira account ID directly
declare -A JIRA_IDS=(
["TomNicholas"]="712020:035c37ae-65d0-49c2-aa10-89ecfde5257a"
["NoraLoose"]="712020:383dc845-6121-46b3-a5f9-3b90a54478a5"
["dafyddstephenson"]="712020:41094963-a473-4408-9c16-c445f195fd65"
)

JIRA_ASSIGNEE_ID="${JIRA_IDS[$GITHUB_ASSIGNEE_USERNAME]}"


# Create the JSON payload, adding assignee if there is one
if [[ -n "$JIRA_ASSIGNEE_ID" ]]; then
cat > payload.json <<EOF
{
"fields": {
"project": { "key": "CW" },
"summary": "$ESCAPED_TITLE",
"description": "$ESCAPED_BODY",
"issuetype": { "name": "Story" },
"assignee": { "accountId": "$JIRA_ASSIGNEE_ID" }
}
}
EOF
else
cat > payload.json <<EOF
{
"fields": {
"project": { "key": "CW" },
Expand All @@ -25,6 +47,7 @@ cat > payload.json <<EOF
}
}
EOF
fi

# Display the JSON content for verification
echo "Generated JSON payload:"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/jira.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:
JIRA_API_TOKEN_DAFYDD: ${{ secrets.JIRA_API_TOKEN_DAFYDD }}
ISSUE_TITLE: "${{ github.event.issue.title }}"
ISSUE_BODY: "${{ github.event.issue.body }}"
GITHUB_ASSIGNEE_USERNAME: "${{ github.event.issue.assignee.login }}"
run: .github/workflows/create_jira_tickets.sh

0 comments on commit 08009e7

Please sign in to comment.