Skip to content

Commit d5a187b

Browse files
authored
fix: repair impact workflow that never posted PR comments (#821)
* fix: repair impact analysis workflow that never posted PR comments The workflow had three bugs preventing it from ever working: - Used non-existent --ref flag (should be positional arg) - Used non-existent --json flag (diff-impact uses -f json) - Missing pull-requests: write permission for commenting Also adds -j/--json shorthand to diff-impact for consistency with all other commands, switches npx to node dist/cli.js to eliminate ~5min startup overhead per invocation, removes silent error swallowing, and updates comments in-place on force-push. * docs: fix broken --ref and --json flags in diff-impact examples All docs examples used non-existent --ref flag (should be positional) and --json flag (should be -f json) for diff-impact commands. * fix: add contents:read permission and paginate comment listing (#821)
1 parent 5d2905f commit d5a187b

5 files changed

Lines changed: 37 additions & 16 deletions

File tree

.github/workflows/codegraph-impact.yml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
name: Codegraph Impact Analysis
22
on: [pull_request]
33

4+
permissions:
5+
contents: read
6+
pull-requests: write
7+
48
concurrency:
5-
group: codegraph-impact-${{ github.ref }}
9+
group: codegraph-impact-${{ github.event.pull_request.number }}
610
cancel-in-progress: true
711

812
jobs:
@@ -33,31 +37,47 @@ jobs:
3337
path: .codegraph/
3438
key: codegraph-${{ hashFiles('src/**', 'package.json') }}
3539
restore-keys: codegraph-
36-
- name: Build codegraph
37-
run: npx codegraph build || (rm -rf .codegraph && npx codegraph build --no-incremental)
40+
- name: Build graph
41+
run: node dist/cli.js build || (rm -rf .codegraph && node dist/cli.js build --no-incremental)
3842
- name: Run impact analysis
39-
run: |
40-
npx codegraph diff-impact --ref origin/${{ github.base_ref }} --json -T > impact.json || echo '{"affectedFiles":[],"summary":null}' > impact.json
43+
run: node dist/cli.js diff-impact origin/${{ github.base_ref }} --json -T > impact.json
4144
- name: Comment on PR
45+
if: success()
4246
uses: actions/github-script@v8
4347
with:
4448
script: |
4549
const fs = require('fs');
4650
const impact = JSON.parse(fs.readFileSync('impact.json', 'utf-8'));
47-
if (!impact.summary) {
51+
if (!impact.summary || (impact.summary.functionsChanged === 0 && impact.summary.callersAffected === 0)) {
4852
console.log('No impact data to report.');
4953
return;
5054
}
5155
const body = `## Codegraph Impact Analysis\n\n` +
52-
`**${impact.summary.functionsChanged} functions changed** -> ` +
56+
`**${impact.summary.functionsChanged} functions changed** ` +
5357
`**${impact.summary.callersAffected} callers affected** across ` +
54-
`**${impact.summary.filesAffected} files**.\n\n` +
58+
`**${impact.summary.filesAffected} files**\n\n` +
5559
(impact.affectedFunctions || []).slice(0, 20).map(f =>
5660
`- \`${f.name}\` in \`${f.file}:${f.line}\` (${f.transitiveCallers} transitive callers)`
5761
).join('\n');
58-
github.rest.issues.createComment({
62+
// Update existing comment or create new one
63+
const comments = await github.paginate(github.rest.issues.listComments, {
5964
owner: context.repo.owner,
6065
repo: context.repo.repo,
6166
issue_number: context.issue.number,
62-
body
6367
});
68+
const existing = comments.find(c => c.body.startsWith('## Codegraph Impact Analysis'));
69+
if (existing) {
70+
await github.rest.issues.updateComment({
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
comment_id: existing.id,
74+
body,
75+
});
76+
} else {
77+
await github.rest.issues.createComment({
78+
owner: context.repo.owner,
79+
repo: context.repo.repo,
80+
issue_number: context.issue.number,
81+
body,
82+
});
83+
}

docs/guides/ai-agent-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ Add a GitHub Actions workflow that posts `diff-impact` results on every PR:
960960

961961
- name: Analyze PR impact
962962
run: |
963-
npx @optave/codegraph diff-impact origin/${{ github.base_ref }} --json -T > impact.json
963+
npx @optave/codegraph diff-impact origin/${{ github.base_ref }} -f json -T > impact.json
964964
965965
- name: Comment on PR
966966
uses: actions/github-script@v7

docs/guides/recommended-practices.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ See what your branch will affect before pushing:
3333
```bash
3434
# .husky/pre-push
3535
codegraph build
36-
codegraph diff-impact --ref origin/main --no-tests
36+
codegraph diff-impact origin/main --no-tests
3737
```
3838

3939
This prints a summary like:
@@ -47,7 +47,7 @@ If you want to **block pushes** that exceed a threshold, add a check:
4747
```bash
4848
# .husky/pre-push
4949
codegraph build
50-
IMPACT=$(codegraph diff-impact --ref origin/main --no-tests --json)
50+
IMPACT=$(codegraph diff-impact origin/main --no-tests -f json)
5151
AFFECTED=$(echo "$IMPACT" | node -e "
5252
const d = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
5353
console.log(d.summary?.callersAffected || 0)
@@ -98,7 +98,7 @@ Add a threshold check to your CI pipeline:
9898
- name: Check impact threshold
9999
run: |
100100
npx codegraph build
101-
IMPACT=$(npx codegraph diff-impact --ref origin/${{ github.base_ref }} --json)
101+
IMPACT=$(npx codegraph diff-impact origin/${{ github.base_ref }} -f json)
102102
AFFECTED=$(echo "$IMPACT" | node -e "
103103
const d = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
104104
console.log(d.summary?.callersAffected || 0)

docs/use-cases/harness-engineering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ All of the above works in CI pipelines, not just locally:
198198

199199
- name: Impact comment on PR
200200
run: |
201-
IMPACT=$(npx codegraph diff-impact --ref origin/${{ github.base_ref }} -T)
201+
IMPACT=$(npx codegraph diff-impact origin/${{ github.base_ref }} -T)
202202
gh pr comment ${{ github.event.number }} --body "$IMPACT"
203203
```
204204

src/cli/commands/diff-impact.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const command: CommandDefinition = {
1313
['--ndjson', 'Newline-delimited JSON output'],
1414
['--staged', 'Analyze staged changes instead of unstaged'],
1515
['--depth <n>', 'Max transitive caller depth', '3'],
16+
['-j, --json', 'Output as JSON (shorthand for -f json)'],
1617
['-f, --format <format>', 'Output format: text, mermaid, json', 'text'],
1718
['--no-implementations', 'Exclude interface/trait implementors from blast radius'],
1819
],
@@ -21,7 +22,7 @@ export const command: CommandDefinition = {
2122
ref,
2223
staged: opts.staged,
2324
depth: parseInt(opts.depth as string, 10),
24-
format: opts.format,
25+
format: opts.json ? 'json' : opts.format,
2526
includeImplementors: opts.implementations !== false,
2627
...ctx.resolveQueryOpts(opts),
2728
});

0 commit comments

Comments
 (0)