Verify readmegen-ai.vercel.app in Google Search Console via HTML file #4
This file contains hidden or 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
| name: Issue Label Bot | |
| on: | |
| issues: | |
| types: [opened, edited] | |
| permissions: | |
| issues: write | |
| contents: read | |
| jobs: | |
| label: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Apply labels based on keywords | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GH_PAT }} | |
| ISSUE_NUMBER: ${{ github.event.issue.number }} | |
| ISSUE_TITLE: ${{ github.event.issue.title }} | |
| ISSUE_BODY: ${{ github.event.issue.body }} | |
| GH_REPOSITORY: ${{ github.repository }} | |
| run: | | |
| python3 << 'EOF' | |
| import os, sys, yaml, json | |
| from urllib.request import Request, urlopen | |
| from urllib.error import HTTPError | |
| token = os.environ['GITHUB_TOKEN'] | |
| issue_number = os.environ['ISSUE_NUMBER'] | |
| repo = os.environ['GH_REPOSITORY'] | |
| title = (os.environ.get('ISSUE_TITLE') or '').lower() | |
| body = (os.environ.get('ISSUE_BODY') or '').lower() | |
| text = title + ' ' + body | |
| config_path = '.github/issue_label_bot.yaml' | |
| try: | |
| with open(config_path) as f: | |
| config = yaml.safe_load(f) | |
| except FileNotFoundError: | |
| print(f'Error: config file not found at {config_path}', file=sys.stderr) | |
| sys.exit(1) | |
| except yaml.YAMLError as e: | |
| print(f'Error: failed to parse {config_path}: {e}', file=sys.stderr) | |
| sys.exit(1) | |
| labels_to_add = [] | |
| for matcher in config['matchers']: | |
| if any(kw.lower() in text for kw in matcher['keywords']): | |
| labels_to_add.append(matcher['label']) | |
| if labels_to_add: | |
| url = f'https://api.github.com/repos/{repo}/issues/{issue_number}/labels' | |
| data = json.dumps({'labels': labels_to_add}).encode() | |
| req = Request(url, data=data, headers={ | |
| 'Authorization': f'Bearer {token}', | |
| 'Content-Type': 'application/json', | |
| 'Accept': 'application/vnd.github+json', | |
| 'X-GitHub-Api-Version': '2022-11-28' | |
| }) | |
| try: | |
| with urlopen(req) as resp: | |
| print(f'Added labels: {labels_to_add}') | |
| except HTTPError as e: | |
| print(f'Error: GitHub API returned {e.code}: {e.read().decode()}', file=sys.stderr) | |
| sys.exit(1) | |
| else: | |
| print('No matching labels found.') | |
| EOF |