|
|
@@ -23,7 +23,6 @@ jobs:
|
|
|
PROJECT_KEY: VEN
|
|
|
run: |
|
|
|
set -e # Exit on any error
|
|
|
- set -x # Print each command before execution
|
|
|
|
|
|
# Verify environment variables
|
|
|
if [ -z "$JIRA_EMAIL" ] || [ -z "$JIRA_TOKEN" ] || [ -z "$JIRA_BASE" ]; then
|
|
|
@@ -43,28 +42,35 @@ jobs:
|
|
|
# Prepare the data with error checking
|
|
|
SUMMARY=$(jq -Rs . <<<"${{ github.event.issue.title }}" || { echo "Error processing summary"; exit 1; })
|
|
|
DESC=$(jq -Rs . <<<"Imported from GitHub: $GH_URL" || { echo "Error processing description"; exit 1; })
|
|
|
- JQL=$(jq -Rs . <<<"description ~ \"$GH_URL\"" || { echo "Error processing JQL"; exit 1; })
|
|
|
|
|
|
- echo "Summary: $SUMMARY"
|
|
|
- echo "Description: $DESC"
|
|
|
- echo "JQL: $JQL"
|
|
|
-
|
|
|
- # URL encode the JQL query
|
|
|
- ENCODED_JQL=$(echo "$JQL" | jq -sRr @uri)
|
|
|
- SEARCH="$JIRA_BASE/rest/api/3/search?jql=$ENCODED_JQL"
|
|
|
+ # Create the JQL match request body
|
|
|
+ MATCH_BODY=$(jq -n --arg url "$GH_URL" --arg proj "$PROJECT_KEY" '
|
|
|
+ {
|
|
|
+ "jqls": [
|
|
|
+ "project = \($proj) AND description ~ \"\($url)\""
|
|
|
+ ]
|
|
|
+ }' || {
|
|
|
+ echo "Error creating JQL match request body"
|
|
|
+ exit 1
|
|
|
+ })
|
|
|
|
|
|
- echo "Searching Jira with URL: $SEARCH"
|
|
|
+ echo "JQL match request body: $MATCH_BODY"
|
|
|
|
|
|
- # Search with error checking
|
|
|
- SEARCH_RESULT=$(curl -f -s -u "$JIRA_EMAIL:$JIRA_TOKEN" "$SEARCH" || {
|
|
|
- echo "Error: Jira search failed with status $?"
|
|
|
- exit 1
|
|
|
- })
|
|
|
+ # Search with JQL match endpoint
|
|
|
+ SEARCH_RESULT=$(curl -f -s -u "$JIRA_EMAIL:$JIRA_TOKEN" \
|
|
|
+ -H "Content-Type: application/json" \
|
|
|
+ -H "Accept: application/json" \
|
|
|
+ --data "$MATCH_BODY" \
|
|
|
+ "$JIRA_BASE/rest/api/3/jql/match" || {
|
|
|
+ echo "Error: Jira JQL match failed with status $?"
|
|
|
+ exit 1
|
|
|
+ })
|
|
|
|
|
|
echo "Search result: $SEARCH_RESULT"
|
|
|
|
|
|
# Parse the key with error checking
|
|
|
- KEY=$(echo "$SEARCH_RESULT" | jq -r '.issues[0].key // empty' || {
|
|
|
+ # The JQL match endpoint returns an array of matching JQLs, we need to get the first matching issue
|
|
|
+ KEY=$(echo "$SEARCH_RESULT" | jq -r 'if .matchedJQLs[0] then .matchedJQLs[0].issues[0].key else empty end' || {
|
|
|
echo "Error parsing search result"
|
|
|
exit 1
|
|
|
})
|