Skip to content

Commit f4afe46

Browse files
committed
Task 4 done
1 parent cbab289 commit f4afe46

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/contributors/GitHubService.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,50 @@ import retrofit2.Retrofit
1212
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
1313
import retrofit2.http.GET
1414
import retrofit2.http.Path
15-
import java.util.Base64
15+
import java.util.*
1616

1717
interface GitHubService {
18+
1819
@GET("orgs/{org}/repos?per_page=100")
1920
fun getOrgReposCall(
20-
@Path("org") org: String
21+
@Path("org") org: String,
2122
): Call<List<Repo>>
2223

2324
@GET("repos/{owner}/{repo}/contributors?per_page=100")
2425
fun getRepoContributorsCall(
2526
@Path("owner") owner: String,
26-
@Path("repo") repo: String
27+
@Path("repo") repo: String,
2728
): Call<List<User>>
29+
30+
@GET("orgs/{org}/repos?per_page=100")
31+
suspend fun getOrgRepos(
32+
@Path("org") org: String,
33+
): Response<List<Repo>>
34+
35+
@GET("repos/{owner}/{repo}/contributors?per_page=100")
36+
suspend fun getRepoContributors(
37+
@Path("owner") owner: String,
38+
@Path("repo") repo: String,
39+
): Response<List<User>>
2840
}
2941

3042
@Serializable
3143
data class Repo(
3244
val id: Long,
33-
val name: String
45+
val name: String,
3446
)
3547

3648
@Serializable
3749
data class User(
3850
val login: String,
39-
val contributions: Int
51+
val contributions: Int,
4052
)
4153

4254
@Serializable
4355
data class RequestData(
4456
val username: String,
4557
val password: String,
46-
val org: String
58+
val org: String,
4759
)
4860

4961
@OptIn(ExperimentalSerializationApi::class)

src/contributors/main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package contributors
22

33
fun main() {
4-
setDefaultFontSize(16f)
4+
setDefaultFontSize(14f)
55
ContributorsUI().apply {
66
pack()
77
setLocationRelativeTo(null)

src/tasks/Request4Suspend.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@ package tasks
33
import contributors.*
44

55
suspend fun loadContributorsSuspend(service: GitHubService, req: RequestData): List<User> {
6-
TODO()
6+
val repos = service
7+
.getOrgRepos(req.org)
8+
.also { logRepos(req, it) }
9+
.body() ?: emptyList()
10+
return repos.flatMap { repo ->
11+
service.getRepoContributors(req.org, repo.name).also { logUsers(repo, it) }.body() ?: emptyList()
12+
}.aggregate()
713
}

0 commit comments

Comments
 (0)