Skip to content

Commit

Permalink
[FX-4787] Create tickets for major dependabot updates (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashuk authored Feb 8, 2024
1 parent 2fe7d47 commit 9a2ad2f
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-jokes-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'davinci-github-actions': minor
---

- enable notify-jira-about-contribution action to create tickets for major dependabot pull requests
16 changes: 9 additions & 7 deletions notify-jira-about-contribution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ Notifies JIRA about external contribution. Draft and dependabot PRs are ignored.

The list of arguments, that are used in GH Action:

| name | type | required | default | description |
| -------------- | ------ | -------- | ------- | ------------------------------------- |
| `team` | string || | Team that we are checking against |
| `repo` | string || | Repository name |
| `pull-number` | string || | Nth pull request |
| `jira-hook` | string || | JIRA automation hook for contribution |
| `github-token` | string || | Token for authorization |
| name | type | required | default | description |
| --------------------------------------- | ------ | -------- | -------------------- | ------------------------------------- |
| `team` | string || | Team that we are checking against |
| `repo` | string || | Repository name |
| `pull-number` | string || | Nth pull request |
| `jira-hook` | string || | JIRA automation hook for contribution |
| `github-token` | string || | Token for authorization |
| `notify-about-major-dependabot-updates` | string | | | Notify about major dependabot updates |
| `dependabot-ticket-jira-label` | string | | ready-for-refinement | Label for dependabot ticket in JIRA |

### Outputs

Expand Down
92 changes: 80 additions & 12 deletions notify-jira-about-contribution/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ inputs:
github-token:
required: true
description: Token for authorization
notify-about-major-dependabot-updates:
required: false
description: Notify about major dependabot updates
type: boolean
default: false
dependabot-ticket-jira-label:
required: false
description: Label for dependabot ticket in JIRA
default: "ready-for-refinement"

runs:
using: composite
Expand All @@ -32,35 +41,94 @@ runs:
pull-number: ${{ inputs.pull-number }}
GITHUB_TOKEN: ${{ inputs.github-token }}

- uses: toptal/davinci-github-actions/is-team-member@v6.0.0
- name: Check if author is a member of specific team
uses: toptal/davinci-github-actions/is-team-member@v6.0.0
id: is-team-member
with:
team: ${{ inputs.team }}
login: ${{ fromJson(steps.get-pr.outputs.data).user.login }}
github-token: ${{ inputs.github-token }}

- name: Define if PR is eligible - PR authored by external contributor and is not draft
- name: Check if PR comes fron dependabot
env:
IS_NOT_DEPENDABOT_BOT: ${{ fromJson(steps.get-pr.outputs.data).user.login != 'dependabot[bot]' }}
id: is-pr-eligible
IS_DEPENDABOT: ${{ fromJson(steps.get-pr.outputs.data).user.login == 'dependabot[bot]' }}
id: is-dependabot
shell: bash
run: |
echo "result=${{ fromJson(steps.is-team-member.outputs.result) == false && fromJson(steps.get-pr.outputs.data).draft == false && env.IS_NOT_DEPENDABOT_BOT }}" >> $GITHUB_OUTPUT
echo "result=${{ env.IS_DEPENDABOT }}" >> $GITHUB_OUTPUT
- name: Jira issue can be created
id: jira-issue-can-be-created
- name: Check if Jira issue already exists
id: jira-issue-already-exists
shell: bash
run: |
echo "result=${{ fromJson(steps.is-pr-eligible.outputs.result) == true && !contains(github.event.pull_request.labels.*.name, 'contribution') }}" >> $GITHUB_OUTPUT
echo "result=${{ contains(github.event.pull_request.labels.*.name, 'contribution') }}" >> $GITHUB_OUTPUT
- name: Decide if Jira ticket needs to be created
id: is-pr-eligible
env:
IS_TEAM_MEMBER: ${{ fromJson(steps.is-team-member.outputs.result) }}
IS_DEPENDABOT: ${{ steps.is-dependabot.outputs.result }}
IS_DRAFT: ${{ fromJson(steps.get-pr.outputs.data).draft }}
NOTIFY_ABOUT_MAJOR_DEPENDABOT_UPDATES: ${{ inputs.notify-about-major-dependabot-updates }}
JIRA_ISSUE_ALREADY_EXISTS: ${{ steps.jira-issue-already-exists.outputs.result }}
PR_TITLE: ${{ fromJson(steps.get-pr.outputs.data).title }}
shell: bash
run: |
echo "Checking if Jira ticket already exists or PR is a draft"
if [[ ${{ env.JIRA_ISSUE_ALREADY_EXISTS }} == "true" || ${{ env.IS_DRAFT }} == "true" ]]; then
echo "result=false" >> $GITHUB_OUTPUT
exit
fi
update_string="${{ env.PR_TITLE }}"
old_version=$(echo "$update_string" | awk '{match($0, /[0-9]+(\.[0-9]+)*/, arr); print arr[0]}')
new_version=$(echo "$update_string" | awk '{match($0, /to [0-9]+(\.[0-9]+)*/, arr); gsub("to ", "", arr[0]); print arr[0]}')
old_major=$(echo "$old_version" | cut -d. -f1)
new_major=$(echo "$new_version" | cut -d. -f1)
isMajorUpdate=false
if [ "$old_major" != "$new_major" ]; then
isMajorUpdate=true
fi
isTeamMember=${{ env.IS_TEAM_MEMBER }}
isDependabot=${{ env.IS_DEPENDABOT }}
notifyAboutMajorDependabotUpdates=${{ env.NOTIFY_ABOUT_MAJOR_DEPENDABOT_UPDATES }}
if [[ $notifyAboutMajorDependabotUpdates == "true" && $isDependabot == "true" ]]; then
if [[ $isMajorUpdate == "true" ]]; then
echo "Major dependabot update"
echo "result=true" >> $GITHUB_OUTPUT
else
echo "Non-major dependabot update"
echo "result=false" >> $GITHUB_OUTPUT
fi
exit
fi
if [[ $isTeamMember == "false" ]]; then
echo "result=true" >> $GITHUB_OUTPUT
fi
echo "result=false" >> $GITHUB_OUTPUT
# Create JIRA issue
- name: Add label - JIRA issue created - for non-Draft PR
if: ${{ fromJson(steps.is-pr-eligible.outputs.result) == true }}
if: ${{ steps.is-pr-eligible.outputs.result == true }}
uses: andymckay/labeler@1.0.4
with:
add-labels: "contribution"

- name: Notify JIRA
if: ${{ fromJson(steps.is-pr-eligible.outputs.result) == true && fromJson(steps.jira-issue-can-be-created.outputs.result) == true }}
- name: Add label for dependabot pull requests
if: ${{ steps.is-pr-eligible.outputs.result == true && steps.is-dependabot.outputs.result == true }}
uses: andymckay/labeler@1.0.4
with:
add-labels: ${{ inputs.dependabot-ticket-jira-label }}

- name: Create JIRA ticket
if: ${{ steps.jira-issue-can-be-created.outputs.result == true }}
shell: bash
env:
JIRA_HOOK: ${{ inputs.jira-hook }}
Expand All @@ -73,7 +141,7 @@ runs:
run: bash ${{ github.action_path }}/notify-jira.sh

- name: Greet author
if: ${{ fromJson(steps.is-pr-eligible.outputs.result) == true && fromJson(steps.jira-issue-can-be-created.outputs.result) == true }}
if: ${{ steps.jira-issue-can-be-created.outputs.result == true && steps.is-dependabot.outputs.result == false }}
uses: actions/github-script@v6
with:
github-token: ${{ inputs.github-token }}
Expand Down

0 comments on commit 9a2ad2f

Please sign in to comment.