Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions composeApp/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,8 @@
<string name="followers_following_format">%1$d followers · %2$d following</string>
<string name="cd_github_logo">GitHub Logo</string>
<string name="app_name_display">GitHub</string>


<string name="explore_action_contributed">contributed to %1$s</string>
<string name="explore_action_published">published a release</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,43 @@ data class NotificationRepo(
@SerialName("full_name") val fullName: String
)

@Serializable
data class SearchResult<T>(val items: List<T>)

@Serializable
data class GitHubEvent(
val id: String,
val type: String,
val actor: GitHubActor,
val repo: EventRepo,
val payload: EventPayload? = null,
@SerialName("created_at") val createdAt: String
)

@Serializable
data class GitHubActor(val login: String, @SerialName("avatar_url") val avatarUrl: String)

@Serializable
data class EventRepo(val name: String)

@Serializable
data class EventPayload(
val action: String? = null,
@SerialName("pull_request") val pullRequest: EventPullRequest? = null,
val release: EventRelease? = null
)

@Serializable
data class EventPullRequest(
val title: String, val body: String? = null, val state: String, val head: EventHead
)

@Serializable
data class EventHead(val ref: String)

@Serializable
data class EventRelease(val name: String? = null, @SerialName("tag_name") val tagName: String)

class GitHubApiClient(private val tokenStorage: TokenStorage) {

private val client = HttpClient {
Expand Down Expand Up @@ -134,5 +171,22 @@ class GitHubApiClient(private val tokenStorage: TokenStorage) {
)
}

suspend fun getTrendingRepos(): Result<SearchResult<GitHubRepo>> = runCatching {
client.get("https://api.github.com/search/repositories") {
withAuth()
parameter("q", "stars:>1000")
parameter("sort", "stars")
parameter("order", "desc")
parameter("per_page", 10)
}.body()
}

suspend fun getReceivedEvents(username: String, perPage: Int = 20): Result<List<GitHubEvent>> = runCatching {
client.get("https://api.github.com/users/${username}/received_events") {
withAuth()
parameter("per_page", perPage)
}.body()
}

fun close() = client.close()
}
Loading
Loading