|
1 | 1 | name: Codegraph Impact Analysis |
2 | 2 | on: [pull_request] |
3 | 3 |
|
| 4 | +permissions: |
| 5 | + contents: read |
| 6 | + pull-requests: write |
| 7 | + |
4 | 8 | concurrency: |
5 | | - group: codegraph-impact-${{ github.ref }} |
| 9 | + group: codegraph-impact-${{ github.event.pull_request.number }} |
6 | 10 | cancel-in-progress: true |
7 | 11 |
|
8 | 12 | jobs: |
@@ -33,31 +37,47 @@ jobs: |
33 | 37 | path: .codegraph/ |
34 | 38 | key: codegraph-${{ hashFiles('src/**', 'package.json') }} |
35 | 39 | 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) |
38 | 42 | - 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 |
41 | 44 | - name: Comment on PR |
| 45 | + if: success() |
42 | 46 | uses: actions/github-script@v8 |
43 | 47 | with: |
44 | 48 | script: | |
45 | 49 | const fs = require('fs'); |
46 | 50 | 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)) { |
48 | 52 | console.log('No impact data to report.'); |
49 | 53 | return; |
50 | 54 | } |
51 | 55 | const body = `## Codegraph Impact Analysis\n\n` + |
52 | | - `**${impact.summary.functionsChanged} functions changed** -> ` + |
| 56 | + `**${impact.summary.functionsChanged} functions changed** → ` + |
53 | 57 | `**${impact.summary.callersAffected} callers affected** across ` + |
54 | | - `**${impact.summary.filesAffected} files**.\n\n` + |
| 58 | + `**${impact.summary.filesAffected} files**\n\n` + |
55 | 59 | (impact.affectedFunctions || []).slice(0, 20).map(f => |
56 | 60 | `- \`${f.name}\` in \`${f.file}:${f.line}\` (${f.transitiveCallers} transitive callers)` |
57 | 61 | ).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, { |
59 | 64 | owner: context.repo.owner, |
60 | 65 | repo: context.repo.repo, |
61 | 66 | issue_number: context.issue.number, |
62 | | - body |
63 | 67 | }); |
| 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 | + } |
0 commit comments