-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (109 loc) · 4.12 KB
/
Copy pathopencode-slash-command.yml
File metadata and controls
127 lines (109 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: OpenCode Slash Command
on:
issue_comment:
types: [created]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
run:
name: OpenCode /oc command
if: |
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/oc') &&
github.event.comment.author_association == 'OWNER'
runs-on: ubuntu-latest
steps:
- name: Generate app token
uses: actions/create-github-app-token@v3
id: app-token
with:
client-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Acknowledge command
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
gh api \
"repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" \
-X POST \
-f content='rocket'
- name: Fetch PR metadata
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ github.event.issue.number }}
run: |
set -euo pipefail
mkdir -p .review
# Full PR data as JSON for OpenCode context
gh pr view "$PR" --json title,body,labels,baseRefName > .review/pr.json
# PR diff for analysis
gh pr diff "$PR" > .review/patch.diff
# PR title for the OpenCode prompt
PR_TITLE=$(gh pr view "$PR" --json title -q '.title')
echo "title=$PR_TITLE" >> "$GITHUB_OUTPUT"
# Checkout dev (the fixed base branch for renovate PRs). PR head code is
# untrusted and must not be executed. We only need the repo's tooling and
# workflow definitions; all PR content is accessed via the GitHub API.
- name: Checkout trusted base (dev)
uses: actions/checkout@v7
with:
ref: dev
persist-credentials: false
- name: Extract prompt
id: prompt
env:
BODY: ${{ github.event.comment.body }}
run: |
# Strip the "/oc" command prefix, then one optional leading space.
PROMPT="${BODY#/oc}"
PROMPT="${PROMPT# }"
{
echo 'text<<OC_PROMPT_DELIM'
printf '%s\n' "$PROMPT"
echo 'OC_PROMPT_DELIM'
} >> "$GITHUB_OUTPUT"
- name: Guard against empty prompt
if: steps.prompt.outputs.text == ''
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
gh api \
"repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
-X POST \
-f body='Usage: `/oc <task description>` — provide a task for OpenCode to perform on this PR.'
echo "Empty /oc prompt; exiting." >&2
exit 1
- name: Install OpenCode CLI
run: |
set -euo pipefail
curl -fsSL https://opencode.ai/install | bash
echo "$HOME/.opencode/bin" >> "$GITHUB_PATH"
- name: Assemble OpenCode prompt
run: |
cat > .review/oc-prompt.md << 'PROMPT_EOF'
You are assisting with a task on the local-stack infrastructure repository.
You have access to the `gh` CLI authenticated via GH_TOKEN to interact
with GitHub (create issues, comment, review, etc.).
PR context:
- Repository: ${{ github.repository }}
- PR number: ${{ github.event.issue.number }}
- PR title: ${{ steps.pr.outputs.title }}
- PR diff is available at .review/patch.diff
- PR metadata is available at .review/pr.json
Read the PR diff and metadata files to understand the changes before
acting on the task below.
## Task
PROMPT_EOF
printf '%s\n' "${{ steps.prompt.outputs.text }}" >> .review/oc-prompt.md
- name: Run OpenCode
env:
OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
opencode run \
--title "OpenCode /oc command for PR #${{ github.event.issue.number }}" \
--model opencode/deepseek-v4-flash \
< .review/oc-prompt.md