Skip to content

Commit

Permalink
ci: Automatically add "contribution" label
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Jul 25, 2024
1 parent 7d32da5 commit e2a3438
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/pr_opened.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,38 @@ jobs:
check-ready:
runs-on: ubuntu-latest
steps:
- uses: andymckay/[email protected]
- name: Add label
uses: andymckay/[email protected]
if: github.event.pull_request.draft == true
with:
add-labels: 'work in progress'

- uses: andymckay/[email protected]
- name: Add label
uses: andymckay/[email protected]
if: tojson(github.event.pull_request.requested_reviewers) != '[]'
with:
add-labels: 'ready for review'

check-contrib:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check contrib
id: contrib
run: |
echo flag=$(scripts/rgh.py show_pr ${{ github.event.pull_request.number }} --json \
| jq -r .pull_request.contrib) >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.github_token }}

- name: Add label
if: steps.contrib.outputs.flag == 'true'
uses: andymckay/[email protected]
with:
add-labels: 'contribution'

check-issue:
runs-on: ubuntu-latest
steps:
Expand Down
11 changes: 11 additions & 0 deletions scripts/rgh.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def query_pr_info(org, repo, pr_number, no_git=False):
'pr_link': (org, repo, pr_number),
'pr_title': response['title'],
'pr_url': response['html_url'],
'pr_author': response['user']['login'],
'pr_state': response['state'],
'pr_draft': response['draft'],
'pr_mergeable': response['mergeable'],
Expand Down Expand Up @@ -247,6 +248,14 @@ def query_pr_info(org, repo, pr_number, no_git=False):
issue_info = query_issue_info(*pr_info['issue_link'])
pr_info.update(issue_info)

try:
subprocess.run(
['gh', 'api', f'/orgs/{org}/members/'+pr_info['pr_author']],
capture_output=True, text=True, check=True)
pr_info['pr_contrib'] = False
except subprocess.CalledProcessError as e:
pr_info['pr_contrib'] = True

if not no_git:
try:
# commit in upstream from which pr branch was forked
Expand Down Expand Up @@ -360,6 +369,7 @@ def add_commit(sha, msg, author, email):
start_section('pull request')
add_field('title', pr_info['pr_title'], Fore.BLUE)
add_field('url', pr_info['pr_url'])
add_field('author', pr_info['pr_author'])
add_field('milestone', str(pr_info['pr_milestone']).lower(),
Fore.MAGENTA if pr_info['pr_milestone'] is not None else Fore.RED)
add_field('source', pr_info['source_branch'], Fore.CYAN)
Expand All @@ -368,6 +378,7 @@ def add_commit(sha, msg, author, email):
Fore.MAGENTA if pr_info['pr_state'] == 'open' else Fore.RED)
add_field('draft', str(pr_info['pr_draft']).lower(),
Fore.MAGENTA if not pr_info['pr_draft'] else Fore.RED)
add_field('contrib', str(pr_info['pr_contrib']).lower(), Fore.CYAN)
add_field('mergeable', str(pr_info['pr_mergeable'] \
if pr_info['pr_mergeable'] is not None else 'unknown').lower(),
Fore.MAGENTA if pr_info['pr_mergeable'] == True else Fore.RED)
Expand Down

0 comments on commit e2a3438

Please sign in to comment.