-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add action workflow for community issues (#2434)
- Loading branch information
1 parent
733b112
commit b5d8fe8
Showing
2 changed files
with
65 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,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 }} |
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,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()) |