jcabi / jcabi/jcabi-github

Issue with get content returned by RtSearch.code()

Open
#1,744 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
307
Forks
144
Avg merge
1d 22h
Merged PRs (30d)
14

Description

Hi, I'm using enterprise github and trying to search for specific code with search.code() function.
The response github api returns looks like this
```json
{
"total_count": 1,
"incomplete_results": false,
"items": [
{
"name": "keyword",
"path": "",
"sha": "",
"url": "https:///api/v3/repositories//contents/?ref=",
"git_url": "https:///api/v3/repositories//git/blobs/",
"html_url": "https://///blob//",
"repository": {
"id": ,
"node_id": ,
"name": "",
"full_name": "/",
"private": false,
"owner": {
"login": "",
"id": id,
"node_id": ,
"avatar_url": "https:///avatars/u/?",
"gravatar_id": "",
"url": "https:///api/v3/users/",
"html_url": "https:///",
"followers_url": "https:///api/v3/users//followers",
"following_url": "https:///api/v3/users//following{/other_user}",
"gists_url": "https:///api/v3/users//gists{/gist_id}",
"starred_url": "https:///api/v3/users//starred{/owner}{/repo}",
"subscriptions_url": "https:///api/v3/users//subscriptions",
"organizations_url": "https:///api/v3/users//orgs",
"repos_url": "https:///api/v3/users//repos",
"events_url": "https:///api/v3/users//events{/privacy}",
"received_events_url": "https:///api/v3/users//received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https:////",
"description": null,
"fork": false,
"url": "https:///api/v3/repos//",
"forks_url": "https:///api/v3/repos///forks",
"keys_url": "https:///api/v3/repos///keys{/key_id}",
"collaborators_url": "https:///api/v3/repos///collaborators{/collaborator}",
"teams_url": "https:///api/v3/repos///teams",
"hooks_url": "https:///api/v3/repos///hooks",
"issue_events_url": "https:///api/v3/repos///issues/events{/number}",
"events_url": "https:///api/v3/repos///events",
"assignees_url": "https:///api/v3/repos///assignees{/user}",
"branches_url": "https:///api/v3/repos///branches{/branch}",
"tags_url": "https:///api/v3/repos///tags",
"blobs_url": "https:///api/v3/repos///git/blobs{/sha}",
"git_tags_url": "https:///api/v3/repos///git/tags{/sha}",
"git_refs_url": "https:///api/v3/repos///git/refs{/sha}",
"trees_url": "https:///api/v3/repos///git/trees{/sha}",
"statuses_url": "https:///api/v3/repos///statuses/{sha}",
"languages_url": "https:///api/v3/repos///languages",
"stargazers_url": "https:///api/v3/repos///stargazers",
"contributors_url": "https:///api/v3/repos///contributors",
"subscribers_url": "https:///api/v3/repos///subscribers",
"subscription_url": "https:///api/v3/repos///subscription",
"commits_url": "https:///api/v3/repos///commits{/sha}",
"git_commits_url": "https:///api/v3/repos///git/commits{/sha}",
"comments_url": "https:///api/v3/repos///comments{/number}",
"issue_comment_url": "https:///api/v3/repos///issues/comments{/number}",
"contents_url": "https:///api/v3/repos///contents/{+path}",
"compare_url": "https:///api/v3/repos///compare/{base}...{head}",
"merges_url": "https:///api/v3/repos///merges",
"archive_url": "https:///api/v3/repos///{archive_format}{/ref}",
"downloads_url": "https:///api/v3/repos///downloads",
"issues_url": "https:///api/v3/repos///issues{/number}",
"pulls_url": "https:///api/v3/repos///pulls{/number}",
"milestones_url": "https:///api/v3/repos///milestones{/number}",
"notifications_url": "https:///api/v3/repos///notifications{?since,all,participating}",
"labels_url": "https:///api/v3/repos///labels{/name}",
"releases_url": "https:///api/v3/repos///releases{/id}",
"deployments_url": "https:///api/v3/repos///deployments"
},
"score": 1.0
}
]
}
```
The code in RtSearch.code() is:
```java
public Iterable codes(String keywords, String sort, Order order) {
return new RtSearchPagination(this.request, "code", keywords, sort, order.identifier(), (object) -> {
try {
URI uri = new URI(object.getString("url"));
String[] parts = SLASH.split(uri.getPath());
String ref = QUERY.split(uri.getQuery())[1];
return this.ghub.repos().get(new Simple(parts[2], parts[3])).contents().get(object.getString("path"), ref);
} catch (URISyntaxException var5) {
throw new IllegalStateException(var5);
} catch (IOException var6) {
throw new IllegalStateException(var6);
}
});
}
```
> return this.ghub.repos().get(new Simple(parts[2], parts[3])).contents().get(object.getString("path"), ref);

This line of code makes codes() return us a list of this
>https://{myHost}/api/v3/repos/v3/repositories/contents/{path}?ref={sha}
(Incorrect)

while it should be
>https://{myHost}/api/v3/repos/{user}/{repo}/contents/{path}

As the result I'm getting 404 not found.
Instead of part[2]/part[3], Can we get the Coordinates from github response?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.