Skip to content

Commit 0db095d

Browse files
author
Tom Brandenburg
committed
fix: ghar fix
1 parent 01ede53 commit 0db095d

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

.github/workflows/ghar-issue-command-executor.yml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
contents: write
1818
outputs:
1919
has-command: ${{ steps.parse-comment.outputs.has_command }}
20+
has-agent: ${{ steps.parse-comment.outputs.has_agent }}
2021
command: ${{ steps.parse-comment.outputs.command }}
2122
prompt: ${{ steps.parse-comment.outputs.prompt }}
2223
agent: ${{ steps.parse-comment.outputs.agent }}
23-
is-agent-command: ${{ steps.parse-comment.outputs.is_agent_command }}
2424

2525
steps:
2626
- name: Checkout repository
@@ -65,6 +65,8 @@ jobs:
6565
prompt="${BASH_REMATCH[3]}"
6666
# Remove leading whitespace from prompt
6767
prompt=$(echo "$prompt" | sed 's/^[[:space:]]*//')
68+
# "agent" is a generic placeholder — clear it to trigger the "build" fallback
69+
[[ "$agent" == "agent" ]] && agent=""
6870
6971
echo "Detected agent command"
7072
echo "agent=$agent" >> $GITHUB_OUTPUT
@@ -73,7 +75,24 @@ jobs:
7375
echo "$prompt" >> $GITHUB_OUTPUT
7476
echo "EOF" >> $GITHUB_OUTPUT
7577
echo "has_command=true" >> $GITHUB_OUTPUT
76-
echo "is_agent_command=true" >> $GITHUB_OUTPUT
78+
echo "has_agent=true" >> $GITHUB_OUTPUT
79+
80+
elif [[ "$comment" =~ ^\*([a-zA-Z0-9_-]+)[[:space:]]+(.*)$ ]]; then
81+
# Agent prompt format: *agent PROMPT (no slash command)
82+
agent="${BASH_REMATCH[1]}"
83+
prompt="${BASH_REMATCH[2]}"
84+
# Remove leading whitespace from prompt
85+
prompt=$(echo "$prompt" | sed 's/^[[:space:]]*//')
86+
# "agent" is a generic placeholder — clear it to trigger the "build" fallback
87+
[[ "$agent" == "agent" ]] && agent=""
88+
89+
echo "Detected agent prompt"
90+
echo "agent=$agent" >> $GITHUB_OUTPUT
91+
echo "prompt<<EOF" >> $GITHUB_OUTPUT
92+
echo "$prompt" >> $GITHUB_OUTPUT
93+
echo "EOF" >> $GITHUB_OUTPUT
94+
echo "has_command=false" >> $GITHUB_OUTPUT
95+
echo "has_agent=true" >> $GITHUB_OUTPUT
7796
7897
elif [[ "$comment" =~ ^/([a-zA-Z0-9_-]+)(.*)$ ]]; then
7998
# Direct command format: /command PROMPT
@@ -88,15 +107,16 @@ jobs:
88107
echo "$prompt" >> $GITHUB_OUTPUT
89108
echo "EOF" >> $GITHUB_OUTPUT
90109
echo "has_command=true" >> $GITHUB_OUTPUT
91-
echo "is_agent_command=false" >> $GITHUB_OUTPUT
110+
echo "has_agent=false" >> $GITHUB_OUTPUT
92111
93112
else
94113
echo "No command detected in comment"
95114
echo "has_command=false" >> $GITHUB_OUTPUT
115+
echo "has_agent=false" >> $GITHUB_OUTPUT
96116
fi
97117
98118
execute-opencode:
99-
if: needs.parse-and-check.outputs.has-command == 'true'
119+
if: needs.parse-and-check.outputs.has-command == 'true' || needs.parse-and-check.outputs.has-agent == 'true'
100120
needs: parse-and-check
101121
permissions:
102122
issues: write
@@ -107,11 +127,11 @@ jobs:
107127
run-name: "${{ github.event.issue.number != null && format('issue-{0}-comment-{1}', github.event.issue.number, github.event.comment.id) || format('pr-{0}-comment-{1}', github.event.pull_request.number, github.event.comment.id) }}"
108128
command: ${{ needs.parse-and-check.outputs.command }}
109129
prompt: ${{ needs.parse-and-check.outputs.prompt }}
110-
agent: ${{ needs.parse-and-check.outputs.is-agent-command == 'true' && needs.parse-and-check.outputs.agent || 'build' }}
130+
agent: ${{ needs.parse-and-check.outputs.agent || 'build' }}
111131
timeout-minutes: 30
112132

113133
comment-results:
114-
if: needs.parse-and-check.outputs.has-command == 'true' && always()
134+
if: (needs.parse-and-check.outputs.has-command == 'true' || needs.parse-and-check.outputs.has-agent == 'true') && always()
115135
needs: [parse-and-check, execute-opencode]
116136
runs-on: ubuntu-latest
117137
permissions:
@@ -123,8 +143,9 @@ jobs:
123143
uses: actions/github-script@v7
124144
with:
125145
script: |
146+
const hasCommand = '${{ needs.parse-and-check.outputs.has-command }}' === 'true';
147+
const hasAgent = '${{ needs.parse-and-check.outputs.has-agent }}' === 'true';
126148
const command = '${{ needs.parse-and-check.outputs.command }}';
127-
const isAgentCommand = '${{ needs.parse-and-check.outputs.is-agent-command }}' === 'true';
128149
const agent = '${{ needs.parse-and-check.outputs.agent }}';
129150
const runId = context.runId;
130151
@@ -134,10 +155,12 @@ jobs:
134155
const artifactName = '${{ needs.execute-opencode.outputs.artifact-name }}';
135156
136157
let executionType;
137-
if (isAgentCommand) {
138-
executionType = '*' + agent + ' /' + command + ' (agent command)';
158+
if (hasAgent && hasCommand) {
159+
executionType = '*' + agent + ' /' + command;
160+
} else if (hasAgent) {
161+
executionType = '*' + agent;
139162
} else {
140-
executionType = '/' + command + ' (direct command)';
163+
executionType = '/' + command;
141164
}
142165
143166
let commentBody;

.opencode/commands/ghar-issue-fix.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,26 @@ git push
557557

558558
### PR creation fails
559559

560-
- Check if PR already exists for branch
561-
- Check for permission issues
562-
- Provide manual gh command
560+
1. Check if a PR already exists for the branch: `gh pr list --head {branch-name}`
561+
- If yes → use that PR, continue
562+
2. Check the error message:
563+
- **"GitHub Actions is not permitted to create or approve pull requests"** → This is a repository-level setting blocking PR creation. Note: the workflow already declares `pull-requests: write` — that is **not** the problem. The repo admin must enable the feature separately.
564+
- **STOP** — do NOT continue to the self-review or archive phases
565+
- Output clearly:
566+
```
567+
❌ PR creation blocked by GitHub Actions permissions.
568+
569+
The branch has been pushed: {branch-url}
570+
571+
To fix (repo admin required):
572+
Settings → Actions → General → Workflow permissions
573+
→ Enable "Allow GitHub Actions to create and approve pull requests"
574+
575+
To create the PR manually in the meantime, run:
576+
gh pr create --title "{title}" --head {branch-name} --base main
577+
```
578+
- **Other permission / auth error** → STOP with the error message and suggest using a PAT with `repo` scope
579+
3. Only provide a manual `gh pr create` command and STOP — do NOT proceed to Phase 8 (review) or Phase 9 (archive) without a real PR number
563580
564581
### Already on a branch with changes
565582

0 commit comments

Comments
 (0)