├── gradle.properties ├── settings.gradle.kts ├── src ├── test │ ├── resources │ │ └── META-INF │ │ │ └── services │ │ │ └── org.slf4j.spi.SLF4JServiceProvider │ └── kotlin │ │ └── io │ │ └── github │ │ └── gnuf0rce │ │ ├── github │ │ └── GitHubClientTest.kt │ │ └── mirai │ │ └── github │ │ ├── GitHubSubscriberTest.kt │ │ ├── GitHubOwnerTest.kt │ │ ├── GitHubReleasePluginUpdaterTest.kt │ │ ├── GitHubCurrentTest.kt │ │ └── GitHubRepoTest.kt └── main │ ├── resources │ └── META-INF │ │ └── services │ │ ├── net.mamoe.mirai.console.data.PluginConfig │ │ ├── net.mamoe.mirai.console.plugin.jvm.JvmPlugin │ │ ├── xyz.cssxsh.mirai.spi.ComparableService │ │ ├── net.mamoe.mirai.console.data.PluginData │ │ └── net.mamoe.mirai.console.command.Command │ └── kotlin │ └── io │ └── github │ └── gnuf0rce │ ├── github │ ├── entry │ │ ├── RepoSecurityAndAnalysis.kt │ │ ├── Query.kt │ │ ├── Link.kt │ │ ├── ActionsArtifacts.kt │ │ ├── Event.kt │ │ ├── AutoLink.kt │ │ ├── IssueBody.kt │ │ ├── GitUser.kt │ │ ├── License.kt │ │ ├── Label.kt │ │ ├── CommentQuery.kt │ │ ├── RateLimit.kt │ │ ├── ApiError.kt │ │ ├── Comment.kt │ │ ├── Owner.kt │ │ ├── PullQuery.kt │ │ ├── IssueQuery.kt │ │ ├── Team.kt │ │ ├── ControlRecord.kt │ │ ├── Reactions.kt │ │ ├── Context.kt │ │ ├── IssueComment.kt │ │ ├── CommitComment.kt │ │ ├── Readme.kt │ │ ├── Enum.kt │ │ ├── Milestone.kt │ │ ├── GithubAppInfo.kt │ │ ├── Bot.kt │ │ ├── ActionsArtifact.kt │ │ ├── PullRequestReviewComment.kt │ │ ├── Organization.kt │ │ ├── User.kt │ │ ├── Issue.kt │ │ ├── IssueEvent.kt │ │ ├── Release.kt │ │ ├── Commit.kt │ │ └── Pull.kt │ ├── model │ │ ├── GitHubMapper.kt │ │ ├── ContentsMapper.kt │ │ ├── OrganizationMapper.kt │ │ ├── MilestonesMapper.kt │ │ ├── AutoLinksMapper.kt │ │ ├── UserMapper.kt │ │ ├── BranchesMapper.kt │ │ ├── ActionMapper.kt │ │ ├── BranchProtectionMapper.kt │ │ ├── CurrentMapper.kt │ │ ├── ReleasesMapper.kt │ │ ├── CommitMapper.kt │ │ ├── PullsMapper.kt │ │ ├── IssuesMapper.kt │ │ ├── WithGithubClient.kt │ │ └── ReposMapper.kt │ ├── GitHubCurrent.kt │ ├── GitHubUser.kt │ ├── GitHubRepo.kt │ ├── GitHubOrganization.kt │ ├── exception │ │ └── GitHubApiException.kt │ ├── ContentType.kt │ ├── Parser.kt │ ├── OkHttpDnsOverHttps.kt │ ├── Utils.kt │ ├── RateLimitFeature.kt │ └── GitHubClient.kt │ └── mirai │ └── github │ ├── command │ ├── GitHubContext.kt │ ├── GitHubUpdateCommand.kt │ ├── GitHubReadmeCommand.kt │ ├── GitHubRepoPullCommand.kt │ ├── GitHubStatsCommand.kt │ ├── GitHubIssuesCommand.kt │ ├── GitHubRepoIssueCommand.kt │ ├── GitHubRepoReleaseCommand.kt │ ├── GitHubRepoArtifactCommand.kt │ └── GitHubRepoCommitCommand.kt │ ├── data │ ├── GitHubTaskData.kt │ ├── GitHubTask.kt │ ├── GitHubRepoTaskData.kt │ └── GitHubConfig.kt │ ├── GitHubHelperPlugin.kt │ ├── spi │ └── GithubMemberApproverService.kt │ ├── GitHubUitls.kt │ ├── GitHubSubscriber.kt │ └── GitHubReleasePluginUpdater.kt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .github └── workflows │ └── test.yml ├── .gitignore ├── gradlew.bat ├── README.md └── gradlew /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "github-helper" -------------------------------------------------------------------------------- /src/test/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider: -------------------------------------------------------------------------------- 1 | org.slf4j.simple.SimpleServiceProvider -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnuf0rce/github-helper/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/net.mamoe.mirai.console.data.PluginConfig: -------------------------------------------------------------------------------- 1 | io.github.gnuf0rce.mirai.github.data.GitHubConfig -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin: -------------------------------------------------------------------------------- 1 | io.github.gnuf0rce.mirai.github.GitHubHelperPlugin -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/xyz.cssxsh.mirai.spi.ComparableService: -------------------------------------------------------------------------------- 1 | io.github.gnuf0rce.mirai.github.spi.GithubMemberApproverService -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/net.mamoe.mirai.console.data.PluginData: -------------------------------------------------------------------------------- 1 | io.github.gnuf0rce.mirai.github.data.GitHubTaskData 2 | io.github.gnuf0rce.mirai.github.data.GitHubTaskData -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/RepoSecurityAndAnalysis.kt: -------------------------------------------------------------------------------- 1 | package io.github.gnuf0rce.github.entry 2 | 3 | import kotlinx.serialization.* 4 | 5 | @Serializable 6 | public data class RepoSecurityAndAnalysis( 7 | @Serializable 8 | public val status: String 9 | ) -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/Query.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.json.* 14 | 15 | public interface Query { 16 | 17 | public fun toJsonObject(): JsonObject 18 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/Link.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | 15 | @Serializable 16 | public data class Link( 17 | @SerialName("href") 18 | val href: String 19 | ) -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/net.mamoe.mirai.console.command.Command: -------------------------------------------------------------------------------- 1 | io.github.gnuf0rce.mirai.github.command.GitHubIssuesCommand 2 | io.github.gnuf0rce.mirai.github.command.GitHubReadmeCommand 3 | io.github.gnuf0rce.mirai.github.command.GitHubRepoCommitCommand 4 | io.github.gnuf0rce.mirai.github.command.GitHubRepoIssueCommand 5 | io.github.gnuf0rce.mirai.github.command.GitHubRepoPullCommand 6 | io.github.gnuf0rce.mirai.github.command.GitHubRepoReleaseCommand 7 | io.github.gnuf0rce.mirai.github.command.GitHubRepoArtifactCommand 8 | io.github.gnuf0rce.mirai.github.command.GitHubStatsCommand 9 | io.github.gnuf0rce.mirai.github.command.GitHubUpdateCommand -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/mirai/github/command/GitHubContext.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.mirai.github.command 12 | 13 | import net.mamoe.mirai.console.command.* 14 | 15 | internal fun CommandSender.context() = subject ?: throw IllegalCommandArgumentException("无法从当前环境获取联系人") -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/model/GitHubMapper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.model 12 | 13 | import io.ktor.http.* 14 | 15 | public sealed class GitHubMapper(parent: Url, path: String) : WithGithubClient { 16 | final override val base: Url = parent.resolve(path) 17 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/GitHubCurrent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github 12 | 13 | import io.github.gnuf0rce.github.model.* 14 | 15 | /** 16 | * @see [CurrentMapper] 17 | */ 18 | public class GitHubCurrent(override val github: GitHubClient = GitHubClient()) : 19 | WithGithubClient, CurrentMapper(parent = api()) -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/mirai/github/data/GitHubTaskData.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.mirai.github.data 12 | 13 | import net.mamoe.mirai.console.data.* 14 | 15 | public object GitHubTaskData : AutoSavePluginData(saveName = "TaskData") { 16 | @ValueName("issues") 17 | public val issues: MutableMap by value() 18 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/GitHubUser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github 12 | 13 | import io.github.gnuf0rce.github.model.* 14 | 15 | /** 16 | * @see [UserMapper] 17 | */ 18 | public class GitHubUser(user: String, override val github: GitHubClient = GitHubClient()) : 19 | WithGithubClient, UserMapper(parent = api("users"), user = user) -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/ActionsArtifacts.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | 15 | @Serializable 16 | public data class ActionsArtifacts( 17 | @SerialName("artifacts") 18 | val artifacts: List, 19 | @SerialName("total_count") 20 | val total: Int 21 | ) -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/GitHubRepo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github 12 | 13 | import io.github.gnuf0rce.github.model.* 14 | 15 | /** 16 | * @see [ReposMapper] 17 | */ 18 | public class GitHubRepo(owner: String, repo: String, override val github: GitHubClient) : 19 | WithGithubClient, ReposMapper(parent = api("repos"), owner = owner, repo = repo) -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/Event.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2023 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | 15 | @Serializable 16 | public sealed class Event : Entry, LifeCycle, Product { 17 | public abstract val actor: Owner? 18 | public abstract val event: String 19 | 20 | override val owner: Owner? 21 | get() = actor 22 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/GitHubOrganization.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github 12 | 13 | import io.github.gnuf0rce.github.model.* 14 | 15 | /** 16 | * @see [OrganizationMapper] 17 | */ 18 | public class GitHubOrganization(org: String, override val github: GitHubClient = GitHubClient()) : 19 | WithGithubClient, OrganizationMapper(parent = api("orgs"), org = org) -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/AutoLink.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | 15 | @Serializable 16 | public data class AutoLink( 17 | @SerialName("id") 18 | val id: Long = 0, 19 | @SerialName("key_prefix") 20 | val keyPrefix: String, 21 | @SerialName("url_template") 22 | val urlTemplate: String 23 | ) -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/IssueBody.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | 15 | @Serializable 16 | public data class IssueBody( 17 | var title: String? = null, 18 | var body: String? = null, 19 | var milestone: String? = null, 20 | var labels: List? = null, 21 | var assignees: List? = null 22 | ) 23 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/GitUser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | import java.time.* 15 | 16 | @Serializable 17 | public data class GitUser( 18 | @Contextual 19 | @SerialName("date") 20 | val date: OffsetDateTime, 21 | @SerialName("email") 22 | val email: String, 23 | @SerialName("name") 24 | val name: String 25 | ) -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/exception/GitHubApiException.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.exception 12 | 13 | import io.github.gnuf0rce.github.entry.* 14 | import io.ktor.client.plugins.* 15 | 16 | public class GitHubApiException(override val cause: ResponseException, public val json: ApiError) : 17 | IllegalStateException(cause) { 18 | 19 | override val message: String get() = json.message 20 | } -------------------------------------------------------------------------------- /src/test/kotlin/io/github/gnuf0rce/github/GitHubClientTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.gnuf0rce.github 2 | 3 | import io.ktor.utils.io.errors.* 4 | import org.slf4j.* 5 | 6 | internal abstract class GitHubClientTest { 7 | protected val logger: Logger = LoggerFactory.getLogger(this::class.java) 8 | 9 | protected val github = object : GitHubClient(token = System.getenv("GITHUB_TOKEN")) { 10 | override val maxIgnoreCount: Int = 30 11 | override val ignore: (Throwable) -> Boolean = { cause -> 12 | when (cause) { 13 | is IOException -> { 14 | logger.warn("GitHub Client IOException", cause) 15 | true 16 | } 17 | else -> { 18 | false 19 | } 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/ContentType.kt: -------------------------------------------------------------------------------- 1 | package io.github.gnuf0rce.github 2 | 3 | import io.ktor.http.* 4 | import kotlin.reflect.jvm.* 5 | 6 | internal fun Headers.fixContentType() { 7 | val type = when (get(HttpHeaders.ContentType)) { 8 | "zip" -> ContentType.Application.Zip 9 | else -> return 10 | } 11 | when (this::class.java.packageName) { 12 | """io.ktor.client.engine.okhttp""" -> { 13 | val impl = this::class.java.getDeclaredField("\$this_fromOkHttp") 14 | impl.isAccessible = true 15 | val value = (impl.get(this) as okhttp3.Headers) 16 | .newBuilder() 17 | .set(HttpHeaders.ContentType, type.toString()) 18 | .build() 19 | impl.set(this, value) 20 | } 21 | else -> throw UnsupportedOperationException("Unsupported headers type ${this::class.jvmName}") 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/License.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | 15 | @Serializable 16 | @SerialName("License") 17 | public data class License( 18 | @SerialName("html_url") 19 | override val htmlUrl: String = "", 20 | @SerialName("key") 21 | val key: String, 22 | @SerialName("name") 23 | val name: String, 24 | @SerialName("node_id") 25 | override val nodeId: String, 26 | @SerialName("spdx_id") 27 | val spdxId: String?, 28 | @SerialName("url") 29 | override val url: String? 30 | ) : Entry, WebPage -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/Label.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | 15 | // TODO: 可能是字符串 16 | @Serializable 17 | public data class Label( 18 | @SerialName("color") 19 | val color: String?, 20 | @SerialName("default") 21 | val default: Boolean, 22 | @SerialName("description") 23 | val description: String?, 24 | @SerialName("id") 25 | val id: Long, 26 | @SerialName("name") 27 | val name: String, 28 | @SerialName("node_id") 29 | override val nodeId: String, 30 | @SerialName("url") 31 | override val url: String 32 | ) : Entry -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/mirai/github/command/GitHubUpdateCommand.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.mirai.github.command 12 | 13 | import io.github.gnuf0rce.mirai.github.* 14 | import net.mamoe.mirai.console.command.* 15 | 16 | public object GitHubUpdateCommand : SimpleCommand( 17 | owner = GitHubHelperPlugin, 18 | primaryName = "update", 19 | description = "Update Plugin of GitHub Release" 20 | ) { 21 | @Handler 22 | public fun ConsoleCommandSender.handle() { 23 | try { 24 | GitHubReleasePluginUpdater.update() 25 | } catch (cause: Throwable) { 26 | logger.warning(name, cause) 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/model/ContentsMapper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.model 12 | 13 | import io.github.gnuf0rce.github.* 14 | import io.ktor.http.* 15 | 16 | /** 17 | * [Repository contents](https://docs.github.com/en/rest/repos/contents) 18 | */ 19 | public open class ContentsMapper(parent: Url, path: String) : 20 | GitHubMapper(parent = parent, path = path) { 21 | 22 | override val github: GitHubClient = GitHubClient() 23 | 24 | public open suspend fun load(): Temp = get() 25 | 26 | public open suspend fun update(content: Temp): Temp = put(context = content) 27 | 28 | public open suspend fun delete(): Unit = delete() 29 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/model/OrganizationMapper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2023 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.model 12 | 13 | import io.github.gnuf0rce.github.* 14 | import io.github.gnuf0rce.github.entry.* 15 | import io.ktor.http.* 16 | 17 | /** 18 | * [Organizations](https://docs.github.com/en/rest/orgs) 19 | */ 20 | public open class OrganizationMapper(parent: Url, public val org: String) : 21 | GitHubMapper(parent = parent, path = org) { 22 | 23 | override val github: GitHubClient = GitHubClient() 24 | 25 | public open suspend fun load(): Owner = get() 26 | 27 | public open suspend fun repos(page: Int, per: Int = 30): List = page(page = page, per = per, path = "repos") 28 | } 29 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/CommentQuery.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import io.github.gnuf0rce.github.* 14 | import kotlinx.serialization.* 15 | import kotlinx.serialization.json.* 16 | import java.time.* 17 | 18 | @Serializable 19 | public data class CommentQuery( 20 | @SerialName("sort") 21 | var sort: ElementSort = ElementSort.created, 22 | @SerialName("direction") 23 | var direction: Direction = Direction.desc, 24 | @Contextual 25 | @SerialName("since") 26 | var since: OffsetDateTime? = null 27 | ) : Query { 28 | 29 | override fun toJsonObject(): JsonObject { 30 | return GitHubJson.encodeToJsonElement(serializer(), this) as JsonObject 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/mirai/github/data/GitHubTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.mirai.github.data 12 | 13 | import io.github.gnuf0rce.github.* 14 | import io.github.gnuf0rce.mirai.github.* 15 | import kotlinx.serialization.* 16 | import java.time.* 17 | 18 | @Serializable 19 | public data class GitHubTask( 20 | @SerialName("id") 21 | val id: String, 22 | @SerialName("contacts") 23 | val contacts: MutableSet = HashSet(), 24 | @SerialName("last") 25 | @Serializable(OffsetDateTimeSerializer::class) 26 | var last: OffsetDateTime = OffsetDateTime.now(), 27 | @SerialName("interval") 28 | var interval: Long = 600_000L, 29 | @SerialName("format") 30 | var format: Format = Format.TEXT 31 | ) 32 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/RateLimit.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | 15 | @Serializable 16 | public data class RateLimit( 17 | @SerialName("rate") 18 | val rate: Status, 19 | @SerialName("resources") 20 | val resources: Map = emptyMap() 21 | ) { 22 | 23 | @Serializable 24 | public data class Status( 25 | @SerialName("limit") 26 | val limit: Int, 27 | @SerialName("remaining") 28 | val remaining: Int, 29 | @SerialName("reset") 30 | val reset: Long, 31 | @SerialName("resource") 32 | val resource: String? = null, 33 | @SerialName("used") 34 | val used: Int 35 | ) 36 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/ApiError.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | 15 | @Serializable 16 | public data class ApiError( 17 | @SerialName("documentation_url") 18 | val documentationUrl: String?, 19 | @SerialName("message") 20 | val message: String = "", 21 | @SerialName("status") 22 | val status: String = "", 23 | @SerialName("errors") 24 | val errors: List = emptyList() 25 | ) { 26 | @Serializable 27 | public data class Detail( 28 | @SerialName("resource") 29 | val resource: String, 30 | @SerialName("field") 31 | val field: String, 32 | @SerialName("code") 33 | val code: String 34 | ) 35 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/Comment.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2023 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | import java.time.* 15 | 16 | @Serializable 17 | public sealed class Comment : Entry, LifeCycle, WebPage, Content, Product { 18 | public abstract val association: Association 19 | abstract override val body: String 20 | abstract override val text: String 21 | abstract override val html: String 22 | abstract override val url: String 23 | 24 | @Deprecated("Comment No Closed", ReplaceWith("null")) 25 | override val closedAt: OffsetDateTime? 26 | get() = null 27 | 28 | @Deprecated("Comment No Merged", ReplaceWith("null")) 29 | override val mergedAt: OffsetDateTime? 30 | get() = null 31 | } -------------------------------------------------------------------------------- /src/test/kotlin/io/github/gnuf0rce/mirai/github/GitHubSubscriberTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.gnuf0rce.mirai.github 2 | 3 | import io.github.gnuf0rce.github.* 4 | import io.github.gnuf0rce.github.entry.* 5 | import kotlinx.coroutines.* 6 | import net.mamoe.mirai.mock.* 7 | import org.junit.jupiter.api.* 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | internal abstract class GitHubSubscriberTest : GitHubClientTest() 11 | where T : LifeCycle, T : WebPage { 12 | 13 | init { 14 | System.setProperty(IMAGE_FOLDER_PROPERTY, "./run/image") 15 | System.setProperty(CACHE_FOLDER_PROPERTY, "./run/cache") 16 | } 17 | 18 | protected val bot = MockBotFactory.newMockBotBuilder().create() 19 | 20 | protected val group = bot.addGroup(114514, "mock") 21 | 22 | protected val sender = group.addMember(1919810, "...") 23 | 24 | protected abstract val subscriber: GitHubSubscriber 25 | 26 | @Test 27 | open fun subscribe(): Unit = runBlocking { 28 | subscriber.start() 29 | delay(15 * 1000L) 30 | } 31 | 32 | @AfterAll 33 | fun stop() { 34 | subscriber.stop() 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/mirai/github/data/GitHubRepoTaskData.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.mirai.github.data 12 | 13 | import net.mamoe.mirai.console.data.* 14 | 15 | public object GitHubRepoTaskData : AutoSavePluginData(saveName = "RepoTaskData") { 16 | @ValueName("commits") 17 | public val commits: MutableMap by value() 18 | 19 | @ValueName("issues") 20 | public val issues: MutableMap by value() 21 | 22 | @ValueName("pulls") 23 | public val pulls: MutableMap by value() 24 | 25 | @ValueName("releases") 26 | public val releases: MutableMap by value() 27 | 28 | @ValueName("artifacts") 29 | public val artifacts: MutableMap by value() 30 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/Owner.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | import java.time.* 15 | 16 | @Serializable 17 | public sealed class Owner : Entry, LifeCycle, WebPage { 18 | public abstract val avatarUrl: String 19 | public abstract val eventsUrl: String 20 | public abstract val reposUrl: String 21 | public abstract val id: Long 22 | public abstract val login: String 23 | public abstract val name: String? 24 | public abstract val type: String 25 | public abstract val userViewType: Visibility 26 | public open val nameOrLogin: String get() = name ?: login 27 | 28 | @Deprecated("Owner No Merged", ReplaceWith("null")) 29 | override val mergedAt: OffsetDateTime? 30 | get() = null 31 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/PullQuery.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import io.github.gnuf0rce.github.* 14 | import kotlinx.serialization.* 15 | import kotlinx.serialization.json.* 16 | 17 | @Serializable 18 | public data class PullQuery( 19 | @SerialName("state") 20 | var state: StateFilter = StateFilter.open, 21 | @SerialName("head") 22 | var head: String = "", 23 | @SerialName("base") 24 | var base: String = "", 25 | @SerialName("sort") 26 | var sort: ElementSort = ElementSort.created, 27 | @SerialName("direction") 28 | var direction: Direction = Direction.desc 29 | ) : Query { 30 | override fun toJsonObject(): JsonObject { 31 | return GitHubJson.encodeToJsonElement(serializer(), this) as JsonObject 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/model/MilestonesMapper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.model 12 | 13 | import io.github.gnuf0rce.github.* 14 | import io.github.gnuf0rce.github.entry.* 15 | import io.ktor.http.* 16 | 17 | /** 18 | * [Milestones](https://docs.github.com/en/rest/issues/milestones) 19 | */ 20 | public open class MilestonesMapper(parent: Url) : 21 | GitHubMapper(parent = parent, path = "milestones") { 22 | 23 | override val github: GitHubClient = GitHubClient() 24 | 25 | public open suspend fun list(page: Int, per: Int = 30, context: Temp? = null): List = 26 | page(page = page, per = per, context = context) 27 | 28 | public open suspend fun new(context: Temp): Milestone = post(context = context) 29 | 30 | public open suspend fun get(index: Int): Milestone = get(path = "$index") 31 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/model/AutoLinksMapper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.model 12 | 13 | import io.github.gnuf0rce.github.* 14 | import io.github.gnuf0rce.github.entry.* 15 | import io.ktor.http.* 16 | 17 | /** 18 | * [Repository autolinks](https://docs.github.com/en/rest/repos/autolinks) 19 | */ 20 | public open class AutoLinksMapper(parent: Url) : 21 | GitHubMapper(parent = parent, path = "autolinks") { 22 | 23 | override val github: GitHubClient = GitHubClient() 24 | 25 | public open suspend fun list(page: Int, per: Int = 30): List = page(page = page, per = per) 26 | 27 | public open suspend fun new(link: AutoLink): AutoLink = post(context = link) 28 | 29 | public open suspend fun get(id: Long): AutoLink = get(path = "$id") 30 | 31 | public open suspend fun delete(id: Long): Unit = delete(path = "$id") 32 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/Parser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github 12 | 13 | internal val FULL_REGEX = """([\w-.]+)/([\w-.]+)""".toRegex() 14 | 15 | public fun GitHubClient.repo(owner: String, repo: String): GitHubRepo = GitHubRepo( 16 | owner = owner, 17 | repo = repo, 18 | github = this 19 | ) 20 | 21 | public fun GitHubClient.repo(full: String): GitHubRepo { 22 | val (owner, repo) = requireNotNull(FULL_REGEX.find(full)) { "Not Found FullName." }.destructured 23 | return GitHubRepo(owner = owner, repo = repo, github = this) 24 | } 25 | 26 | public fun GitHubClient.user(login: String): GitHubUser = GitHubUser(user = login, github = this) 27 | 28 | public fun GitHubClient.organization(login: String): GitHubOrganization = GitHubOrganization(org = login, github = this) 29 | 30 | public fun GitHubClient.current(): GitHubCurrent = GitHubCurrent(github = this) -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/IssueQuery.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import io.github.gnuf0rce.github.* 14 | import kotlinx.serialization.* 15 | import kotlinx.serialization.json.* 16 | import java.time.* 17 | 18 | @Serializable 19 | public data class IssueQuery( 20 | @SerialName("filter") 21 | var filter: IssueFilter = IssueFilter.assigned, 22 | @SerialName("state") 23 | var state: StateFilter = StateFilter.open, 24 | @SerialName("sort") 25 | var sort: ElementSort = ElementSort.created, 26 | @SerialName("direction") 27 | var direction: Direction = Direction.desc, 28 | @Contextual 29 | @SerialName("since") 30 | var since: OffsetDateTime? = null 31 | ) : Query { 32 | override fun toJsonObject(): JsonObject { 33 | return GitHubJson.encodeToJsonElement(serializer(), this) as JsonObject 34 | } 35 | } -------------------------------------------------------------------------------- /src/test/kotlin/io/github/gnuf0rce/mirai/github/GitHubOwnerTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.gnuf0rce.mirai.github 2 | 3 | import io.github.gnuf0rce.github.* 4 | import kotlinx.coroutines.* 5 | import org.junit.jupiter.api.* 6 | 7 | internal class GitHubOwnerTest : GitHubClientTest() { 8 | 9 | init { 10 | System.setProperty(IMAGE_FOLDER_PROPERTY, "./run/image") 11 | System.setProperty(CACHE_FOLDER_PROPERTY, "./run/cache") 12 | } 13 | 14 | @Test 15 | fun user(): Unit = runBlocking { 16 | val user = github.user(login = "cssxsh").load() 17 | Assertions.assertEquals("cssxsh", user.login) 18 | val page = github.user(login = "cssxsh").repos(page = 1) 19 | Assertions.assertEquals(user.login, page.firstOrNull()?.owner?.login) 20 | Assertions.assertEquals(30, page.size) 21 | } 22 | 23 | 24 | @Test 25 | fun organization(): Unit = runBlocking { 26 | val organization = github.organization(login = "iTXTech").load() 27 | Assertions.assertEquals("iTXTech", organization.login) 28 | val page = github.user(login = "iTXTech").repos(page = 1) 29 | Assertions.assertEquals(organization.login, page.firstOrNull()?.owner?.login) 30 | Assertions.assertEquals(30, page.size) 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/OkHttpDnsOverHttps.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2023 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github 12 | 13 | import okhttp3.Dns 14 | import okhttp3.HttpUrl.Companion.toHttpUrl 15 | import okhttp3.OkHttpClient 16 | import okhttp3.dnsoverhttps.DnsOverHttps 17 | import java.net.* 18 | 19 | internal fun OkHttpClient.Builder.doh(urlString: String, ipv6: Boolean) { 20 | if (urlString.isEmpty()) return 21 | dns(dns = object : Dns { 22 | val doh = DnsOverHttps.Builder() 23 | .client(OkHttpClient()) 24 | .url(urlString.toHttpUrl()) 25 | .includeIPv6(ipv6) 26 | .build() 27 | override fun lookup(hostname: String): List { 28 | return try { 29 | doh.lookup(hostname) 30 | } catch (_: UnknownHostException) { 31 | Dns.SYSTEM.lookup(hostname) 32 | } 33 | } 34 | }) 35 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/mirai/github/command/GitHubReadmeCommand.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2024 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.mirai.github.command 12 | 13 | import io.github.gnuf0rce.mirai.github.* 14 | import net.mamoe.mirai.console.command.* 15 | import net.mamoe.mirai.message.data.* 16 | import net.mamoe.mirai.utils.warning 17 | 18 | public object GitHubReadmeCommand : SimpleCommand( 19 | owner = GitHubHelperPlugin, 20 | primaryName = "readme", 21 | description = "Readme Download" 22 | ) { 23 | 24 | @Handler 25 | public suspend fun UserCommandSender.handle(name: String) { 26 | val message = try { 27 | repo(if ('/' in name) name else "${name}/${name}").readme().toMessage(subject) 28 | } catch (cause: Exception) { 29 | logger.warning({ "readme with $name 获取失败" }, cause) 30 | "readme with $name 获取失败".toPlainText() 31 | } 32 | 33 | sendMessage(message) 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/Team.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | 15 | @Serializable 16 | @SerialName("Team") 17 | public data class Team( 18 | @SerialName("description") 19 | val description: String?, 20 | @SerialName("html_url") 21 | override val htmlUrl: String, 22 | @SerialName("id") 23 | val id: Long, 24 | @SerialName("members_url") 25 | val membersUrl: String, 26 | @SerialName("name") 27 | val name: String, 28 | @SerialName("node_id") 29 | override val nodeId: String, 30 | @SerialName("parent") 31 | val parent: Team?, 32 | @SerialName("permission") 33 | val permission: String, 34 | @SerialName("privacy") 35 | val privacy: Privacy, 36 | @SerialName("repositories_url") 37 | val repositoriesUrl: String, 38 | @SerialName("slug") 39 | val slug: String, 40 | @SerialName("url") 41 | override val url: String 42 | ) : Entry, WebPage -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/model/UserMapper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2023 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.model 12 | 13 | import io.github.gnuf0rce.github.* 14 | import io.github.gnuf0rce.github.entry.* 15 | import io.ktor.http.* 16 | 17 | /** 18 | * [Users](https://docs.github.com/en/rest/users) 19 | */ 20 | public open class UserMapper(parent: Url, public val user: String) : 21 | GitHubMapper(parent = parent, path = user) { 22 | 23 | override val github: GitHubClient = GitHubClient() 24 | 25 | // region Users 26 | 27 | /** 28 | * [about-the-users-api](https://docs.github.com/en/rest/users/users#about-the-users-api) 29 | */ 30 | public open suspend fun load(): Owner = get() 31 | 32 | /** 33 | * [list-repositories-for-a-user](https://docs.github.com/en/rest/repos/repos#list-repositories-for-a-user) 34 | */ 35 | public open suspend fun repos(page: Int, per: Int = 30): List = page(page = page, per = per, path = "repos") 36 | 37 | // endregion 38 | } 39 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/gnuf0rce/github/entry/ControlRecord.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2023 dsstudio Technologies and contributors. 3 | * 4 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 5 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 6 | * 7 | * https://github.com/gnuf0rce/github-helper/blob/master/LICENSE 8 | */ 9 | 10 | 11 | package io.github.gnuf0rce.github.entry 12 | 13 | import kotlinx.serialization.* 14 | 15 | /** 16 | * @see Pull 17 | * @see Issue 18 | */ 19 | @Serializable 20 | public sealed class ControlRecord : Entry, LifeCycle, WebPage, Content, Product { 21 | public abstract val title: String 22 | public abstract override val owner: Owner? 23 | public abstract val assignee: Owner? 24 | public abstract val assignees: List 25 | public abstract val closedBy: Owner? 26 | public abstract val mergedBy: Owner? 27 | public abstract val state: State 28 | public abstract val number: Int 29 | public abstract val labels: List