Skip to content

Commit 28a8a44

Browse files
authored
Merge pull request #1779 from cloudflare/diff
Refactor git diff handling
2 parents 01e5c6c + c2cb012 commit 28a8a44

56 files changed

Lines changed: 4106 additions & 1773 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/pint/lint.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ func verifyOwners(entries []*discovery.Entry, allowedOwners []*regexp.Regexp) (r
203203
}
204204
if entry.Owner == "" {
205205
reports = append(reports, reporter.Report{
206-
Path: entry.Path,
207-
ModifiedLines: entry.ModifiedLines,
208-
Rule: entry.Rule,
209-
Owner: "",
206+
Path: entry.Path,
207+
Changes: entry.Changes,
208+
Rule: entry.Rule,
209+
Owner: "",
210210
Problem: checks.Problem{
211211
Anchor: checks.AnchorAfter,
212212
Lines: entry.Rule.Lines,
@@ -230,10 +230,10 @@ func verifyOwners(entries []*discovery.Entry, allowedOwners []*regexp.Regexp) (r
230230
}
231231
}
232232
reports = append(reports, reporter.Report{
233-
Path: entry.Path,
234-
ModifiedLines: entry.ModifiedLines,
235-
Rule: entry.Rule,
236-
Owner: "",
233+
Path: entry.Path,
234+
Changes: entry.Changes,
235+
Rule: entry.Rule,
236+
Owner: "",
237237
Problem: checks.Problem{
238238
Anchor: checks.AnchorAfter,
239239
Lines: entry.Rule.Lines,

cmd/pint/scan.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ func scanWorker(ctx context.Context, jobs <-chan scanJob, results chan<- reporte
167167
checkDuration.WithLabelValues(job.check.Reporter()).Observe(time.Since(start).Seconds())
168168
for _, problem := range problems {
169169
results <- reporter.Report{
170-
Path: job.entry.Path,
171-
ModifiedLines: job.entry.ModifiedLines,
172-
Rule: job.entry.Rule,
173-
Problem: problem,
174-
Owner: job.entry.Owner,
175-
IsDuplicate: false, // unused
176-
Duplicates: nil,
170+
Path: job.entry.Path,
171+
Changes: job.entry.Changes,
172+
Rule: job.entry.Rule,
173+
Problem: problem,
174+
Owner: job.entry.Owner,
175+
IsDuplicate: false, // unused
176+
Duplicates: nil,
177177
}
178178
}
179179
}

cmd/pint/tests/0032_ci_github.txt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/files 200 [{"filename":"rules.yml", "patch": "@@ -1,4 +1,4 @@ - record: target is down\n- expr: up == 1\n+ expr: up == 0\n - record: sum errors\n expr: sum(errors) by (job)"}]http method github GET /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 []
21
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 []
32
http method github POST /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 {}
43
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/comments 200 []
@@ -73,12 +72,6 @@ rule {
7372
}
7473

7574
-- github.expected --
76-
GET /api/v3/repos/cloudflare/pint/pulls/1/files
77-
Accept: application/vnd.github.v3+json
78-
Accept-Encoding: gzip
79-
Authorization: Bearer 12345
80-
X-Github-Api-Version: 2022-11-28
81-
8275
GET /api/v3/repos/cloudflare/pint/pulls/1/comments
8376
Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
8477
Accept-Encoding: gzip
@@ -117,7 +110,7 @@ body: |
117110

118111
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/comparison.html).
119112
path: rules.yml
120-
line: 1
113+
line: 3
121114
side: RIGHT
122115
commit_id: <COMMIT ID>
123116
--- END ---
@@ -148,7 +141,7 @@ body: |
148141

149142
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/for.html).
150143
path: rules.yml
151-
line: 1
144+
line: 3
152145
side: RIGHT
153146
commit_id: <COMMIT ID>
154147
--- END ---
@@ -183,7 +176,7 @@ body: |
183176

184177
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/promql/aggregate.html).
185178
path: rules.yml
186-
line: 1
179+
line: 8
187180
side: RIGHT
188181
commit_id: <COMMIT ID>
189182
--- END ---

cmd/pint/tests/0033_ci_github_multi.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/files 200 [{"filename":"rules.yml", "patch": "@@ -1,4 +1,4 @@ - record: target is down\n- expr: up == 1\n+ expr: up == 0\n - record: sum errors\n expr: sum(errors) by (job)"}]http method github GET /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 []
21
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 []
32
http method github POST /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 {}
43
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/comments 200 []
@@ -67,12 +66,6 @@ repository {
6766
}
6867

6968
-- github.expected --
70-
GET /api/v3/repos/cloudflare/pint/pulls/1/files
71-
Accept: application/vnd.github.v3+json
72-
Accept-Encoding: gzip
73-
Authorization: Bearer 12345
74-
X-Github-Api-Version: 2022-11-28
75-
7669
GET /api/v3/repos/cloudflare/pint/pulls/1/comments
7770
Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
7871
Accept-Encoding: gzip
@@ -123,7 +116,7 @@ body: |
123116

124117
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/template.html).
125118
path: rules.yml
126-
line: 1
119+
line: 4
127120
side: RIGHT
128121
commit_id: <COMMIT ID>
129122
--- END ---
@@ -171,7 +164,7 @@ body: |
171164

172165
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/comparison.html).
173166
path: rules.yml
174-
line: 1
167+
line: 2
175168
side: RIGHT
176169
commit_id: <COMMIT ID>
177170
--- END ---

cmd/pint/tests/0083_github_action.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
http method github GET /api/v3/repos/foo/bar/pulls/123/files 200 [{"filename":"rules.yml", "patch": "@@ -1,4 +1,4 @@ - record: target is down\n- expr: up == 1\n+ expr: up == 0\n - record: sum errors\n expr: sum(errors) by (job)"}]
21
http method github GET /api/v3/repos/foo/bar/pulls/123/reviews 200 []
32
http method github POST /api/v3/repos/foo/bar/pulls/123/reviews 200 {}
43
http method github GET /api/v3/repos/foo/bar/pulls/123/comments 200 []
@@ -64,12 +63,6 @@ groups:
6463
repository {}
6564

6665
-- github.expected --
67-
GET /api/v3/repos/foo/bar/pulls/123/files
68-
Accept: application/vnd.github.v3+json
69-
Accept-Encoding: gzip
70-
Authorization: Bearer 12345
71-
X-Github-Api-Version: 2022-11-28
72-
7366
GET /api/v3/repos/foo/bar/pulls/123/comments
7467
Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
7568
Accept-Encoding: gzip
@@ -108,7 +101,7 @@ body: |
108101

109102
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/comparison.html).
110103
path: rules.yml
111-
line: 1
104+
line: 6
112105
side: RIGHT
113106
commit_id: <COMMIT ID>
114107
--- END ---
@@ -139,7 +132,7 @@ body: |
139132

