Skip to content

Commit b45d3d6

Browse files
Merge pull request #1319 from 5an7y/main
PR to test changes from original branch. No harm done since this is done to my users branch
2 parents 4f30b7f + a0d6b25 commit b45d3d6

File tree

5 files changed

+265
-0
lines changed

5 files changed

+265
-0
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# Windows Implementation Library submodule
1111
/wil/ @microsoft/driver-samples-maintainers
1212

13+
# Samples
14+
1315
# Audio
1416
/audio/ @microsoft/windowsaudio
1517

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Issue with a sample
2+
description: Report a problem you have with a specific sample.
3+
title: '[path/to/sample]: '
4+
body:
5+
- type: dropdown
6+
id: sample_area
7+
attributes:
8+
label: Which is the area where the sample lives?
9+
description: Select the area where you're experiencing the problem.
10+
options:
11+
- /TrEE/
12+
- /audio/
13+
- /avstream/
14+
- /bluetooth/
15+
- /filesys/cdfs/
16+
- /filesys/fastfat/
17+
- /filesys/miniFilter/
18+
- /general/DCHU/
19+
- /general/PLX9x5x/
20+
- /general/SimpleMediaSource/
21+
- /general/SystemDma/
22+
- /general/cancel/
23+
- /general/echo/
24+
- /general/event/
25+
- /general/ioctl/
26+
- /general/pcidrv/
27+
- /general/perfcounters/
28+
- /general/registry/
29+
- /general/toaster/
30+
- /general/tracing/
31+
- /gnss/
32+
- /gpio/
33+
- /hid/
34+
- /input/
35+
- /network/config/
36+
- /network/modem/
37+
- /network/ndis/
38+
- /network/radio/
39+
- /network/trans/
40+
- /network/wlan/
41+
- /network/wsk/
42+
- /network/wwan/
43+
- /nfc/
44+
- /pofx/PEP/
45+
- /pofx/UMDF2/
46+
- /pofx/WDF/
47+
- /pos/
48+
- /powerlimit/
49+
- /print/
50+
- /prm/
51+
- /sd/
52+
- /security/
53+
- /sensors/
54+
- /serial/
55+
- /setup/
56+
- /simbatt/
57+
- /smartcrd/
58+
- /spb/
59+
- /storage/
60+
- /thermal/
61+
- /tools/
62+
- /usb/
63+
- /video/
64+
- /wia/
65+
- /wmi/wmiacpi/
66+
- /wmi/wmisamp/
67+
validations:
68+
required: true
69+
- type: textarea
70+
id: description
71+
attributes:
72+
label: Describe the issue
73+
description: Provide a clear and concise description of what the issue is.
74+
validations:
75+
required: true
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import yaml
2+
import os
3+
4+
# Read the CODEOWNERS file
5+
codeowners_path = os.path.join(os.path.dirname(__file__), "..", "CODEOWNERS")
6+
with open(codeowners_path, "r") as file:
7+
lines = file.readlines()
8+
9+
# Parse the CODEOWNERS file to extract areas and their paths
10+
areas = []
11+
sample_section_found = False
12+
13+
for line in lines:
14+
line = line.strip()
15+
if line.startswith("# Samples"):
16+
sample_section_found = True
17+
continue
18+
19+
if sample_section_found:
20+
if line.startswith("#"):
21+
continue
22+
elif line:
23+
path, codeowner = line.split()
24+
if path in areas:
25+
raise ValueError(f"Path:{path} has been found two times inside CODEOWNERS file")
26+
areas.append(path)
27+
28+
29+
# Sort the areas in lexicographical order
30+
areas = sorted(areas)
31+
32+
# Generate the YAML structure
33+
yaml_form = {
34+
"name": "Issue with a sample",
35+
"description": "Report a problem you have with a specific sample.",
36+
"title": "[path/to/sample]: ",
37+
"body": []
38+
}
39+
40+
dropdown = {
41+
"type": "dropdown",
42+
"id": "sample_area",
43+
"attributes": {
44+
"label": "Which is the area where the sample lives?",
45+
"description": "Select the area where you're experiencing the problem.",
46+
"options": areas
47+
},
48+
"validations": {
49+
"required": True
50+
}
51+
}
52+
53+
# Add a description field
54+
description_field = {
55+
"type": "textarea",
56+
"id": "description",
57+
"attributes": {
58+
"label": "Describe the issue",
59+
"description": "Provide a clear and concise description of what the issue is."
60+
},
61+
"validations": {
62+
"required": True
63+
}
64+
}
65+
66+
yaml_form["body"].append(dropdown)
67+
yaml_form["body"].append(description_field)
68+
69+
# Write the YAML to a file
70+
output_path = os.path.join(os.path.dirname(__file__), "sample_issue.yml")
71+
with open(output_path, "w") as outfile:
72+
yaml.dump(yaml_form, outfile, sort_keys=False)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Generate Sample Issue Template
2+
3+
on:
4+
push:
5+
paths:
6+
- '.github/CODEOWNERS'
7+
pull_request:
8+
paths:
9+
- '.github/CODEOWNERS'
10+
11+
12+
jobs:
13+
generate-template:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.x'
24+
25+
- name: Install dependencies
26+
run: pip install pyyaml
27+
28+
- name: Run the generator script
29+
run: python .github/ISSUE_TEMPLATE/sample_issue_generator.py
30+
31+
- name: Commit and push changes
32+
run: |
33+
git config user.name "github-actions[bot]"
34+
git config user.email "github-actions[bot]@users.noreply.github.com"
35+
git add .github/ISSUE_TEMPLATE/sample_issue.yml
36+
git commit -m "Auto-generate sample issue template from CODEOWNERS" || echo "No changes to commit"
37+
git push origin HEAD:${{ github.head_ref }}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Tag Codeowner on Sample Issue
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
jobs:
8+
tag-codeowner:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.x'
19+
20+
- name: Install dependencies
21+
run: pip install pyyaml requests
22+
23+
- name: Extract selected path and tag codeowner
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
run: |
27+
python3 - <<EOF
28+
import os
29+
import re
30+
import requests
31+
32+
issue_body = """${{ github.event.issue.body }}"""
33+
selected_path = None
34+
35+
# Try to extract the selected path from the issue body
36+
match = re.search(r'### Which is the area where the sample lives\?\s*\n(.+)', issue_body, re.MULTILINE)
37+
if match:
38+
selected_path = match.group(1).strip()
39+
40+
if not selected_path:
41+
print("No sample path found in issue body.")
42+
exit(0)
43+
44+
# Read CODEOWNERS
45+
with open(".github/CODEOWNERS", "r") as f:
46+
lines = f.readlines()
47+
48+
codeowner = None
49+
sample_section = False
50+
for line in lines:
51+
line = line.strip()
52+
if line.startswith("# Samples"):
53+
sample_section = True
54+
continue
55+
if sample_section:
56+
if line.startswith("#") or not line:
57+
continue
58+
path, owner = line.split()
59+
if path == selected_path:
60+
codeowner = owner
61+
break
62+
63+
if codeowner is None:
64+
print(f"No codeowner found for path: {selected_path}")
65+
exit(0)
66+
67+
# Post a comment tagging the owner
68+
comment = f"{codeowner} can you please take a look at this issue related to {selected_path}?"
69+
repo = os.environ['GITHUB_REPOSITORY']
70+
token = os.environ['GITHUB_TOKEN']
71+
72+
url = f"https://api.github.com/repos/{repo}/issues/${{ github.event.issue.number }}/comments"
73+
headers = {
74+
"Authorization": f"Bearer {token}",
75+
"Accept": "application/vnd.github.v3+json"
76+
}
77+
response = requests.post(url, headers=headers, json={"body": comment})
78+
print("Comment posted:", response.status_code, response.text)
79+
EOF

0 commit comments

Comments
 (0)