Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getLabels() call for a pull request results in 403 #429

Closed
VirenMody opened this issue Mar 29, 2018 · 2 comments
Closed

getLabels() call for a pull request results in 403 #429

VirenMody opened this issue Mar 29, 2018 · 2 comments

Comments

@VirenMody
Copy link

VirenMody commented Mar 29, 2018

I'm a student working on a project in which we're analyzing git repositories' pull request's patch files.

I was able to make the getLabels() call using a GHIssue object, but when making it from a GHPullRequest object I get a 403. ("message":"Must have admin rights to Repository.","documentation_url":"https://developer.github.com/v3/issues/#edit-an-issue")
NOTE: This was tested on a public repo, not my own.

I did see #178, but didn't see the GHPullRequest.fetchIssue() method in the Javadocs.

GHPullRequest extends from GHIssue, so the design here is to call GHPullRequest.fetchIssue() at the right point to ensure methods defined on GHIssue return correct info when used on GHPullRequest instance, such as getLabels() do.

Why does the getLabels() call work for a GHIssue object but not for a GHPullRequest object?

Here's my code

String testRepoName = "code4craft/webmagic";
GHRepository testRepo = null;
try {
    GitHub gitHub = GitHub.connect("*******", "**********");
    testRepo = gitHub.getRepository(testRepoName);
    List<GHPullRequest> pullRequestList = testRepo.getPullRequests(GHIssueState.CLOSED);
    System.out.println(testRepoName + "'s number of pull requests: " + pullRequestList.size());
    for(GHPullRequest pullRequest: pullRequestList) {
        Collection<GHLabel> labelList = pullRequest.getLabels();

Here's the stacktrace:

org.kohsuke.github.HttpException: {"message":"Must have admin rights to Repository.","documentation_url":"https://developer.github.com/v3/issues/#edit-an-issue"}
	at org.kohsuke.github.Requester.handleApiError(Requester.java:695)
	at org.kohsuke.github.Requester._to(Requester.java:298)
	at org.kohsuke.github.Requester.to(Requester.java:246)
	at org.kohsuke.github.GHPullRequest.fetchIssue(GHPullRequest.java:396)
	at org.kohsuke.github.GHPullRequest.getLabels(GHPullRequest.java:136)
	at Main.main(Main.java:48)
Caused by: org.kohsuke.github.HttpException: Server returned HTTP response code: 403, message: 'Forbidden' for URL: https://api.github.com/repos/code4craft/webmagic/issues/713
	at org.kohsuke.github.Requester.parse(Requester.java:638)
	at org.kohsuke.github.Requester.parse(Requester.java:599)
	at org.kohsuke.github.Requester._to(Requester.java:277)
	... 4 more
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: https://api.github.com/repos/code4craft/webmagic/issues/713
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1963)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1958)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1957)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1525)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509)
	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:245)
	at org.kohsuke.github.Requester.parse(Requester.java:617)
	... 6 more
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: https://api.github.com/repos/code4craft/webmagic/issues/713
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1913)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509)
	at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)
	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:329)
	at org.kohsuke.github.Requester.parse(Requester.java:607)
	... 6 more
@Rechi
Copy link
Contributor

Rechi commented May 26, 2018

Have you tried with #431?
It looks like that could fix your issue.

@VirenMody
Copy link
Author

Thanks, I'll check it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants