@@ -54,17 +54,19 @@ trait PullRequestService {
54
54
currentVersion : String
55
55
)
56
56
57
+ private [this ] val githubUrl = " https://api.github.com"
58
+
57
59
def claUrl (userName : String ): String =
58
60
s " https://www.lightbend.com/contribute/cla/scala/check/ $userName"
59
61
60
62
def commitsUrl (prNumber : Int ): String =
61
- s " https://api.github.com /repos/lampepfl/dotty/pulls/ $prNumber/commits?per_page=100 "
63
+ s " $githubUrl /repos/lampepfl/dotty/pulls/ $prNumber/commits?per_page=100 "
62
64
63
65
def statusUrl (sha : String ): String =
64
- s " https://api.github.com /repos/lampepfl/dotty/statuses/ $sha"
66
+ s " $githubUrl /repos/lampepfl/dotty/statuses/ $sha"
65
67
66
68
def issueCommentsUrl (issueNbr : Int ): String =
67
- s " https://api.github.com /repos/lampepfl/dotty/issues/ $issueNbr/comments "
69
+ s " $githubUrl /repos/lampepfl/dotty/issues/ $issueNbr/comments "
68
70
69
71
def toUri (url : String ): Task [Uri ] =
70
72
Uri .fromString(url).fold(Task .fail, Task .now)
@@ -201,7 +203,7 @@ trait PullRequestService {
201
203
(validStatuses, invalidStatuses) = statuses.partition(_.isValid)
202
204
invalidUsers = usersFromInvalid(invalidStatuses)
203
205
204
- // Mark the invalid statuses :
206
+ // Mark the invalid commits :
205
207
_ <- sendStatuses(invalidStatuses, httpClient)
206
208
207
209
// Set status of last to indicate previous failures or all good:
@@ -220,35 +222,48 @@ trait PullRequestService {
220
222
221
223
}
222
224
223
- // TODO: Could this be done with `issueNbr` instead?
225
+ def getStatus (commit : Commit , client : Client ): Task [StatusResponse ] =
226
+ for {
227
+ endpoint <- toUri(statusUrl(commit.sha))
228
+ req <- getRequest(endpoint)
229
+ res <- client.expect(req)(jsonOf[List [StatusResponse ]])
230
+ } yield res.head
231
+
224
232
def getStatuses (commits : List [Commit ], client : Client ): Task [List [StatusResponse ]] =
225
- ???
233
+ Task .gatherUnordered(commits.map(getStatus(_, client)))
226
234
227
- private def extractCommit (status : StatusResponse ): Task [Commit ] =
228
- ???
235
+ private def extractCommitSha (status : StatusResponse ): Task [String ] =
236
+ Task .delay(status.sha)
237
+
238
+ def recheckCLA (statuses : List [StatusResponse ], commits : List [Commit ], client : Client ): Task [List [CommitStatus ]] = {
239
+ /** Return the matching commits from the SHAs */
240
+ def prunedCommits (shas : List [String ]): Task [List [Commit ]] =
241
+ Task .delay(commits.filter(cm => shas.contains(cm.sha)))
229
242
230
- def recheckCLA (statuses : List [StatusResponse ], client : Client ): Task [List [CommitStatus ]] =
231
243
for {
232
- commits <- Task .gatherUnordered(statuses.map(extractCommit))
233
- statuses <- checkCLA(commits, client)
244
+ commitShas <- Task .gatherUnordered(statuses.map(extractCommitSha))
245
+ commits <- prunedCommits(commitShas)
246
+ statuses <- checkCLA(commits, client)
234
247
} yield statuses
248
+ }
235
249
236
250
def checkSynchronize (issue : Issue ): Task [Response ] = {
237
251
val httpClient = PooledHttp1Client ()
238
252
239
253
for {
240
- commits <- getCommits(issue.number, httpClient)
241
- statuses <- getStatuses(commits, httpClient)
242
- stillInvalid <- recheckCLA(statuses, httpClient)
254
+ commits <- getCommits(issue.number, httpClient)
255
+ statuses <- checkCLA(commits, httpClient)
256
+
257
+ (_, invalid) = statuses.partition(_.isValid)
258
+
259
+ _ <- sendStatuses(invalid, httpClient)
243
260
244
- // Set final commit status based on `stillInvalid `:
261
+ // Set final commit status based on `invalid `:
245
262
_ <- {
246
- if (stillInvalid.nonEmpty)
247
- setStatus(InvalidPrevious (usersFromInvalid(stillInvalid), commits.last), httpClient)
248
- else {
249
- val lastCommit = commits.last
250
- setStatus(Valid (lastCommit.author.login, lastCommit), httpClient)
251
- }
263
+ if (invalid.nonEmpty)
264
+ setStatus(InvalidPrevious (usersFromInvalid(invalid), commits.last), httpClient)
265
+ else
266
+ setStatus(statuses.last, httpClient)
252
267
}
253
268
_ <- shutdownClient(httpClient)
254
269
resp <- Ok (" Updated PR checked" )
0 commit comments