github api 使用
Github 支持通过 github api 操作创建 issues 等操作。
有一个开源库 https://github-api.kohsuke.org/ 做了封装,可以通过 Java api 方式直接调用。文章来源:https://www.toymoban.com/news/detail-558472.html
Maven 依赖
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.314</version>
</dependency>
Demo
每个issue发完建议sleep一两秒,太快会被限流。文章来源地址https://www.toymoban.com/news/detail-558472.html
org.kohsuke.github.HttpException: {"message":"You have exceeded a secondary rate limit and have been temporarily blocked from content creation. Please retry your request again later.","documentation_url":"https://docs.github.com/rest/overview/resources-in-the-rest-api#secondary-rate-limits"}
public static final String repositoryOwner = "apache"; // 仓库所有者
public static final String repositoryName = "xx"; // 仓库名称
// 客户端认证
public static final GitHub github;
static {
try {
// TODO 这个地方需要去github上申请自己的 token 填进去即可
github = new GitHubBuilder().withOAuthToken("").build();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Test
public void testCreateOneIssue() throws Exception {
// 获取指定仓库
GHRepository repository = github.getRepository(repositoryOwner + "/" + repositoryName);
// 可以通过 Map<Integer, GHMilestone> ms = repository.getMilestones();
GHMilestone milestone = repository.getMilestone(27);
// Issue标题
String title = "Your title";
// Issue内容
String body = "Your issue body";
createOneIssue(repository, milestone, title, body);
}
private static void createOneIssue(GHRepository repository, GHMilestone milestone, String title, String body) throws IOException {
// 创建一个新的Issue
GHIssue issue = repository.createIssue(title)
.body(body)
// 指定 milestone
.milestone(milestone)
// 指定多个tags
.label("db: Oracle")
.label("in: SQL parse")
.label("type: enhancement")
.label("good first issue")
.create();
// 输出Issue的URL
System.out.println(issue.getHtmlUrl());
}
到了这里,关于使用 github api 批量创建 issues的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!