Skip to content

Commit 1529fed

Browse files
authored
Deduplicate linter comments (#606)
1 parent 150af47 commit 1529fed

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

.github/workflows/lint.yml

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Code Linting
22

33
on:
4-
pull_request_target:
5-
types: [opened, synchronize]
4+
pull_request:
5+
branches: [main]
6+
workflow_dispatch:
67

78
jobs:
89
lint:
@@ -27,22 +28,32 @@ jobs:
2728

2829
- name: Run linter
2930
run: |
30-
FILES=$(git diff --name-only --diff-filter=d ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '\.zig$' || true)
31-
echo "changed files: $FILES"
31+
echo "Base SHA: ${{ github.event.pull_request.base.sha }}"
32+
echo "Head SHA: ${{ github.event.pull_request.head.sha }}"
33+
34+
# Get changed .zig files
35+
FILES=$(git diff --name-only --diff-filter=d ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep '\.zig$' || true)
36+
echo "Changed files: $FILES"
37+
3238
if [ -n "$FILES" ]; then
33-
./tools/linter/zig-out/bin/linter $FILES > lint_results.json
39+
echo "$FILES" | xargs ./tools/linter/zig-out/bin/linter > lint_results.json
3440
else
3541
echo "[]" > lint_results.json
3642
fi
3743
38-
- name: Post comments
44+
# Debug output
45+
echo "Lint results:"
46+
cat lint_results.json
47+
48+
49+
- name: Post comments with metadata
3950
uses: actions/github-script@v7
4051
with:
4152
github-token: ${{ secrets.GITHUB_TOKEN }}
4253
script: |
4354
const fs = require('fs');
55+
const crypto = require('crypto');
4456
45-
// Check if lint results file exists and has content
4657
if (!fs.existsSync('lint_results.json')) {
4758
console.log('No lint results file found');
4859
return;
@@ -55,9 +66,40 @@ jobs:
5566
}
5667
5768
const issues = JSON.parse(content);
58-
console.log(`Found ${issues.length} lint issues`);
69+
70+
const existingComments = await github.rest.pulls.listReviewComments({
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
pull_number: context.issue.number
74+
});
75+
76+
const botComments = existingComments.data.filter(comment =>
77+
comment.user.login === 'github-actions[bot]' &&
78+
comment.body.includes('<!-- lint-comment')
79+
);
80+
81+
const existingHashes = new Set();
82+
botComments.forEach(comment => {
83+
const match = comment.body.match(/<!-- lint-comment:(\w+) -->/);
84+
if (match) existingHashes.add(match[1]);
85+
});
86+
87+
let postedCount = 0;
88+
let skippedCount = 0;
5989
6090
for (const issue of issues) {
91+
const issueData = `${issue.file}:${issue.line}:${issue.message}`;
92+
const issueHash = crypto.createHash('md5').update(issueData).digest('hex').substring(0, 8);
93+
94+
if (existingHashes.has(issueHash)) {
95+
console.log(`Skipping duplicate issue: ${issueHash}`);
96+
skippedCount++;
97+
continue;
98+
}
99+
100+
const commentBody = `${issue.message}\n\n<!-- lint-comment:${issueHash} -->\n`;
101+
console.log(`comment body:`, commentBody);
102+
61103
try {
62104
await github.rest.pulls.createReviewComment({
63105
owner: context.repo.owner,
@@ -66,10 +108,12 @@ jobs:
66108
commit_id: context.payload.pull_request.head.sha,
67109
path: issue.file,
68110
line: issue.line,
69-
body: issue.message
111+
body: commentBody
70112
});
71-
console.log(`Posted comment for ${issue.file}:${issue.line}`);
113+
postedCount++;
72114
} catch (error) {
73-
console.error(`Failed to post comment for ${issue.file}:${issue.line}:`, error.message);
115+
console.error(`Failed to post comment:`, error.message);
74116
}
75117
}
118+
119+
console.log(`Posted ${postedCount} new comments, skipped ${skippedCount} duplicates`);

build.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,3 +862,5 @@ inline fn custom_find_import_pkg_hash_or_fatal(comptime dep_name: []const u8) []
862862

863863
@panic("dependency not found");
864864
}
865+
866+
fn myFunc() void {}

port/nordic/nrf5x/src/hal.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ test "hal tests" {
2424

2525
_ = drivers;
2626
}
27+
28+
pub fn myFunc() void {}

0 commit comments

Comments
 (0)