140133
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/for.html).
141134
path: rules.yml
142-
line: 1
135+
line: 6
143136
side: RIGHT
144137
commit_id: <COMMIT ID>
145138
--- END ---

cmd/pint/tests/0084_github_action_override.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
http method github GET /api/v3/repos/cloudflare/pint/pulls/123/files 200 [{"filename":"rules.yml", "patch": "@@ -1,4 +1,4 @@ - record: target is down\n- expr: up == 1\n+ expr: up == 0\n - record: sum errors\n expr: sum(errors) by (job)"}]
21
http method github GET /api/v3/repos/cloudflare/pint/pulls/123/reviews 200 []
32
http method github POST /api/v3/repos/cloudflare/pint/pulls/123/reviews 200 {}
43
http method github GET /api/v3/repos/cloudflare/pint/pulls/123/comments 200 []
@@ -67,12 +66,6 @@ repository {
6766
}
6867

6968
-- github.expected --
70-
GET /api/v3/repos/cloudflare/pint/pulls/123/files
71-
Accept: application/vnd.github.v3+json
72-
Accept-Encoding: gzip
73-
Authorization: Bearer 12345
74-
X-Github-Api-Version: 2022-11-28
75-
7669
GET /api/v3/repos/cloudflare/pint/pulls/123/comments
7770
Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
7871
Accept-Encoding: gzip
@@ -111,7 +104,7 @@ body: |
111104

112105
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/comparison.html).
113106
path: rules.yml
114-
line: 1
107+
line: 6
115108
side: RIGHT
116109
commit_id: <COMMIT ID>
117110
--- END ---
@@ -142,7 +135,7 @@ body: |
142135

143136
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/for.html).
144137
path: rules.yml
145-
line: 1
138+
line: 6
146139
side: RIGHT
147140
commit_id: <COMMIT ID>
148141
--- END ---

cmd/pint/tests/0085_github_no_envs.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
http method github GET /api/v3/repos/cloudflare/pint/pulls/123/files 200 [{"filename":"rules.yml", "patch": "@@ -1,4 +1,4 @@ - record: target is down\n- expr: up == 1\n+ expr: up == 0\n - record: sum errors\n expr: sum(errors) by (job)"}]
21
http method github GET /api/v3/repos/cloudflare/pint/pulls/123/reviews 200 []
32
http method github POST /api/v3/repos/cloudflare/pint/pulls/123/reviews 200 {}
43
http method github GET /api/v3/repos/cloudflare/pint/pulls/123/comments 200 []
@@ -62,12 +61,6 @@ repository {
6261
}
6362

