44
55## 1. Context & Pre-Flight
661 . ** Detect Target Repo:**
7- * Run: ` git remote get-url upstream ` (Priority) OR ` git remote get-url origin ` .
8- * Extract: ` OWNER ` and ` REPO_NAME ` .
9- * Construct ID: ` REPO_ID="$OWNER/$REPO_NAME" ` .
10- 2 . ** User Identity:** Use ` @me ` (CLI magic var).
11- 3 . ** Label Strategy:** Match ` refactor ` , ` enhancement ` , ` bug ` , ` documentation ` . Default: ` enhancement ` .
7+ * Run: ` REPO_ID=$(gh repo view --json nameWithOwner -q .nameWithOwner || git remote get-url upstream | sed 's/.*github.com[\/:]\(.*\).git/\1/') `
8+ * * Fallback:* If ` upstream ` fails, use ` origin ` .
9+ 2 . ** User Identity:**
10+ * Use: ` @me ` (Native ` gh ` CLI support).
11+ 3 . ** Label Strategy:**
12+ * Map column keywords to labels: ` refactor ` , ` enhancement ` , ` bug ` , ` documentation ` .
13+ * Default Label: ` enhancement ` .
1214
1315## 2. Input Parsing
1416Parse the Markdown table strictly: ` | Cohort Name | Summary | `
15- * ** Row Handling:** Each row = 1 Issue.
16- * ** Title:** Col 1.
17- * ** Body:** Col 2 + File list.
17+ * ** Row Handling:** Iterate through rows. Map data to variables: ` ISSUE_TITLE ` , ` ISSUE_BODY ` , ` ISSUE_LABELS ` .
18+ * ** Content Generation:**
19+ * ` ISSUE_TITLE ` = Column 1.
20+ * ` ISSUE_BODY ` = Column 2 + template below.
1821
1922## 3. Execution Loop (Fail-Safe CLI)
20- * Action: Create a secure temporary file to store results.*
23+ * Action: Create secure temporary files to store results using standard shell commands .*
2124
2225``` bash
23- LOG_FILE=$( mktemp)
26+ # Create clean temp files for logging
27+ LOG_FILE=$( mktemp) # For PR Body (Markdown links)
28+ FIXES_FILE=$( mktemp) # For Commit Footer (Fixes: URL)
2429```
2530
26- ### Strategy A : GitHub CLI (Targeting Org/Repo Explicitly)
27- For each row in the table, execute :
31+ ### Strategy: GitHub CLI Loop
32+ For each row parsed, execute the following sequence in your shell :
2833
2934``` bash
30- # 1. Create issue on the specific ORG/REPO
31- url=$( gh issue create --repo " $REPO_ID " --title " TITLE" --body " BODY" --label " LABEL" --assignee " @me" )
35+ # 1. Define Variables (Agent populates these per row)
36+ CURRENT_TITLE=" [Parsed Title]"
37+ CURRENT_BODY=" [Parsed Body]"
38+ CURRENT_LABEL=" [Parsed Label]"
3239
33- # 2. Parse the Issue Number
34- num=${url##*/ }
40+ # 2. Create issue using GH CLI
41+ # --assignee "@me" assigns it to the authenticated user
42+ # Capture the URL output
43+ ISSUE_URL=$( gh issue create --repo " $REPO_ID " --title " $CURRENT_TITLE " --body " $CURRENT_BODY " --label " $CURRENT_LABEL " --assignee " @me" )
3544
36- # 3. Log format: - [#12](link): Description
37- echo " - [# $num ]( $url ): TITLE " >> " $LOG_FILE "
45+ # 3. Parse the Issue Number from the URL
46+ ISSUE_NUM= " ${ISSUE_URL ##*/ } "
3847
39- # 4. Safety Brake: Prevent API Rate Limiting
48+ # 4. Log for PR Description: - [#12](link): Description
49+ echo " - [#$ISSUE_NUM ]($ISSUE_URL ): $CURRENT_TITLE " >> " $LOG_FILE "
50+
51+ # 5. Log for Commit Footer: Fixes: URL
52+ echo " Fixes: $ISSUE_URL " >> " $FIXES_FILE "
53+
54+ # 6. Safety Brake: Prevent API Rate Limiting
4055sleep 1
4156```
4257
43- ### Strategy B: GitHub MCP (Fallback)
44- Call ` github_create_issue ` manually if CLI fails.
45-
4658## 4. Issue Content Template
59+ Appended to ` ISSUE_BODY ` variable before creation:
60+
4761``` markdown
4862### Change Summary
49- [ Summary Text]
63+ [ Column 2 Text]
5064
5165### Files Affected
52- [ List of files ]
66+ $(git diff --name-only --cached)
5367
5468### Verification
5569- [ ] Verify functionality locally
@@ -58,48 +72,58 @@ Call `github_create_issue` manually if CLI fails.
5872## 5. Post-Processing & Output
5973
6074### Phase A: PR Enrichment (Idempotent Update)
61- ** Condition:** Check ` git branch --show-current ` . If PR exists:
75+ ** Condition:** Check if a PR exists for the current branch.
6276
6377``` bash
64- # 1. Get current body
65- current_body=$( gh pr view --repo " $REPO_ID " --json body -q .body)
66- new_links=$( cat " $LOG_FILE " )
67-
68- # 2. Smart Append Logic
69- # Checks if the "Connected Issues" section already exists to avoid duplicate headers
70- if echo " $current_body " | grep -q " ### 🔗 Connected Issues" ; then
71- # Just append links
72- final_body=" $current_body
73- $new_links "
74- else
75- # Create Header + Links
76- final_body=" $current_body
78+ # 1. Check for existing PR on current branch
79+ PR_NUMBER=$( gh pr view --json number -q .number 2> /dev/null)
80+
81+ if [ -n " $PR_NUMBER " ]; then
82+ # 2. Get current body
83+ CURRENT_PR_BODY=$( gh pr view " $PR_NUMBER " --json body -q .body)
84+ NEW_LINKS=$( cat " $LOG_FILE " )
85+
86+ # 3. Smart Append Logic
87+ if echo " $CURRENT_PR_BODY " | grep -q " ### 🔗 Connected Issues" ; then
88+ FINAL_BODY=" $CURRENT_PR_BODY
89+ $NEW_LINKS "
90+ else
91+ FINAL_BODY=" $CURRENT_PR_BODY
7792
7893### 🔗 Connected Issues
79- $new_links "
80- fi
94+ $NEW_LINKS "
95+ fi
8196
82- # 3. Update PR
83- gh pr edit --repo " $REPO_ID " --body " $final_body "
97+ # 4. Update PR
98+ gh pr edit " $PR_NUMBER " --body " $FINAL_BODY "
99+ PR_UPDATED=" Yes"
100+ else
101+ PR_UPDATED=" No (No active PR found)"
102+ fi
84103```
85104
86- ### Phase B: Cleanup & Display (Mandatory)
87- Always run this, regardless of PR status .
105+ ### Phase B: Cleanup & Display
106+ Always run this to finalize the output .
88107
89108``` bash
90109# Read content for final summary display
91- summary_content=$( cat " $LOG_FILE " )
110+ SUMMARY_CONTENT=$( cat " $LOG_FILE " )
111+ FIXES_CONTENT=$( cat " $FIXES_FILE " )
92112
93- # Remove the temp file to keep filesystem clean
94- rm " $LOG_FILE "
113+ # Remove the temp files
114+ rm " $LOG_FILE " " $FIXES_FILE "
95115```
96116
97117### Phase C: Final Output Block
98118> ## 🚀 Issues Created
99- > ** Target Repo:** ` OWNER/REPO `
119+ > ** Target Repo:** ` $REPO_ID `
100120>
101121> ### Summary
102- > (Display the content of ` $summary_content ` )
122+ > ` $SUMMARY_CONTENT `
123+ >
124+ > * PR Description updated automatically?* ` $PR_UPDATED `
103125>
104- > * PR Description updated automatically?* (Yes/No)
105- ```
126+ > ### 📋 Commit Footer / Fixes
127+ > ``` text
128+ > $FIXES_CONTENT
129+ > ```
0 commit comments