【问题标题】:Create issue over github using java使用 java 在 github 上创建问题
【发布时间】:2015-08-20 08:06:34
【问题描述】:

我想使用 java EGIT API 在 GitHub 上创建问题。

我试过了:

GitHubClient client = new GitHubClient().setCredentials("abc", "xyz");

IssueService service = new IssueService(client);

Repository repo = new Repository();

【问题讨论】:

  • 我认为此功能对于应用程序中的错误报告非常有用。太糟糕了,您需要一个帐户才能做到这一点。

标签: java github egit issue-tracking


【解决方案1】:

我能够使用EGit 2.1.5 实现这一目标。以下是我采取的步骤:

  1. 我在项目https://github.com/settings/tokens 中创建了个人访问令牌。创建令牌时,根据您的需要指定scope。对于我的情况(只是创建问题),我选择了repo scope

亲爱的,现在我们有了token,让我们跳入代码。

GitHubClient client = new GitHubClient();
client.setOAuth2Token("PUT_YOUR_PERSONAL_ACCESS_TOKEN_HERE"); // Use the token generated above
IssueService issueService = new IssueService(client);
try {
    Issue issue = new Issue();
    issue.setTitle("Test issue"); // Title of the issue
    issue.setBody("Some stuff"); // Body of the issue
    // Other stuff can be included in the Issue as you'd expect .. like labels, authors, dates, etc. 
    // Check out the API per your needs
    
    // In my case, we utilize a private issue-only-repository "RepositoryIssueTracker" that is maintainted under our Organization "MyCompany"
    issueService.createIssue("MyCompany", "RepositoryIssueTracker", issue);
} catch (Exception e) {
    System.out.println("Failed");
    e.printStackTrace();
}

总结: 我认为 OP 的问题与未提供适当的凭据有关,可能与私人回购有关。我也无法让Basic auth 使用我们私人仓库的用户名/密码(可能是因为我们的组织需要 2 因素)。相反,按照上述说明使用Personal Access Token 授权。

有关创建仅问题存储库的更多信息,请访问here

【讨论】:

    猜你喜欢
    • 2020-10-17
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    • 1970-01-01
    相关资源
    最近更新 更多