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

Issue with get content returned by RtSearch.code() #1744

Open
yrzzzzzz opened this issue May 8, 2024 · 0 comments
Open

Issue with get content returned by RtSearch.code() #1744

yrzzzzzz opened this issue May 8, 2024 · 0 comments

Comments

@yrzzzzzz
Copy link

yrzzzzzz commented May 8, 2024

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

{
    "total_count": 1,
    "incomplete_results": false,
    "items": [
        {
            "name": "keyword",
            "path": "<path>",
            "sha": "<sha>",
            "url": "https://<myEnterpriseHost>/api/v3/repositories/<id>/contents/<path>?ref=<sha>",
            "git_url": "https://<myEnterpriseHost>/api/v3/repositories/<id>/git/blobs/<sha>",
            "html_url": "https://<myEnterpriseHost>/<user>/<repo>/blob/<sha>/<path>",
            "repository": {
                "id": <id>,
                "node_id": <node_id>,
                "name": "<repo>",
                "full_name": "<user>/<repo>",
                "private": false,
                "owner": {
                    "login": "<user>",
                    "id": id,
                    "node_id": <node_id>,
                    "avatar_url": "https://<myEnterpriseHost>/avatars/u/<id>?",
                    "gravatar_id": "",
                    "url": "https://<myEnterpriseHost>/api/v3/users/<user>",
                    "html_url": "https://<myEnterpriseHost>/<user>",
                    "followers_url": "https://<myEnterpriseHost>/api/v3/users/<user>/followers",
                    "following_url": "https://<myEnterpriseHost>/api/v3/users/<user>/following{/other_user}",
                    "gists_url": "https://<myEnterpriseHost>/api/v3/users/<user>/gists{/gist_id}",
                    "starred_url": "https://<myEnterpriseHost>/api/v3/users/<user>/starred{/owner}{/repo}",
                    "subscriptions_url": "https://<myEnterpriseHost>/api/v3/users/<user>/subscriptions",
                    "organizations_url": "https://<myEnterpriseHost>/api/v3/users/<user>/orgs",
                    "repos_url": "https://<myEnterpriseHost>/api/v3/users/<user>/repos",
                    "events_url": "https://<myEnterpriseHost>/api/v3/users/<user>/events{/privacy}",
                    "received_events_url": "https://<myEnterpriseHost>/api/v3/users/<user>/received_events",
                    "type": "Organization",
                    "site_admin": false
                },
                "html_url": "https://<myEnterpriseHost>/<user>/<repo>",
                "description": null,
                "fork": false,
                "url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>",
                "forks_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/forks",
                "keys_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/keys{/key_id}",
                "collaborators_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/collaborators{/collaborator}",
                "teams_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/teams",
                "hooks_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/hooks",
                "issue_events_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/issues/events{/number}",
                "events_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/events",
                "assignees_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/assignees{/user}",
                "branches_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/branches{/branch}",
                "tags_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/tags",
                "blobs_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/git/blobs{/sha}",
                "git_tags_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/git/tags{/sha}",
                "git_refs_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/git/refs{/sha}",
                "trees_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/git/trees{/sha}",
                "statuses_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/statuses/{sha}",
                "languages_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/languages",
                "stargazers_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/stargazers",
                "contributors_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/contributors",
                "subscribers_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/subscribers",
                "subscription_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/subscription",
                "commits_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/commits{/sha}",
                "git_commits_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/git/commits{/sha}",
                "comments_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/comments{/number}",
                "issue_comment_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/issues/comments{/number}",
                "contents_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/contents/{+path}",
                "compare_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/compare/{base}...{head}",
                "merges_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/merges",
                "archive_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/{archive_format}{/ref}",
                "downloads_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/downloads",
                "issues_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/issues{/number}",
                "pulls_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/pulls{/number}",
                "milestones_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/milestones{/number}",
                "notifications_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/notifications{?since,all,participating}",
                "labels_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/labels{/name}",
                "releases_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/releases{/id}",
                "deployments_url": "https://<myEnterpriseHost>/api/v3/repos/<user>/<repo>/deployments"
            },
            "score": 1.0
        }
    ]
}

The code in RtSearch.code() is:

  public Iterable<Content> 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?

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

1 participant