-
Notifications
You must be signed in to change notification settings - Fork 1
DEVOPS-853: check jira issue #147
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
andrewg-mira
wants to merge
7
commits into
main
Choose a base branch
from
DEVOPS-853-check-jira-issue
base: main
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da9ef2e
DEVOPS-853 check if Jira issue in open or future sprint
andrewg-mira 4d59de0
DEVOPS-853 add check for Jira issue In Progress
andrewg-mira e1a01be
DEVOPS-853 only run add_jira_summary on PR open
andrewg-mira a4460f1
DEVOPS-853 add check-jira-issue to other workflow file
andrewg-mira 228af07
Revert "DEVOPS-853 add check-jira-issue to other workflow file"
andrewg-mira 176016c
DEVOPS-853 jira-pr_actions
andrewg-mira 656611e
DEVOPS-853 do not raise error if issue key not found
andrewg-mira 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,161 @@ | ||
| # This workflow will comment the PR with the JIRA issue summary | ||
| # if a JIRA issue number is detected in the branch name or title | ||
|
|
||
| name: Jira issue jobs | ||
|
|
||
| on: | ||
| workflow_call: | ||
| secrets: | ||
| JIRA_BASE_URL: | ||
| required: true | ||
| description: The base URL of your JIRA instance | ||
| JIRA_USER_EMAIL: | ||
| required: true | ||
| description: The email address for your JIRA account | ||
| JIRA_API_TOKEN: | ||
| required: true | ||
| description: The API token for your JIRA account | ||
|
|
||
| env: | ||
| JIRA_PATTERN: "([A-Z]+)[-# ]*([0-9]+)" | ||
| JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | ||
| JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | ||
| JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | ||
|
|
||
| jobs: | ||
| get_issue_key: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| outputs: | ||
| issue_key_from_branch: steps.jira_key_from_branch.output.issue_key | ||
| issue_key_from_title: steps.jira_key_from_title.output.issue_key | ||
|
|
||
| steps: | ||
| - name: Find JIRA issue key from branch | ||
| id: jira_key_from_branch | ||
| env: | ||
| HEAD_REF: ${{ github.head_ref }} | ||
| run: > | ||
| echo "issue_key=$( | ||
| echo $HEAD_REF | grep -osiE "$JIRA_PATTERN" | ||
| | head -n1 | sed -E "s/\W*$JIRA_PATTERN/\1-\2/i" | ||
| | tr [:lower:] [:upper:] | ||
| )" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Find JIRA issue key from title | ||
| id: jira_key_from_title | ||
| env: | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| run: > | ||
| echo "issue_key=$( | ||
| echo $PR_TITLE | grep -osiE "^\s*\[?\s*$JIRA_PATTERN" | ||
| | head -n1 | sed -E "s/\W*$JIRA_PATTERN/\1-\2/i" | ||
| | tr [:lower:] [:upper:] | ||
| )" >> $GITHUB_OUTPUT | ||
|
|
||
| add_jira_summary: | ||
| if: ${{ github.event.action == 'opened' }} | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| needs: get_issue_key | ||
|
|
||
| steps: | ||
|
|
||
| - name: Get JIRA summary from branch | ||
| if: ${{ needs.get_issue_key.outputs.issue_key_from_branch }} | ||
| id: jira_summary_from_branch | ||
| run: > | ||
| curl -sS -X GET | ||
| -u "${JIRA_USER_EMAIL}:${JIRA_API_TOKEN}" | ||
| -H "Content-Type: application/json" | ||
| "$JIRA_BASE_URL/rest/api/2/issue/${{ needs.get_issue_key.outputs.issue_key_from_branch }}" | ||
| | echo "summary=$(jq -r '.fields.summary // empty' | xargs)" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Get JIRA summary from title | ||
| if: ${{ !steps.jira_summary_from_branch.outputs.summary && needs.get_issue_key.outputs.issue_key_from_title }} | ||
| id: jira_summary_from_title | ||
| run: > | ||
| curl -sS -X GET | ||
| -u "${JIRA_USER_EMAIL}:${JIRA_API_TOKEN}" | ||
| -H "Content-Type: application/json" | ||
| "$JIRA_BASE_URL/rest/api/2/issue/${{ needs.get_issue_key.outputs.issue_key_from_title }}" | ||
| | echo "summary=$(jq -r '.fields.summary // empty' | xargs)" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Extract PR title | ||
| id: get_pr_title | ||
| if: ${{ steps.jira_summary_from_branch.outputs.summary || steps.jira_summary_from_title.outputs.summary }} | ||
| env: | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| run: | | ||
| echo "text=$(echo $PR_TITLE | sed -E "s/^\s*[?[A-Z]+[-# ]*[0-9]+]?[-: ]*(.*)/\1/i")" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Add comment | ||
| if: ${{ steps.jira_summary_from_branch.outputs.summary || steps.jira_summary_from_title.outputs.summary }} | ||
| env: | ||
| ISSUE_SUMMARY: ${{ steps.jira_summary_from_branch.outputs.summary || steps.jira_summary_from_title.outputs.summary }} | ||
| ISSUE_KEY: ${{ steps.jira_summary_from_branch.outputs.summary && steps.jira_key_from_branch.outputs.issue_key || steps.jira_key_from_title.outputs.issue_key }} | ||
| TITLE_TEXT: ${{ steps.get_pr_title.outputs.text }} | ||
| PR_BODY: ${{ github.event.pull_request.body }} | ||
| run: > | ||
| jq | ||
| --arg ISSUE_ID "$(cat <<< $ISSUE_KEY)" | ||
| --arg ISSUE_SUMMARY "$(cat <<< $ISSUE_SUMMARY)" | ||
| --arg TITLE_TEXT "$(cat <<< ${TITLE_TEXT:-$ISSUE_SUMMARY})" | ||
| --arg PR_BODY "$(cat <<< $PR_BODY)" | ||
| -c '{"title": ($ISSUE_ID + ": " + $TITLE_TEXT), "body": ("**" + $ISSUE_ID + " - " + $ISSUE_SUMMARY + "**\n" + $PR_BODY)}' <<< {} | ||
| | curl -sS -X POST -d @- | ||
| -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" | ||
| -H "Content-Type: application/json" | ||
| "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls/${{ github.event.pull_request.number }}" | ||
| > /dev/null | ||
|
|
||
| check_jira_issue: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| needs: get_issue_key | ||
|
|
||
| - name: Check issue key | ||
| if: ${{ !needs.get_issue_key.outputs.issue_key_from_title && !needs.get_issue_key.outputs.issue_key_from_branch }} | ||
| run: | | ||
| echo "Could not determine Jira issue" | ||
|
|
||
| - name: Check issue status | ||
| if: ${{ needs.get_issue_key.outputs.issue_key_from_title || needs.get_issue_key.outputs.issue_key_from_branch }} | ||
| run: | | ||
| issue_key=${{ needs.get_issue_key.output.issue_key_from_title }} | ||
| if [ -z "$issue_key" ]; then | ||
| issue_key=${{ needs.get_issue_key.output.issue_key_from_branch }} | ||
| fi | ||
| jql="Sprint in (openSprints(), futureSprints()) and issue=$issue_key" | ||
| jqlencoded=$(jq -R -r @uri <<<"$jql") | ||
| response=$(curl -s --request GET \ | ||
| --url "$JIRA_BASE_URL/rest/api/3/search/jql?jql=$jqlencoded&fields=statusCategory" \ | ||
| --user "${JIRA_USER_EMAIL}:${JIRA_API_TOKEN}" \ | ||
| --header 'Accept: application/json' \ | ||
| --header 'Content-Type: application/json') | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "Jira API: error" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "response was: $(echo $response|jq)" | ||
| error="" | ||
|
|
||
| echo "Checking if issue is in open or future sprint" | ||
| sprint=$(echo $response | jq '.issues | length') | ||
| if [ $sprint -eq 0 ]; then | ||
| error="Error: Jira issue is not in open or future sprint" | ||
| fi | ||
|
|
||
| echo "Checking if issue is In Progress" | ||
| status=$(echo $response| jq -r '.issues[0].fields.statusCategory.name') | ||
| if [ "$status" != "In Progress" ]; then | ||
| error="$error Error: Jira issue is not In Progress" | ||
| fi | ||
|
|
||
| if [[ ! -z "$error" ]]; then | ||
| echo $error | ||
| exit 1 | ||
| fi | ||
|
|
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
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,85 @@ | ||
| # This workflow will comment the PR with the JIRA issue summary | ||
| # if a JIRA issue number is detected in the branch name or title | ||
|
|
||
| name: Check Jira Issue | ||
|
|
||
| on: | ||
| workflow_call: | ||
| secrets: | ||
| JIRA_BASE_URL: | ||
| required: true | ||
| description: The base URL of your JIRA instance | ||
| JIRA_USER_EMAIL: | ||
| required: true | ||
| description: The email address for your JIRA account | ||
| JIRA_API_TOKEN: | ||
| required: true | ||
| description: The API token for your JIRA account | ||
|
|
||
|
|
||
| jobs: | ||
| check_jira_issue: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| env: | ||
| JIRA_PATTERN: "([A-Z]+)[-# ]*([0-9]+)" | ||
| JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | ||
| JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | ||
| JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | ||
|
|
||
| steps: | ||
|
|
||
| - name: Find JIRA issue key from title | ||
| id: jira_key_from_title | ||
| if: ${{ !steps.jira_summary_from_branch.outputs.summary }} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: |
||
| env: | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| run: > | ||
| echo "issue_key=$( | ||
| echo $PR_TITLE | grep -osiE "^\s*\[?\s*$JIRA_PATTERN" | ||
| | head -n1 | sed -E "s/\W*$JIRA_PATTERN/\1-\2/i" | ||
| | tr [:lower:] [:upper:] | ||
| )" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Check issue key | ||
| if: ${{ !steps.jira_key_from_title.outputs.issue_key }} | ||
| run: | | ||
| echo "Could not determine Jira issue from PR title" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably TODO: add exceptions for Dependabot etc PRs. |
||
| exit 1 | ||
|
|
||
| - name: Check issue status | ||
| if: ${{ steps.jira_key_from_title.outputs.issue_key }} | ||
| run: | | ||
| jql="Sprint in (openSprints(), futureSprints()) and issue=${{ steps.jira_key_from_title.outputs.issue_key }}" | ||
| jqlencoded=$(jq -R -r @uri <<<"$jql") | ||
| response=$(curl -s --request GET \ | ||
| --url "$JIRA_BASE_URL/rest/api/3/search/jql?jql=$jqlencoded&fields=statusCategory" \ | ||
| --user "${JIRA_USER_EMAIL}:${JIRA_API_TOKEN}" \ | ||
| --header 'Accept: application/json' \ | ||
| --header 'Content-Type: application/json') | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "Jira API: error" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "response was: $(echo $response|jq)" | ||
| error="" | ||
|
|
||
| echo "Checking if issue is in open or future sprint" | ||
| sprint=$(echo $response | jq '.issues | length') | ||
| if [ $sprint -eq 0 ]; then | ||
| error="Error: Jira issue is not in open or future sprint" | ||
| fi | ||
|
|
||
| echo "Checking if issue is In Progress" | ||
| status=$(echo $response| jq -r '.issues[0].fields.statusCategory.name') | ||
| if [ "$status" != "In Progress" ]; then | ||
| error="$error Error: Jira issue is not In Progress" | ||
| fi | ||
|
|
||
| if [[ ! -z "$error" ]]; then | ||
| echo $error | ||
| exit 1 | ||
| fi | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might run too soon. Somehow, we want it executed after
pr_add_jira_summaryPossibly just have "Check issue status" as an extra step in
pr_add_jira_summary.However, "Check issue status" must reran at every push (e.g. to error out when pushing to a closed issue).
My suggesting: merge the two workflow into one "Check Jira Status", with "Check JIRA issue status" step last:
pull_request[opened], run all stepspull_request[synchronize, reopened, ready_for_review], only run steps:Not finding JIRA from title is not an error.
Possible, use a secret to configure the pattern of supported key, e.g. "\b(NI|SHRUB|BEAST|AARG|SWALLOW|TIM|BRIDGE)[-# ]*([0-9]+)"