Skip to content

Commit

Permalink
adjust for ora jira
Browse files Browse the repository at this point in the history
  • Loading branch information
auhlig committed Jun 4, 2024
1 parent 78235b9 commit 29c2fdf
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 51 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/example.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Sync GitHub issues to Jira example
on: [issues, issue_comment]
on: [issues]

jobs:
sync-issues:
Expand All @@ -9,4 +9,9 @@ jobs:
- uses: actions/checkout@v2
- uses: ./
with:
webhook-url: ${{ secrets.JIRA_WEBHOOK_URL }}
JIRA_URL: ${{ secrets.JIRA_URL }}
JIRA_USERNAME: ${{ secrets.JIRA_USERNAME }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
JIRA_COMPONENT: ${{ secrets.JIRA_COMPONENT }}
JIRA_PROJECT_KEY: ${{ secrets.JIRA_PROJECT_KEY }}
JIRA_EPIC_KEY: ${{ secrets.JIRA_EPIC_KEY }}
112 changes: 63 additions & 49 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
name: 'Sync github issues to jira'
inputs:
webhook-url:
description: >
Jira integration webhook URL.
Store it as a secret as anyone who has access to it will be able to post to your Jira board.
JIRA_URL:
description: Jira URL domain to be stored as a secret.
required: true
component:
description: 'Jira component to attach your issue to. This component should exists in your project.'
JIRA_USERNAME:
description: Jira username to be stored as a secret.
required: true
JIRA_API_TOKEN:
description: Jira API token to be stored as a secret.
required: true
JIRA_COMPONENT:
description: Jira component to be stored as a secret.
required: true
JIRA_PROJECT_KEY:
description: Jira project key to be stored as a secret.
required: true
JIRA_EPIC_KEY:
description: Jira epic key to be stored as a secret.
required: true
JIRA_ISSUE_TYPE:
description: Jira issue type.
required: false
default: "Feature"
JIRA_LINK_TYPE:
description: Jira link type.
required: false
default: "Dependency"
label:
description: 'Label which will trigger a Jira import.'
required: true
Expand Down Expand Up @@ -75,6 +93,7 @@ runs:
component: ${{ inputs.component }}
commentAuthor: ${{ github.actor }}
comment: ${{ github.event.comment.body }}
shell: bash
run: |
set -eux
Expand All @@ -94,46 +113,41 @@ runs:
fi
description="${body}
Opened by ${author}."
commentContent=""
# Choose Jira action based on event type and action.
action=""
if [ ${{ github.event_name }} == "issues" ]; then
action=Update
if [ ${{ github.event.action }} == "labeled" ]; then
action=Create
elif [ ${{ github.event.action }} == "reopened" ]; then
action=Reopen
elif [ ${{ github.event.action }} == "deleted" ] || [ ${{ github.event.action }} == "unlabeled" ]; then
# Note: deleting issue from GH is not supported ATM as there is no more label attached. unlabeled is supported.
action=Delete
elif [ ${{ github.event.action }} == "closed" ]; then
action=Close
fi
else
action=AddComment
if [ ${{ github.event.action }} == "deleted" ]; then
echo "Deleting comment on Jira is not supported ATM, skipping."
exit 0
fi
# For now, editing comments will add a new one on Jira.
commentContent="From ${commentAuthor}:
${comment}"
fi
echo "PUSHING: $id $action $title $description $component $commentContent"
# Push to Jira as a json data format.
data=$(jq -n \
--arg id "$id" \
--arg action "$action" \
--arg title "$title" \
--arg description "$description" \
--arg component "$component" \
--arg commentContent "$commentContent" \
'{data: {id: $id, action: $action, title: $title, description: $description, component: $component, commentContent: $commentContent}}')
curl -X POST -H 'Content-type: application/json' --data "${data}" '${{ inputs.webhook-url }}'
shell: bash
# Create the new issue
create_response=$(curl -s -u "${{ inputs.JIRA_USERNAME}}:${{ inputs.JIRA_API_TOKEN}}" -X POST -H "Content-Type: application/json" --data '{
"fields": {
"project": {
"key": "${{ inputs.JIRA_PROJECT_KEY }}"
},
"summary": "$title",
"description": "$description",
"issuetype": {
"name": "${{ inputs.JIRA_ISSUE_TYPE }}"
},
"components": [
{
"name": "${{ inputs.JIRA_COMPONENT }}"
}
],
"customfield_10008": "${{ inputs.JIRA_EPIC_KEY }}"
}
}' "https://${{ inputs.JIRA_URL }}/rest/api/2/issue/")
# Extract the new issue key from the response
new_issue_key=$(echo $create_response | jq -r '.key')
# Link the new issue to the existing issue
curl -u "${{ inputs.JIRA_USERNAME}}:${{ inputs.JIRA_API_TOKEN}}" -X POST -H "Content-Type: application/json" --data '{
"type": {
"name": "${{ inputs.JIRA_LINK_TYPE }}"
},
"inwardIssue": {
"key": "${{inputs.DEPENDENT_ISSUE}}"
},
"outwardIssue": {
"key": "$new_issue_key"
}
}' "https://${{ inputs.JIRA_URL }}/rest/api/2/issueLink"
echo "Created issue $new_issue_key and linked it as a dependency to ${{ inputs.DEPENDENT_ISSUE}}"

0 comments on commit 29c2fdf

Please sign in to comment.