You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a test program to evaluate the library:
packageorg.example;
importorg.kohsuke.github.*;
publicclassMain {
publicstaticvoidmain(String[] args) {
System.out.println("Hello world from Github API Experiment!");
Stringtoken = "xxx";
try {
// ConnectGitHubgithub = newGitHubBuilder().withOAuthToken(token).build();
System.out.println("Built Github API bridge");
System.out.println("With valid credential: " + github.isCredentialValid());
// Get ref from environmentStringref_name = System.getenv("GITHUB_REF_NAME");
System.out.println("Ref name is " + ref_name);
GHRepositoryrepo = github.getRepository("NlightNFotis/demo-spring-petclinic");
// Create branch out of refGHBranchpr_branch = repo.getBranch(ref_name);
// Find pull request corresponding to refGHPullRequestSearchBuilderbuilder = repo.searchPullRequests().isOpen();
varpr_list = builder.list();
System.out.println("PRs found " + pr_list.getTotalCount());
// Iterate through PRsfor (varpr : pr_list) {
System.out.println("PR URL: " + pr.listCommits().toArray()[0].getUrl());
}
} catch (Exceptione) {
System.out.println("Got an exception: " + e.getMessage());
}
}
}
This unfortunately results in a 404 from Github's endpoint, with the output being the following:
Hello world from Github API Experiment!
Built Github API bridge
With valid credential: true
Ref name is cover_action
PRs found 1
Got an exception: https://api.github.com/repos/NlightNFotis/demo-spring-petclinic/issues/1/commits {"message":"Not Found","documentation_url":"https://docs.github.com/rest"}
The error that shows up is a GHFileNotFoundException.
I spent some time trying to debug it, and I understand that the issue is because of the /issues/ path in the URL being queried. If I change the URL to point to /pulls/ instead of /issues/ in a debugger, the issue vanishes: https://api.github.com/repos/NlightNFotis/demo-spring-petclinic/pulls/1/commits.
I have managed to identify the culprit as the GHPullRequest.getApiRoute method.
/** * Gets the api route. * * @return the api route */@OverrideprotectedStringgetApiRoute() {
if (owner == null) {
// Issues returned from search to do not have an owner. Attempt to use url.finalURLurl = Objects.requireNonNull(getUrl(), "Missing instance URL!");
returnStringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/");
}
return"/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/pulls/" + number;
}
What I understand about the issue is:
In my code, I retrieve pull requests using a search. This results in objects that have no owner.
Inside of GHPullRequest.getApiRoute, the owner == null path is being followed, trying to compensate for the lack of an owner by trying to get an API URL from previous API responses.
This results in a URL that contains the /issues/ path, e.g. repos/NlightNFotis/demo-sping-petclinic/issues/, which is then appended to by other queries, such as listCommits().
The request is then sent to GitHub, resulting in a 404.
Expected behavior
If I build with a patched version locally, I get the (expected) output of:
Hello world from Github API Experiment!
Built Github API bridge
With valid credential: true
Ref name is cover_action
PRs found 1
PR URL: https://github.com/NlightNFotis/demo-spring-petclinic/commit/c0b514d30b11a03dbaea71cebec4d4f6cad0f45a
Desktop (please complete the following information):
OS: [e.g. iOS] MacOS Sonoma 14.0
Browser [e.g. chrome, safari] Safari 17.0
Version [e.g. 22] 1.319
Additional context
I have a fix and a regression test locally that I will try to push. It's a drive by change, so I don't know if it satisfies the quality standards of the project, though I have taken every care to try to meet them.
The text was updated successfully, but these errors were encountered:
Describe the bug
Hello.
I'm writing a test program to evaluate the library:
This unfortunately results in a 404 from Github's endpoint, with the output being the following:
The error that shows up is a
GHFileNotFoundException
.I spent some time trying to debug it, and I understand that the issue is because of the
/issues/
path in the URL being queried. If I change the URL to point to/pulls/
instead of/issues/
in a debugger, the issue vanishes:https://api.github.com/repos/NlightNFotis/demo-spring-petclinic/pulls/1/commits
.I have managed to identify the culprit as the
GHPullRequest.getApiRoute
method.What I understand about the issue is:
owner
.GHPullRequest.getApiRoute
, theowner == null
path is being followed, trying to compensate for the lack of an owner by trying to get an API URL from previous API responses./issues/
path, e.g.repos/NlightNFotis/demo-sping-petclinic/issues/
, which is then appended to by other queries, such aslistCommits()
.Expected behavior
If I build with a patched version locally, I get the (expected) output of:
Desktop (please complete the following information):
Additional context
I have a fix and a regression test locally that I will try to push. It's a drive by change, so I don't know if it satisfies the quality standards of the project, though I have taken every care to try to meet them.
The text was updated successfully, but these errors were encountered: