Skip to content

Commit 65da069

Browse files
authored
Merge pull request #95 from kompassdev/fix/pr-review-branch-handling
fix: tighten PR review branch handling
2 parents 0b3520e + 501b2c2 commit 65da069

14 files changed

Lines changed: 97 additions & 27 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Kompass PR Review Comment
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
jobs:
8+
review:
9+
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/review') && contains(fromJson('["OWNER","MEMBER"]'), github.event.comment.author_association)
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Generate GitHub App Token
13+
id: token
14+
uses: actions/create-github-app-token@v1
15+
with:
16+
app-id: ${{ secrets.KOMPASS_APP_ID }}
17+
private-key: ${{ secrets.KOMPASS_APP_PRIVATE_KEY }}
18+
19+
- name: Get PR details
20+
id: pr
21+
env:
22+
GH_TOKEN: ${{ steps.token.outputs.token }}
23+
run: |
24+
gh api /repos/${{ github.repository }}/pulls/${{ github.event.issue.number }} > pr_data.json
25+
echo "head_repo=$(jq -r .head.repo.full_name pr_data.json)" >> "$GITHUB_OUTPUT"
26+
echo "head_ref=$(jq -r .head.ref pr_data.json)" >> "$GITHUB_OUTPUT"
27+
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
with:
31+
repository: ${{ steps.pr.outputs.head_repo }}
32+
ref: ${{ steps.pr.outputs.head_ref }}
33+
fetch-depth: 0
34+
token: ${{ steps.token.outputs.token }}
35+
36+
- name: Setup Bun
37+
uses: oven-sh/setup-bun@v1
38+
with:
39+
bun-version: latest
40+
41+
- name: Install dependencies
42+
run: bun install
43+
44+
- name: Install Kompass Tooling
45+
uses: ./.github/actions/kompass-opencode-install
46+
47+
- name: Run Kompass PR Review
48+
env:
49+
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
50+
OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
51+
run: opencode run --model="${{ vars.OPENCODE_MODEL }}" --variant="${{ vars.OPENCODE_VARIANT }}" --thinking --command="pr/review" "${{ github.event.issue.number }}"
52+
53+
- name: Export Kompass Session
54+
if: always()
55+
uses: ./.github/actions/kompass-opencode-session-export

.github/workflows/kompass-pr-review.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
review:
9-
if: github.event.pull_request.draft == false
9+
if: github.event.pull_request.draft == false && github.event.pull_request.head.repo.full_name == github.repository
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Generate GitHub App Token

kompass.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
},
5252

5353
"components": {
54+
"align-pr-branch": { "enabled": true },
5455
"change-summary": { "enabled": true },
5556
"changes-summary": { "enabled": true },
5657
"commit": { "enabled": true },

kompass.schema.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@
215215
"type": "object",
216216
"additionalProperties": false,
217217
"properties": {
218+
"align-pr-branch": {
219+
"$ref": "#/$defs/componentConfig"
220+
},
218221
"change-summary": {
219222
"$ref": "#/$defs/componentConfig"
220223
},
@@ -243,15 +246,15 @@
243246
"type": "array",
244247
"items": {
245248
"type": "string",
246-
"enum": ["change-summary", "changes-summary", "commit", "dev-flow", "load-pr", "load-ticket", "skill-authoring", "summarize-changes"]
249+
"enum": ["align-pr-branch", "change-summary", "changes-summary", "commit", "dev-flow", "load-pr", "load-ticket", "skill-authoring", "summarize-changes"]
247250
},
248251
"uniqueItems": true,
249252
"deprecated": true
250253
},
251254
"paths": {
252255
"type": "object",
253256
"propertyNames": {
254-
"enum": ["change-summary", "changes-summary", "commit", "dev-flow", "load-pr", "load-ticket", "skill-authoring", "summarize-changes"]
257+
"enum": ["align-pr-branch", "change-summary", "changes-summary", "commit", "dev-flow", "load-pr", "load-ticket", "skill-authoring", "summarize-changes"]
255258
},
256259
"additionalProperties": {
257260
"type": "string"

packages/core/commands/pr/fix.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ $ARGUMENTS
3030

3131
### Align Local Branch
3232

33-
- If `<pr-branch>` is unavailable, STOP and report that the PR head branch could not be determined
34-
- If `<current-branch>` differs from `<pr-branch>`:
35-
- Checkout `<pr-branch>` before analyzing repository files or making code changes for this PR
36-
- After checkout, store the active branch as `<active-branch>`
37-
- If checkout fails, STOP and report that the PR branch could not be checked out locally
38-
- Otherwise, store `<current-branch>` as `<active-branch>`
39-
- Do not inspect or modify local code for this PR until `<active-branch>` equals `<pr-branch>`
33+
<%~ include("@align-pr-branch", { action: "analyzing repository files or making code changes for this PR", scope: "inspect or modify local code for this PR" }) %>
4034

4135
### Analyze Feedback
4236

packages/core/commands/pr/review.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ $ARGUMENTS
2626

2727
### Align Local Branch
2828

29-
- If `<pr-branch>` is unavailable, STOP and report that the PR head branch could not be determined
30-
- If `<current-branch>` differs from `<pr-branch>`:
31-
- Checkout `<pr-branch>` before inspecting local repository files for this PR review
32-
- After checkout, store the active branch as `<active-branch>`
33-
- If checkout fails, STOP and report that the PR branch could not be checked out locally
34-
- Otherwise, store `<current-branch>` as `<active-branch>`
35-
- Do not inspect local repository code for this PR until `<active-branch>` equals `<pr-branch>`
29+
<%~ include("@align-pr-branch", { action: "inspecting local repository files for this PR review", scope: "inspect local repository code for this PR" }) %>
3630

3731
### Load Ticket Context
3832

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- If `<pr-branch>` is unavailable, STOP and report that the PR head branch could not be determined
2+
- Run `gh pr checkout <pr-context.pr.number>` before <%= it.action %>
3+
- After checkout, store the active branch as `<active-branch>`
4+
- If checkout fails, STOP and report that the PR branch could not be checked out locally
5+
- Do not <%= it.scope %> until `<active-branch>` equals `<pr-branch>`

packages/core/kompass.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
},
5252

5353
"components": {
54+
"align-pr-branch": { "enabled": true },
5455
"change-summary": { "enabled": true },
5556
"changes-summary": { "enabled": true },
5657
"commit": { "enabled": true },

packages/core/lib/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const DEFAULT_COMMAND_NAMES = [
4848
export const DEFAULT_AGENT_NAMES = ["worker", "navigator", "planner", "reviewer"] as const;
4949

5050
export const DEFAULT_COMPONENT_NAMES = [
51+
"align-pr-branch",
5152
"change-summary",
5253
"changes-summary",
5354
"commit",
@@ -129,6 +130,7 @@ export interface KompassConfig {
129130
ticket_load?: ToolConfig;
130131
};
131132
components?: {
133+
"align-pr-branch"?: ComponentConfig;
132134
"change-summary"?: ComponentConfig;
133135
"changes-summary"?: ComponentConfig;
134136
commit?: ComponentConfig;
@@ -443,6 +445,7 @@ const defaultAgentPlanner: AgentDefinition = {
443445
};
444446

445447
const defaultComponentPaths: Record<string, string> = {
448+
"align-pr-branch": "components/align-pr-branch.md",
446449
"change-summary": "components/change-summary.md",
447450
"changes-summary": "components/changes-summary.md",
448451
"commit": "components/commit.md",

packages/opencode/.opencode/commands/pr/fix.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ $ARGUMENTS
4545
### Align Local Branch
4646

4747
- If `<pr-branch>` is unavailable, STOP and report that the PR head branch could not be determined
48-
- If `<current-branch>` differs from `<pr-branch>`:
49-
- Checkout `<pr-branch>` before analyzing repository files or making code changes for this PR
50-
- After checkout, store the active branch as `<active-branch>`
51-
- If checkout fails, STOP and report that the PR branch could not be checked out locally
52-
- Otherwise, store `<current-branch>` as `<active-branch>`
48+
- Run `gh pr checkout <pr-context.pr.number>` before analyzing repository files or making code changes for this PR
49+
- After checkout, store the active branch as `<active-branch>`
50+
- If checkout fails, STOP and report that the PR branch could not be checked out locally
5351
- Do not inspect or modify local code for this PR until `<active-branch>` equals `<pr-branch>`
5452

5553
### Analyze Feedback

0 commit comments

Comments
 (0)