6463
-- github.expected --
65-
GET /api/v3/repos/cloudflare/pint/pulls/123/files
66-
Accept: application/vnd.github.v3+json
67-
Accept-Encoding: gzip
68-
Authorization: Bearer 12345
69-
X-Github-Api-Version: 2022-11-28
70-
7164
GET /api/v3/repos/cloudflare/pint/pulls/123/comments
7265
Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
7366
Accept-Encoding: gzip
@@ -106,7 +99,7 @@ body: |
10699

107100
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/comparison.html).
108101
path: rules.yml
109-
line: 1
102+
line: 6
110103
side: RIGHT
111104
commit_id: <COMMIT ID>
112105
--- END ---
@@ -137,7 +130,7 @@ body: |
137130

138131
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/for.html).
139132
path: rules.yml
140-
line: 1
133+
line: 6
141134
side: RIGHT
142135
commit_id: <COMMIT ID>
143136
--- END ---

cmd/pint/tests/0098_rule_file_symlink_gh.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/files 200 [{"filename":"rules.yml", "patch": "@@ -1,4 +1,4 @@ - record: target is down\n- expr: up == 1\n+ expr: up == 0\n - record: sum errors\n expr: sum(errors) by (job)"}]
21
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 []
32
http method github POST /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 {}
43
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/comments 200 []
@@ -62,12 +61,6 @@ repository {
6261
}
6362

6463
-- github.expected --
65-
GET /api/v3/repos/cloudflare/pint/pulls/1/files
66-
Accept: application/vnd.github.v3+json
67-
Accept-Encoding: gzip
68-
Authorization: Bearer 12345
69-
X-Github-Api-Version: 2022-11-28
70-
7164
GET /api/v3/repos/cloudflare/pint/pulls/1/comments
7265
Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
7366
Accept-Encoding: gzip
@@ -117,7 +110,7 @@ body: |
117110

118111
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/comparison.html).
119112
path: rules.yml
120-
line: 1
113+
line: 7
121114
side: RIGHT
122115
commit_id: <COMMIT ID>
123116
--- END ---

cmd/pint/tests/0118_ci_dir_move.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/files 200 [{"filename":"rules.yml", "patch": "@@ -1,4 +1,4 @@ - record: target is down\n- expr: up == 1\n+ expr: up == 0\n - record: sum errors\n expr: sum(errors) by (job)"}]
21
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 []
32
http method github POST /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 {}
43
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/comments 200 []
@@ -55,12 +54,6 @@ repository {
5554
}
5655

5756
-- github.expected --
58-
GET /api/v3/repos/cloudflare/pint/pulls/1/files
59-
Accept: application/vnd.github.v3+json
60-
Accept-Encoding: gzip
61-
Authorization: Bearer 12345
62-
X-Github-Api-Version: 2022-11-28
63-
6457
GET /api/v3/repos/cloudflare/pint/pulls/1/comments
6558
Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
6659
Accept-Encoding: gzip

cmd/pint/tests/0119_ci_fail_on_warning.txt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/files 200 [{"filename":"rules.yml", "patch": "@@ -1,4 +1,4 @@ - record: target is down\n- expr: up == 1\n+ expr: up == 0\n - record: sum errors\n expr: sum(errors) by (job)"}]
21
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 []
32
http method github POST /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 {}
43
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/comments 200 []
@@ -68,12 +67,6 @@ rule {
6867
}
6968

7069
-- github.expected --
71-
GET /api/v3/repos/cloudflare/pint/pulls/1/files
72-
Accept: application/vnd.github.v3+json
73-
Accept-Encoding: gzip
74-
Authorization: Bearer 12345
75-
X-Github-Api-Version: 2022-11-28
76-
7770
GET /api/v3/repos/cloudflare/pint/pulls/1/comments
7871
Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
7972
Accept-Encoding: gzip
@@ -108,7 +101,7 @@ body: |
108101

109102
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/rule/label.html).
110103
path: rules.yml
111-
line: 1
104+
line: 3
112105
side: RIGHT
113106
commit_id: <COMMIT ID>
114107
--- END ---
@@ -145,7 +138,7 @@ body: |
145138

146139
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/comparison.html).
147140
path: rules.yml
148-
line: 1
141+
line: 3
149142
side: RIGHT
150143
commit_id: <COMMIT ID>
151144
--- END ---
@@ -176,7 +169,7 @@ body: |
176169

177170
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/for.html).
178171
path: rules.yml
179-
line: 1
172+
line: 3
180173
side: RIGHT
181174
commit_id: <COMMIT ID>
182175
--- END ---

0 commit comments

Comments
 (0)