-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from kdvalin/ci/issue-labelling
Add Issue Labelling based on PR state
- Loading branch information
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,59 @@ | ||
name: Update parent issue | ||
|
||
permissions: | ||
issues: write | ||
|
||
env: | ||
ISSUE_STATE: pr_inprogress | ||
REMOVE_ISSUES: --remove-label pr_approved --remove-label pr_review --remove-label pr_inprogress | ||
GH_TOKEN: ${{ github.token }} | ||
|
||
on: | ||
issue_comment: | ||
pull_request_target: | ||
types: | ||
- review_requested | ||
pull_request_review: | ||
types: | ||
- submitted | ||
jobs: | ||
update_parent_issue: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Get PR number on issue type | ||
if: github.event_name == 'pull_request_review' | ||
run: echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> "$GITHUB_ENV" | ||
|
||
- name: Get PR number on PR event | ||
if: github.event_name == 'pull_request_target' | ||
run: echo "PR_NUMBER=${{ github.event.number }}" >> "$GITHUB_ENV" | ||
|
||
- name: Get parent issues | ||
shell: bash | ||
run: > | ||
echo PARENT_ISSUES=$( | ||
./ci/get_parent_issue.sh | ||
$PR_NUMBER | ||
) >> $GITHUB_ENV | ||
- name: Fail when unable to find a parent issue | ||
if: env.PARENT_ISSUE == '' | ||
run: echo "Could not find a parent issue" && exit 1 | ||
|
||
- name: Get PR states | ||
run: > | ||
echo PR_STATUS=pr_$( | ||
gh pr view $PR_NUMBER --json reviewRequests,latestReviews | | ||
python ./ci/determine_status.py | ||
) >> $GITHUB_ENV | ||
- name: Set parent issues state | ||
run: > | ||
for issue in $PARENT_ISSUES; do | ||
echo "Updating $issue to $PR_STATUS" && | ||
gh issue edit $issue $REMOVE_ISSUES && | ||
gh issue edit $issue --add-label=$PR_STATUS | ||
done | ||
This file contains 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,8 @@ | ||
# Workflows in this repository | ||
|
||
## Update parent issue | ||
The idea behind this workflow is to keep Jira tickets in sync with the current status of their GitHub issue. A flowchart for how this works can be seen below. | ||
|
||
 | ||
|
||
This workflow does not work with forked repositories, since the `GITHUB_TOKEN` provided by GitHub runner will not have write access to the base repository unless the pull request originated from the base repository. |
This file contains 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,26 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
|
||
def _main(file): | ||
data = json.load(file) | ||
|
||
for review in data['latestReviews']: | ||
if review['state'] == "CHANGES_REQUESTED": | ||
return "inprogress" | ||
|
||
if len(data['reviewRequests']) > 0: | ||
return "review" | ||
|
||
if len(data['latestReviews']) > 0: | ||
return "approved" | ||
|
||
return "inprogress" #No PR Requests and no reviews | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
in_file = sys.stdin | ||
if len(sys.argv) > 1: | ||
in_file = open(sys.argv[1], 'r') | ||
print(_main(in_file)) | ||
in_file.close() |
This file contains 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,9 @@ | ||
#!/bin/bash | ||
|
||
mentioned_issues=$(gh pr view "$1" --json body | jq -r .body | grep -Eo '#[0-9]+' | sed -e 's/#//g') | ||
|
||
for issue in $mentioned_issues; do | ||
if gh issue view "$issue" --json id > /dev/null; then | ||
echo -n "$issue " | ||
fi | ||
done |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.