diff options
| author | Jose Santiago Vales Mena <[email protected]> | 2025-06-27 14:12:54 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-27 14:12:54 -0700 |
| commit | 9e1ed2c25a2a11b07142c45f67d587edcd921a04 (patch) | |
| tree | e3e5de4b25a493bebcfe1394cea47b0abd828f22 /.github/workflows | |
| parent | 841bf5e979f76d2f8fdaf41e273a5d775a3ea9e8 (diff) | |
| parent | 737e9212529aa48662d8675a1b1bf24a75dc9f9e (diff) | |
Merge pull request #2 from 5an7y/sample-based-issue-template
Sample based issue template
Diffstat (limited to '.github/workflows')
| -rw-r--r-- | .github/workflows/generate-sample-issue-template.yml | 37 | ||||
| -rw-r--r-- | .github/workflows/tag-codeowner-on-issue.yml | 80 |
2 files changed, 117 insertions, 0 deletions
diff --git a/.github/workflows/generate-sample-issue-template.yml b/.github/workflows/generate-sample-issue-template.yml new file mode 100644 index 00000000..001fe01d --- /dev/null +++ b/.github/workflows/generate-sample-issue-template.yml @@ -0,0 +1,37 @@ +name: Generate Sample Issue Template + +on: + push: + paths: + - '.github/CODEOWNERS' + pull_request: + paths: + - '.github/CODEOWNERS' + + +jobs: + generate-template: + 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.x' + + - name: Install dependencies + run: pip install pyyaml + + - name: Run the generator script + run: python .github/ISSUE_TEMPLATE/sample_issue_generator.py + + - name: Commit and push changes + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add .github/ISSUE_TEMPLATE/sample_issue.yml + git commit -m "Auto-generate sample issue template from CODEOWNERS" || echo "No changes to commit" + git push diff --git a/.github/workflows/tag-codeowner-on-issue.yml b/.github/workflows/tag-codeowner-on-issue.yml new file mode 100644 index 00000000..35789520 --- /dev/null +++ b/.github/workflows/tag-codeowner-on-issue.yml @@ -0,0 +1,80 @@ +name: Tag Codeowner on Sample Issue + +on: + issues: + types: [opened] + +jobs: + tag-codeowner: + 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.x' + + - name: Install dependencies + run: pip install pyyaml + + - name: Extract selected path and tag codeowner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + python3 <<EOF + import os + import re + import requests + import yaml + + issue_body = """${{ github.event.issue.body }}""" + selected_path = None + + # Try to extract the selected path from the issue body + match = re.search(r'### Which is the area where the sample lives\\?\\n(.+)', issue_body) + if match: + selected_path = match.group(1).strip() + + if not selected_path: + print("No sample path found in issue body.") + exit(0) + + # Read CODEOWNERS + with open(".github/CODEOWNERS", "r") as f: + lines = f.readlines() + + codeowners = {} + sample_section = False + for line in lines: + line = line.strip() + if line.startswith("# Samples"): + sample_section = True + continue + if sample_section: + if line.startswith("#") or not line: + continue + path, owner = line.split() + codeowners[path] = owner + + owner = codeowners.get(selected_path) + if not owner: + print(f"No codeowner found for path: {selected_path}") + exit(0) + + # Post a comment tagging the owner + comment = f"{owner} can you please take a look at this issue related to `{selected_path}`?" + issue_number = os.environ['GITHUB_REF'].split('/')[-1] + repo = os.environ['GITHUB_REPOSITORY'] + token = os.environ['GITHUB_TOKEN'] + + url = f"https://api.github.com/repos/{repo}/issues/${{ github.event.issue.number }}/comments" + headers = { + "Authorization": f"Bearer {token}", + "Accept": "application/vnd.github.v3+json" + } + response = requests.post(url, headers=headers, json={"body": comment}) + print("Comment posted:", response.status_code, response.text) + EOF |
