Skip to content

Commit 1e59011

Browse files
committed
Use a dedicated output field to indicate request conclusion
In cases where the request submitter or the submitted repositories are from entities without registry access privileges, the parser can determine the conclusion of the request. When the access control system was implemented, the pre-existing `type` field was used to pass this information. That field is used in two ways: - Determine the appropriate handling for the request. - Apply the appropriate labeling to the pull request. Although the `type` field is suitable for the first of these in the case where the request is declined, it is not very suitable for the second. The reason is that the labels are grouped in sets. The type data corresponds to the "topic" label set, while the conclusion corresponds to the "conclusion" set. The PR should be labeled with the appropriate label from each of these sets. So the request conclusion data is moved to a dedicated `conclusion` output field, leaving the `type` field to be used exclusively for its original purpose.
1 parent 16c5fb4 commit 1e59011

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type accessDataType struct {
9393

9494
// request is the type of the request data.
9595
type request struct {
96+
Conclusion string `json:"conclusion"` // Request conclusion.
9697
Type string `json:"type"` // Request type.
9798
ArduinoLintLibraryManagerSetting string `json:"arduinoLintLibraryManagerSetting"` // Argument to pass to Arduino Lint's --library-manager flag.
9899
Submissions []submissionType `json:"submissions"` // Data for submitted libraries.
@@ -185,7 +186,8 @@ func main() {
185186
if accessData.Host == "github.com" && *submitterArgument == accessData.Name {
186187
submitterAccess = accessData.Access
187188
if submitterAccess == Deny {
188-
req.Type = "declined"
189+
req.Conclusion = "declined"
190+
req.Type = "invalid"
189191
req.Error = fmt.Sprintf("Library registry privileges for @%s have been revoked.%%0ASee: %s", *submitterArgument, accessData.Reference)
190192
}
191193
break
@@ -216,7 +218,7 @@ func main() {
216218
}
217219
if len(submissionURLs) > 0 && !allowedSubmissions {
218220
// If none of the submissions are allowed, decline the request.
219-
req.Type = "declined"
221+
req.Conclusion = "declined"
220222
}
221223

222224
// Check for duplicates within the submission itself.

tests/test_all.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
@pytest.mark.parametrize(
2424
"repopath_folder_name,"
2525
"submitter,"
26+
"expected_conclusion,"
2627
"expected_type,"
2728
"expected_error,"
2829
"expected_submissions,"
@@ -32,6 +33,7 @@
3233
(
3334
"submitter-access-allow",
3435
"AllowUser",
36+
"",
3537
"submission",
3638
"",
3739
[
@@ -53,30 +55,33 @@
5355
"submitter-access-deny",
5456
"DenyUser",
5557
"declined",
58+
"invalid",
5659
"Library registry privileges for @DenyUser have been revoked.%0ASee: https://example.com",
5760
None,
5861
"",
5962
"",
6063
),
61-
("list-deleted-diff", "FooUser", "other", "", None, "", ""),
62-
("list-deleted-diff", "FooUser", "other", "", None, "", ""),
63-
("list-deleted-diff", "FooUser", "other", "", None, "", ""),
64-
("multi-file-diff", "FooUser", "other", "", None, "", ""),
65-
("non-list-diff", "FooUser", "other", "", None, "", ""),
66-
("list-rename-diff", "FooUser", "other", "", None, "", ""),
64+
("list-deleted-diff", "FooUser", "", "other", "", None, "", ""),
65+
("list-deleted-diff", "FooUser", "", "other", "", None, "", ""),
66+
("list-deleted-diff", "FooUser", "", "other", "", None, "", ""),
67+
("multi-file-diff", "FooUser", "", "other", "", None, "", ""),
68+
("non-list-diff", "FooUser", "", "other", "", None, "", ""),
69+
("list-rename-diff", "FooUser", "", "other", "", None, "", ""),
6770
(
6871
"no-final-newline-diff",
6972
"FooUser",
73+
"",
7074
"invalid",
7175
"Pull request removes newline from the end of a file.%0APlease add a blank line to the end of the file.",
7276
None,
7377
"",
7478
"",
7579
),
76-
("removal", "FooUser", "removal", "", None, "", ""),
80+
("removal", "FooUser", "", "removal", "", None, "", ""),
7781
(
7882
"modification",
7983
"FooUser",
84+
"",
8085
"modification",
8186
"",
8287
[
@@ -96,6 +101,7 @@
96101
(
97102
"url-error",
98103
"FooUser",
104+
"",
99105
"submission",
100106
"",
101107
[
@@ -115,6 +121,7 @@
115121
(
116122
"url-404",
117123
"FooUser",
124+
"",
118125
"submission",
119126
"",
120127
[
@@ -135,6 +142,7 @@
135142
"all-owner-access-deny",
136143
"FooUser",
137144
"declined",
145+
"submission",
138146
"",
139147
[
140148
{
@@ -154,6 +162,7 @@
154162
(
155163
"some-owner-access-deny",
156164
"FooUser",
165+
"",
157166
"submission",
158167
"",
159168
[
@@ -184,6 +193,7 @@
184193
(
185194
"not-supported-git-host",
186195
"FooUser",
196+
"",
187197
"submission",
188198
"",
189199
[
@@ -205,6 +215,7 @@
205215
(
206216
"not-git-clone-url",
207217
"FooUser",
218+
"",
208219
"submission",
209220
"",
210221
[
@@ -225,6 +236,7 @@
225236
(
226237
"already-in-library-manager",
227238
"FooUser",
239+
"",
228240
"submission",
229241
"",
230242
[
@@ -244,6 +256,7 @@
244256
(
245257
"type-arduino",
246258
"FooUser",
259+
"",
247260
"submission",
248261
"",
249262
[
@@ -263,6 +276,7 @@
263276
(
264277
"type-partner",
265278
"FooUser",
279+
"",
266280
"submission",
267281
"",
268282
[
@@ -282,6 +296,7 @@
282296
(
283297
"type-recommended",
284298
"FooUser",
299+
"",
285300
"submission",
286301
"",
287302
[
@@ -301,6 +316,7 @@
301316
(
302317
"type-contributed",
303318
"FooUser",
319+
"",
304320
"submission",
305321
"",
306322
[
@@ -321,6 +337,7 @@
321337
(
322338
"no-tags",
323339
"FooUser",
340+
"",
324341
"submission",
325342
"",
326343
[
@@ -342,6 +359,7 @@
342359
(
343360
"no-library-properties",
344361
"FooUser",
362+
"",
345363
"submission",
346364
"",
347365
[
@@ -362,6 +380,7 @@
362380
(
363381
"duplicates-in-submission",
364382
"FooUser",
383+
"",
365384
"submission",
366385
"",
367386
[
@@ -395,6 +414,7 @@ def test_request(
395414
run_command,
396415
repopath_folder_name,
397416
submitter,
417+
expected_conclusion,
398418
expected_type,
399419
expected_error,
400420
expected_submissions,
@@ -423,6 +443,7 @@ def test_request(
423443
assert result.ok
424444

425445
request = json.loads(result.stdout)
446+
assert request["conclusion"] == expected_conclusion
426447
assert request["type"] == expected_type
427448
assert request["error"] == expected_error
428449
assert request["submissions"] == expected_submissions

0 commit comments

Comments
 (0)