@@ -29,13 +29,14 @@ extension GitHub.Repository {
29
29
public var url : URL
30
30
public var output : Output ?
31
31
public var app : App
32
+ public var check_suite : CheckSuite
32
33
}
33
34
}
34
35
35
36
extension GitHub . Repository . CheckRun {
36
37
public struct Output : Decodable {
37
- public var title : String
38
- public var summary : String
38
+ public var title : String ?
39
+ public var summary : String ?
39
40
public var text : String ?
40
41
public var annotations : [ Annotation ] ?
41
42
}
@@ -79,22 +80,25 @@ extension GitHub.Repository.CheckRun {
79
80
public var id : Int
80
81
public var name : String
81
82
}
83
+
84
+ public struct CheckSuite : Decodable {
85
+ public var id : Int
86
+ }
82
87
}
83
88
84
89
extension GitHub . Repository {
85
90
public func currentCheckRun( ) -> CheckRun ? {
86
91
guard let sha = environment ( " GITHUB_SHA " ) else { return nil }
87
- guard let name = environment ( " GITHUB_ACTION " ) else { return nil }
88
- guard let checkRun = findCheckRun ( for: sha, with: name) else {
89
- print ( " Current Action ` \( name) ` not found! " )
92
+ guard let checkRun = findCheckRun ( for: sha) else {
93
+ print ( " Current Action not found! " )
90
94
return nil
91
95
}
92
96
return checkRun
93
97
}
94
98
95
- public func findCheckRun( for ref: String , with name : String ) -> CheckRun ? {
99
+ public func findCheckRun( for ref: String ) -> CheckRun ? {
96
100
return checkRuns ( for: ref) . first { checkRun -> Bool in
97
- checkRun. name == name && checkRun . app. name == " GitHub Actions "
101
+ checkRun. app. name == " GitHub Actions "
98
102
}
99
103
}
100
104
@@ -103,8 +107,10 @@ extension GitHub.Repository {
103
107
var check_runs : [ CheckRun ]
104
108
}
105
109
106
- let response : Response ? = request ( url ( with: " /repos/ \( repo) /commits/ \( ref) /check-runs " ) )
107
- return response? . check_runs ?? [ ]
110
+ let response1 : Response ? = request ( url ( with: " /repos/ \( repo) /commits/ \( ref) /check-runs " ) )
111
+ guard let suite_id = response1? . check_runs. first? . check_suite. id else { return [ ] }
112
+ let response2 : Response ? = request ( url ( with: " /repos/ \( repo) /check-suites/ \( suite_id) /check-runs " ) )
113
+ return response2? . check_runs ?? [ ]
108
114
}
109
115
110
116
@discardableResult
@@ -118,16 +124,17 @@ extension GitHub.Repository {
118
124
var output : Output
119
125
}
120
126
121
- guard let output = checkRun. output else {
122
- print ( " \( checkRun) has no output. " )
123
- return false
124
- }
127
+ let title = " SwiftLint Violations "
128
+ let warnings = annotations. filter { $0. annotation_level == . warning } . count
129
+ let failure = annotations. filter { $0. annotation_level == . failure } . count
130
+ let summary = " warnings: \( warnings) , failures: \( failure) "
131
+
125
132
let batchSize = 50
126
133
var rest = ArraySlice ( annotations)
127
134
while !rest. isEmpty {
128
135
let annotations = Array ( rest. prefix ( batchSize) )
129
136
rest = rest. dropFirst ( batchSize)
130
- let output = Request . Output ( title: output . title, summary: output . summary, annotations: annotations)
137
+ let output = Request . Output ( title: title, summary: summary, annotations: annotations)
131
138
let response : CheckRun ? = request ( checkRun. url, method: " PATCH " , with: Request ( output: output) )
132
139
if response == nil {
133
140
return false
@@ -174,6 +181,9 @@ extension GitHub.Repository {
174
181
}
175
182
guard ( 200 ... 299 ) . contains ( httpURLResponse. statusCode) else {
176
183
print ( " server error status: \( httpURLResponse. statusCode) " )
184
+ if let data = data, let output = String ( data: data, encoding: . utf8) {
185
+ print ( output)
186
+ }
177
187
return
178
188
}
179
189
guard let data = data else {
0 commit comments