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)
我能够使用EGit 2.1.5实现这一点。以下是我采取的步骤:
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
按照上述说明使用授权即可。
归档时间: |
|
查看次数: |
142 次 |
最近记录: |