1313
1414import json
1515import os
16+ import re
1617import sys
1718
1819# Add the scripts directory to Python path so we can import guideline_utils
2829)
2930
3031
32+ def extract_guideline_id (rst_content : str ) -> str :
33+ """
34+ Extract the guideline ID from RST content.
35+
36+ Args:
37+ rst_content: The generated RST content
38+
39+ Returns:
40+ The guideline ID (e.g., "gui_abc123XYZ") or empty string if not found
41+ """
42+ match = re .search (r':id:\s*(gui_[a-zA-Z0-9]+)' , rst_content )
43+ return match .group (1 ) if match else ""
44+
45+
3146def generate_comment (rst_content : str , chapter : str ) -> str :
3247 """
3348 Generate a formatted GitHub comment with instructions and RST content.
@@ -40,17 +55,39 @@ def generate_comment(rst_content: str, chapter: str) -> str:
4055 Formatted Markdown comment string
4156 """
4257 chapter_slug = chapter_to_filename (chapter )
43- target_file = f"src/coding-guidelines/{ chapter_slug } .rst"
58+ guideline_id = extract_guideline_id (rst_content )
59+
60+ # Determine target path based on whether we have a guideline ID
61+ if guideline_id :
62+ target_dir = f"src/coding-guidelines/{ chapter_slug } /"
63+ target_file = f"{ target_dir } { guideline_id } .rst.inc"
64+ file_instructions = f"""
65+ ### 📁 Target Location
66+
67+ Create a new file: `{ target_file } `
68+
69+ > **Note:** The `.rst.inc` extension prevents Sphinx from auto-discovering the file.
70+ > It will be included via the chapter's `index.rst`."""
71+ else :
72+ # Fallback for legacy structure (shouldn't happen with new template)
73+ target_file = f"src/coding-guidelines/{ chapter_slug } .rst"
74+ file_instructions = f"""
75+ ### 📁 Target File
76+
77+ Add this guideline to: `{ target_file } `"""
4478
4579 comment = f"""## 📋 RST Preview for Coding Guideline
4680
4781This is an automatically generated preview of your coding guideline in reStructuredText format.
82+ { file_instructions }
4883
49- ### 📁 Target File
84+ ### 📝 How to Use This
5085
51- Add this guideline to: ` { target_file } `
86+ **Option A: Automatic (Recommended)**
5287
53- ### 📝 How to Use This
88+ Once this issue is approved, a maintainer will add the `sign-off: create pr from issue` label, which automatically creates a PR with the guideline file.
89+
90+ **Option B: Manual**
5491
55921. **Fork the repository** (if you haven't already) and clone it locally
56932. **Create a new branch** from `main`:
@@ -59,19 +96,27 @@ def generate_comment(rst_content: str, chapter: str) -> str:
5996 git pull origin main
6097 git checkout -b guideline/your-descriptive-branch-name
6198 ```
62- 3. **Open the target file** `{ target_file } ` in your editor
63- 4. **Copy the RST content** below and paste it at the end of the file (before any final directives if present)
64- 5. **Build locally** to verify the guideline renders correctly:
99+ 3. **Create the guideline file**:
100+ ```bash
101+ mkdir -p src/coding-guidelines/{ chapter_slug }
102+ ```
103+ 4. **Copy the RST content** below into a new file named `{ guideline_id } .rst.inc`
104+ 5. **Update the chapter index** - Add an include directive to `src/coding-guidelines/{ chapter_slug } /index.rst`:
105+ ```rst
106+ .. include:: { guideline_id } .rst.inc
107+ ```
108+ Keep the includes in alphabetical order by guideline ID.
109+ 6. **Build locally** to verify the guideline renders correctly:
65110 ```bash
66111 ./make.py
67112 ```
68- 6 . **Commit and push** your changes:
113+ 7 . **Commit and push** your changes:
69114 ```bash
70- git add { target_file }
115+ git add src/coding-guidelines/ { chapter_slug } /
71116 git commit -m "Add guideline: <your guideline title>"
72117 git push origin guideline/your-descriptive-branch-name
73118 ```
74- 7 . **Open a Pull Request** against `main`
119+ 8 . **Open a Pull Request** against `main`
75120
76121<details>
77122<summary><strong>📄 Click to expand RST content</strong></summary>
0 commit comments