summaryrefslogtreecommitdiff
path: root/.github/workflows
diff options
context:
space:
mode:
author5an7y <[email protected]>2025-06-27 14:09:41 -0700
committer5an7y <[email protected]>2025-06-27 14:09:41 -0700
commitb83d9d2893455ef2ef88261852da145c4440e3d1 (patch)
tree3ee9e5735924462ac1fbcab50a2f10d348ef8dde /.github/workflows
parentb279aaadb2bf18c16c7f59fee896e0c5f5a8db77 (diff)
Action to auto tag the codeowner.
Diffstat (limited to '.github/workflows')
-rw-r--r--.github/workflows/tag-codeowner-on-issue.yml80
1 files changed, 80 insertions, 0 deletions
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