使用 java 在 github 上创建问题

Ano*_*mar 5 java github issue-tracking egit

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

我试过了:

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

IssueService service = new IssueService(client);

Repository repo = new Repository();
Run Code Online (Sandbox Code Playgroud)

mcw*_*mcw 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();
}
Run Code Online (Sandbox Code Playgroud)

摘要: 我认为 OP 的问题与未提供适当的凭据有关,可能与私人存储库有关。我也无法使用Basic用户名/密码对我们的私人存储库进行身份验证(可能是因为我们的组织需要 2 因素)。相反,Personal Access Token按照上述说明使用授权即可。

有关创建仅问题存储库的更多信息可以在此处找到。