Skip to content

Commit

Permalink
Add action workflow for community issues (#2434)
Browse files Browse the repository at this point in the history
  • Loading branch information
navarone-feekery authored Apr 24, 2024
1 parent 733b112 commit b5d8fe8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/label-community-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Label Community Issues

on:
issues:
types: [opened]

jobs:
run-python-script:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: python3 -m pip install aiohttp gidgethub

- name: Run Python script
run: python .github/workflows/scripts/label_community_issues.py
env:
ACTOR: ${{ github.actor }}
NUMBER: ${{ github.event.issue.number }}
REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 changes: 36 additions & 0 deletions .github/workflows/scripts/label_community_issues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python

import aiohttp
import asyncio
import os
from gidgethub.aiohttp import GitHubAPI
from gidgethub import BadRequest

ACTOR = os.getenv("ACTOR")
NUMBER = os.getenv("NUMBER")
REPO = os.getenv("REPO")
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")

LABELS = ["community-driven", "needs-triage"]

async def main():
async with aiohttp.ClientSession() as session:
gh = GitHubAPI(session, requester="", base_url="https://api.github.com", oauth_token=GITHUB_TOKEN)

print("********")
print(f"ACTOR: {ACTOR}")
print(f"NUMBER: {NUMBER}")
print(f"REPO: {REPO}")
print("********")

try:
# this API returns a None response, but will raise if the user isn't a collaborator
await gh.getitem(f"/repos/{REPO}/collaborators/{ACTOR}")
print("User is a collaborator, not applying labels.")
except BadRequest as e:
# if this fails we want it to be noisy, so no try/except
print("User is not a collaborator, applying labels...")
await gh.post(f"/repos/{REPO}/issues/{NUMBER}/labels", data={"labels": LABELS})

if __name__ == "__main__":
asyncio.run(main())

0 comments on commit b5d8fe8

Please sign in to comment.