-
-
Notifications
You must be signed in to change notification settings - Fork 125
89 lines (75 loc) · 2.8 KB
/
Copy pathpr-context.yml
File metadata and controls
89 lines (75 loc) · 2.8 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
name: Suggest relevant context for PRs
on:
pull_request:
types: [opened]
permissions:
pull-requests: write
jobs:
suggest-context:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: astral-sh/setup-uv@v7
- name: Install cognitive-cache
run: uv tool install cognitive-cache
- name: Get changed files
id: diff
env:
BASE_REF: ${{ github.base_ref }}
run: |
echo "files<<EOF" >> "$GITHUB_OUTPUT"
git diff --name-only "origin/${BASE_REF}...HEAD" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Select relevant context
id: select
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BODY: ${{ github.event.pull_request.body }}
CHANGED_FILES: ${{ steps.diff.outputs.files }}
run: |
TASK="PR: ${PR_TITLE}. ${PR_BODY}. Changed files: ${CHANGED_FILES}"
cognitive-cache select \
--repo . \
--task "${TASK}" \
--budget 16000 \
--json > /tmp/cc-result.json
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const result = JSON.parse(fs.readFileSync('/tmp/cc-result.json', 'utf8'));
if (!result.files || result.files.length === 0) {
core.info('No relevant context files found, skipping comment.');
return;
}
const changedFiles = process.env.CHANGED_FILES?.split('\n').filter(Boolean) || [];
const contextFiles = result.files.filter(f => !changedFiles.includes(f.path));
if (contextFiles.length === 0) {
core.info('All relevant files are already in the diff, skipping comment.');
return;
}
const rows = contextFiles.slice(0, 15).map(f =>
`| \`${f.path}\` | ${f.score.toFixed(3)} | ${f.token_count} |`
).join('\n');
const body = [
'### Context for reviewers',
'',
'Files not in this diff but likely needed to understand the change:',
'',
'| File | Relevance | Tokens |',
'|------|-----------|--------|',
rows,
'',
`<sub>${contextFiles.length} context files selected via symbol analysis, dependency graphs, and git history. No LLM calls.</sub>`,
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
env:
CHANGED_FILES: ${{ steps.diff.outputs.files }}