Skip to content

Commit 4c17924

Browse files
authored
refactor(commands): remove hardcoded organization from global commands (#50)
Replace hardcoded 'kcenon' organization with dynamic organization detection. Commands now support: - Auto-detection from git remote origin - Explicit --org flag - Full path format (org/project) This makes /issue-work and /pr-work reusable across different GitHub organizations.
1 parent d88261e commit 4c17924

2 files changed

Lines changed: 86 additions & 29 deletions

File tree

global/commands/issue-work.md

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,51 @@ Automate GitHub issue workflow with project name as argument.
55
## Usage
66

77
```
8-
/issue-work <project-name>
8+
/issue-work <project-name> [--org <organization>]
9+
/issue-work <organization>/<project-name>
910
```
1011

1112
**Example**:
1213
```
13-
/issue-work hospital_erp_system
14-
/issue-work messaging_system
15-
/issue-work thread_system
14+
/issue-work hospital_erp_system # Auto-detect org from git remote
15+
/issue-work hospital_erp_system --org mycompany # Explicit organization
16+
/issue-work mycompany/hospital_erp_system # Full repo path format
1617
```
1718

1819
## Arguments
1920

20-
- `$ARGUMENTS`: Project name (required)
21-
- Repository: `https://github.com/kcenon/$ARGUMENTS`
22-
- Source path: `./$ARGUMENTS`
21+
- `$ARGUMENTS`: Project name or full repository path (required)
22+
- Format 1: `<project-name>` - auto-detect organization from git remote
23+
- Format 2: `<project-name> --org <organization>` - explicit organization
24+
- Format 3: `<organization>/<project-name>` - full repository path
25+
26+
## Organization Detection
27+
28+
Parse `$ARGUMENTS` and determine organization:
29+
30+
```bash
31+
# Check if --org flag is provided
32+
if [[ "$ARGUMENTS" == *"--org"* ]]; then
33+
PROJECT=$(echo "$ARGUMENTS" | awk '{print $1}')
34+
ORG=$(echo "$ARGUMENTS" | sed -n 's/.*--org[[:space:]]*\([^[:space:]]*\).*/\1/p')
35+
# Check if full path format (contains /)
36+
elif [[ "$ARGUMENTS" == *"/"* ]]; then
37+
ORG=$(echo "$ARGUMENTS" | cut -d'/' -f1)
38+
PROJECT=$(echo "$ARGUMENTS" | cut -d'/' -f2)
39+
# Auto-detect from git remote
40+
else
41+
PROJECT="$ARGUMENTS"
42+
cd "$PROJECT" 2>/dev/null || { echo "Error: Project directory not found: $PROJECT"; exit 1; }
43+
ORG=$(git remote get-url origin 2>/dev/null | sed -E 's|.*[:/]([^/]+)/[^/]+\.git$|\1|' | sed -E 's|.*[:/]([^/]+)/[^/]+$|\1|')
44+
if [[ -z "$ORG" ]]; then
45+
echo "Error: Cannot detect organization. Use --org flag or full path format."
46+
exit 1
47+
fi
48+
fi
49+
```
50+
51+
- Repository: `https://github.com/$ORG/$PROJECT`
52+
- Source path: `./$PROJECT`
2353

2454
## Instructions
2555

@@ -28,9 +58,9 @@ Execute the following workflow for the specified project:
2858
### 1. Issue Selection
2959

3060
```bash
31-
gh issue list --repo kcenon/$ARGUMENTS --label "priority/critical" --state open --limit 1
61+
gh issue list --repo $ORG/$PROJECT --label "priority/critical" --state open --limit 1
3262
# If none found:
33-
gh issue list --repo kcenon/$ARGUMENTS --label "priority/high" --state open --limit 1
63+
gh issue list --repo $ORG/$PROJECT --label "priority/high" --state open --limit 1
3464
```
3565

3666
Select the oldest (first created) issue from the results.
@@ -53,7 +83,7 @@ If splitting required:
5383
### 3. Git Environment Setup
5484

5585
```bash
56-
cd $ARGUMENTS
86+
cd $PROJECT
5787
git fetch origin
5888
git checkout main && git pull origin main
5989
git checkout -b <type>/issue-<NUMBER>-<short-description>
@@ -68,7 +98,7 @@ Branch naming convention:
6898
### 4. Issue Assignment
6999

70100
```bash
71-
gh issue edit <NUMBER> --repo kcenon/$ARGUMENTS --add-assignee @me
101+
gh issue edit <NUMBER> --repo $ORG/$PROJECT --add-assignee @me
72102
```
73103

74104
### 5. Code Implementation
@@ -122,7 +152,7 @@ docs(scope): update documentation for <feature>
122152
```bash
123153
git push -u origin <branch-name>
124154

125-
gh pr create --repo kcenon/$ARGUMENTS \
155+
gh pr create --repo $ORG/$PROJECT \
126156
--title "type(scope): description" \
127157
--body "Closes #<ISSUE_NUMBER>
128158
@@ -141,7 +171,7 @@ gh pr create --repo kcenon/$ARGUMENTS \
141171
### 9. Update Original Issue
142172

143173
```bash
144-
gh issue comment <NUMBER> --repo kcenon/$ARGUMENTS \
174+
gh issue comment <NUMBER> --repo $ORG/$PROJECT \
145175
--body "Implementation PR: #<PR_NUMBER>"
146176
```
147177

@@ -164,7 +194,7 @@ After completion, provide summary:
164194

165195
| Item | Value |
166196
|------|-------|
167-
| Project | $ARGUMENTS |
197+
| Repository | $ORG/$PROJECT |
168198
| Issue | #NUMBER - Title |
169199
| Branch | branch-name |
170200
| PR | #PR_NUMBER |
@@ -191,6 +221,7 @@ After completion, provide summary:
191221
| gh CLI installed | "GitHub CLI is not installed" | Install from https://cli.github.com |
192222
| gh authenticated | "Not authenticated with GitHub" | Run `gh auth login` |
193223
| Project directory exists | "Project directory not found: [path]" | Verify project path in configuration |
224+
| Organization detected | "Cannot detect organization" | Use `--org` flag or full path format |
194225

195226
### Runtime Errors
196227

global/commands/pr-work.md

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,60 @@ Analyze and fix failed CI/CD workflows for a pull request.
55
## Usage
66

77
```
8-
/pr-work <project-name> <pr-number>
8+
/pr-work <project-name> <pr-number> [--org <organization>]
9+
/pr-work <organization>/<project-name> <pr-number>
910
```
1011

1112
**Example**:
1213
```
13-
/pr-work hospital_erp_system 42
14-
/pr-work messaging_system 156
15-
/pr-work thread_system 89
14+
/pr-work hospital_erp_system 42 # Auto-detect org from git remote
15+
/pr-work hospital_erp_system 42 --org mycompany # Explicit organization
16+
/pr-work mycompany/hospital_erp_system 42 # Full repo path format
1617
```
1718

1819
## Arguments
1920

20-
`$ARGUMENTS` format: `<project-name> <pr-number>`
21+
`$ARGUMENTS` format: `<project-name> <pr-number> [--org <organization>]` or `<organization>/<project-name> <pr-number>`
2122

22-
- **Project name**: Repository name under `kcenon/`
23+
- **Project name**: Repository name (or full path with organization)
2324
- **PR number**: Pull request number to fix
25+
- **--org**: GitHub organization or user (optional, auto-detected if not provided)
26+
27+
## Organization Detection
28+
29+
Parse `$ARGUMENTS` and determine organization:
2430

25-
Parsing:
2631
```bash
27-
PROJECT=$(echo "$ARGUMENTS" | awk '{print $1}')
28-
PR_NUMBER=$(echo "$ARGUMENTS" | awk '{print $2}')
32+
# Check if --org flag is provided
33+
if [[ "$ARGUMENTS" == *"--org"* ]]; then
34+
PROJECT=$(echo "$ARGUMENTS" | awk '{print $1}')
35+
PR_NUMBER=$(echo "$ARGUMENTS" | awk '{print $2}')
36+
ORG=$(echo "$ARGUMENTS" | sed -n 's/.*--org[[:space:]]*\([^[:space:]]*\).*/\1/p')
37+
# Check if first argument contains / (full path format)
38+
elif [[ "$(echo "$ARGUMENTS" | awk '{print $1}')" == *"/"* ]]; then
39+
REPO_PATH=$(echo "$ARGUMENTS" | awk '{print $1}')
40+
ORG=$(echo "$REPO_PATH" | cut -d'/' -f1)
41+
PROJECT=$(echo "$REPO_PATH" | cut -d'/' -f2)
42+
PR_NUMBER=$(echo "$ARGUMENTS" | awk '{print $2}')
43+
# Auto-detect from git remote
44+
else
45+
PROJECT=$(echo "$ARGUMENTS" | awk '{print $1}')
46+
PR_NUMBER=$(echo "$ARGUMENTS" | awk '{print $2}')
47+
cd "$PROJECT" 2>/dev/null || { echo "Error: Project directory not found: $PROJECT"; exit 1; }
48+
ORG=$(git remote get-url origin 2>/dev/null | sed -E 's|.*[:/]([^/]+)/[^/]+\.git$|\1|' | sed -E 's|.*[:/]([^/]+)/[^/]+$|\1|')
49+
if [[ -z "$ORG" ]]; then
50+
echo "Error: Cannot detect organization. Use --org flag or full path format."
51+
exit 1
52+
fi
53+
fi
2954
```
3055

3156
## Instructions
3257

3358
### 1. PR Information Retrieval
3459

3560
```bash
36-
gh pr view $PR_NUMBER --repo kcenon/$PROJECT --json title,state,headRefName,checks
61+
gh pr view $PR_NUMBER --repo $ORG/$PROJECT --json title,state,headRefName,checks
3762
```
3863

3964
Identify:
@@ -45,10 +70,10 @@ Identify:
4570

4671
```bash
4772
# List failed workflow runs for the PR
48-
gh run list --repo kcenon/$PROJECT --branch <head-branch> --status failure --limit 5
73+
gh run list --repo $ORG/$PROJECT --branch <head-branch> --status failure --limit 5
4974

5075
# Get detailed log for failed run
51-
gh run view <RUN_ID> --repo kcenon/$PROJECT --log-failed
76+
gh run view <RUN_ID> --repo $ORG/$PROJECT --log-failed
5277
```
5378

5479
For each failed workflow:
@@ -121,10 +146,10 @@ git push origin <head-branch>
121146
After push:
122147
```bash
123148
# Monitor workflow status
124-
gh run list --repo kcenon/$PROJECT --branch <head-branch> --limit 3
149+
gh run list --repo $ORG/$PROJECT --branch <head-branch> --limit 3
125150

126151
# Wait for completion and check result
127-
gh run watch <RUN_ID> --repo kcenon/$PROJECT
152+
gh run watch <RUN_ID> --repo $ORG/$PROJECT
128153
```
129154

130155
### 8. Iterate if Needed
@@ -152,7 +177,7 @@ After completion, provide summary:
152177

153178
| Item | Value |
154179
|------|-------|
155-
| Project | $PROJECT |
180+
| Repository | $ORG/$PROJECT |
156181
| PR | #$PR_NUMBER |
157182
| Branch | branch-name |
158183

@@ -216,6 +241,7 @@ warning: variable name should be camelCase
216241
| gh CLI installed | "GitHub CLI is not installed" | Install from https://cli.github.com |
217242
| gh authenticated | "Not authenticated with GitHub" | Run `gh auth login` |
218243
| Project directory exists | "Project directory not found: [path]" | Verify project path in configuration |
244+
| Organization detected | "Cannot detect organization" | Use `--org` flag or full path format |
219245

220246
### Runtime Errors
221247

0 commit comments

Comments
 (0)