-
Notifications
You must be signed in to change notification settings - Fork 67
OKRF23-54 Add GitHub action to sync labeled issue to Jira board #1354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dmytrotsko
wants to merge
4
commits into
dev
Choose a base branch
from
OKRF23-54-Jira-GitHub-Integration
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
156c4a7
OKRF23-54 Adde GitHub action to sync labeled issue to Jira board
dmytrotsko 193a838
OKRF23-54 Updated sync-issue-to-jira action.
dmytrotsko 6fce1ef
Merge branch 'dev' into OKRF23-54-Jira-GitHub-Integration
dmytrotsko 0795e20
Merge branch 'dev' into OKRF23-54-Jira-GitHub-Integration
dmytrotsko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| name: "Sync GitHub issue to Jira" | ||
| description: 'This GitHub action creates Jira issue from GitHub issue when GitHub issue is labeled with "jira" label.' | ||
| 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. | ||
| required: true | ||
| label: | ||
| description: "Label which will trigger a Jira import." | ||
| required: true | ||
| default: "jira" | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: restrict action to labelled issues | ||
| run: | | ||
| set -eux | ||
|
|
||
| echo "NeedsJiraUpdate=false" >> $GITHUB_ENV | ||
|
|
||
| if [ ${{ github.event_name }} != "issues" ]; then | ||
| echo "This action only work on issue events. Please use on: issues to use this action." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ ${{ github.event.issue.pull_request }} ]; then | ||
| echo "This action only work on issues, not pull requests." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Issue creation with label will trigger 2 events and run twice: one create, one labelled. | ||
| # let just focus on labelling then for creating issues Jira-side. | ||
| if [ ${{ github.event_name }} == "issues" ] && [ ${{ github.event.action }} == "opened" ]; then | ||
| echo "Ignoring creation of issues as a label will trigger a second event." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # We only operate on labelled issues or issues that are just unlabeled with our desired label | ||
| ## check if one label of labels is our jira label | ||
| toconsider=${{ contains(github.event.issue.labels.*.name, inputs.label) }} | ||
| ## second chance, this has just been unlabeled and needs to be deleted on Jira | ||
| if [ ${{ github.event.action }} == "unlabeled" ] && [ ${{ github.event.label.name }} == ${{ inputs.label }} ]; then | ||
| toconsider=true | ||
| fi | ||
| if [ "${toconsider}" == false ]; then | ||
| echo "Our desired label not found on issue or not unlabeled, skipping" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # And finally, for the "labeled" event, we are only interested if the new added label is our desired one. | ||
| if [ ${{ github.event.action }} == "labeled" ] && [ ${{ github.event.label.name }} != ${{ inputs.label }} ]; then | ||
| echo "Not interested in this action, skipping" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # last one wins | ||
| echo "NeedsJiraUpdate=true" >> $GITHUB_ENV | ||
| shell: bash | ||
|
|
||
| - name: "Update jira" | ||
| if: ${{ env.NeedsJiraUpdate == 'true' }} | ||
| env: | ||
| # ID is the html url to keep a link between systems as there is no way to force an ID on Jira side. | ||
| id: ${{ github.event.issue.html_url }} | ||
| title: ${{ github.event.issue.title }} | ||
| body: ${{ github.event.issue.body }} | ||
| author: ${{ github.event.issue.user.login }} | ||
| run: | | ||
| set -eux | ||
|
|
||
| # Convert markdown to JIRA using mistletoe package which is available starting with impish. | ||
| # Since GH runners only have LTS versions it's safe to only check for focal which doesn't have the package. | ||
| if [ $(lsb_release -c -s) == "focal" ]; then | ||
| echo "Converting Markdown to JIRA is only possible starting with Ubuntu 22.04 (jammy). Pushing verbatim content to JIRA..." | ||
| else | ||
| TMPDIR=$(mktemp -d) | ||
| trap 'rm -rf -- "$TMPDIR"' EXIT | ||
|
|
||
| sudo apt install -y python3-mistletoe | ||
| echo ${body} > $TMPDIR/body.md | ||
| body=$(PYTHONPATH=/usr/share/doc/python3-mistletoe mistletoe -r examples.jira_renderer.JIRARenderer $TMPDIR/body.md) | ||
| fi | ||
|
|
||
| description="${body} | ||
|
|
||
|
|
||
| GitHub URL: ${id}. | ||
|
|
||
| Opened by ${author}." | ||
|
|
||
| # Choose Jira action based on event type and action. | ||
| action="" | ||
| if [ ${{ github.event_name }} == "issues" ]; then | ||
dmytrotsko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
dmytrotsko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| elif [ ${{ github.event.action }} == "closed" ]; then | ||
| action=Close | ||
| fi | ||
| fi | ||
|
|
||
| echo "PUSHING: $id $action $title $description" | ||
|
|
||
| # Push to Jira as a json data format. | ||
| data=$(jq -n \ | ||
| --arg id "$id" \ | ||
| --arg action "$action" \ | ||
| --arg title "$title" \ | ||
| --arg description "$description" \ | ||
| '{data: {id: $id, action: $action, title: $title, description: $description}}') | ||
| curl -X POST -H 'Content-type: application/json' --data "${data}" '${{ inputs.webhook-url }}' | ||
|
|
||
| shell: bash | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| name: Sync GitHub issues to Jira | ||
| on: [issues] | ||
|
|
||
| jobs: | ||
| sync-issues: | ||
| name: Sync issues to Jira | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - uses: ./.github/actions/sync_with_jira/ | ||
dmytrotsko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| with: | ||
| webhook-url: ${{ secrets.JIRA_WEBHOOK }} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.