forked from CodeGraphContext/CodeGraphContext
-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (96 loc) · 4.81 KB
/
Copy pathpr-code-graph.yml
File metadata and controls
110 lines (96 loc) · 4.81 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
# ─────────────────────────────────────────────────────────────────────────────
# .github/workflows/pr-code-graph.yml
# ─────────────────────────────────────────────────────────────────────────────
# Runs on every PR to produce a PR Reviewer graph JSON artifact.
# Uses CGC + FalkorDB Lite (Linux-native, zero-config embedded graph DB).
# ─────────────────────────────────────────────────────────────────────────────
name: "PR Code Graph Analysis"
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: read
jobs:
analyze:
name: "🔍 Build PR Code Graph"
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
# ── 1. Checkout the repository (with PR head) ────────────────────────
- name: Checkout PR head
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0 # full history for git-churn metrics
# ── 2. Set up Python ──────────────────────────────────────────────────
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
# ── 3. Install CGC + FalkorDB Lite ─────────────────────────────────
- name: Install CodeGraphContext
run: |
pip install --upgrade pip
pip install codegraphcontext falkordblite
# ── 4. Run the PR graph analysis script ────────────────────────────
- name: Analyze PR Code Graph
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Extract owner/repo/pr from the event context
OWNER="${{ github.repository_owner }}"
REPO="${{ github.event.repository.name }}"
PR_NUMBER="${{ github.event.pull_request.number }}"
# Run the analysis script
bash scripts/pr-graph-analyze.sh \
"$OWNER" "$REPO" "$PR_NUMBER" \
"./pr-graph-output"
# ── 5. Upload the JSON as a build artifact ─────────────────────────
- name: Upload PR Graph JSON
uses: actions/upload-artifact@v4
with:
name: pr-code-graph-${{ github.event.pull_request.number }}
path: ./pr-graph-output/*.json
retention-days: 30
# ── 6. (Optional) Post a comment with the viewer link ──────────────
- name: Comment PR with viewer link
if: success()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const pr = context.payload.pull_request.number;
const body = [
'## 🔍 PR Code Graph Analysis',
'',
`**${context.payload.pull_request.title}** (#${pr})`,
'',
'### 📊 Interactive Visualization',
`View the blast radius graph: **[PR Reviewer Dashboard](https://codegraphcontext.dev/pr-reviewer/${owner}/${repo}/pull/${pr})**`,
'',
'### 📦 Artifacts',
`The graph JSON has been uploaded as a build artifact: \`pr-code-graph-${pr}\``,
'',
'---',
'*Generated by [CodeGraphContext](https://github.com/CodeGraphContext/CodeGraphContext) using FalkorDB Lite*',
].join('\n');
// Check for existing bot comment to update instead of spam
const { data: comments } = await github.rest.issues.listComments({
owner, repo, issue_number: pr,
});
const existing = comments.find(c =>
c.user.type === 'Bot' && c.body.includes('PR Code Graph Analysis')
);
if (existing) {
await github.rest.issues.updateComment({
owner, repo, comment_id: existing.id, body,
});
} else {
await github.rest.issues.createComment({
owner, repo, issue_number: pr, body,
});
}