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

Calling getRef().delete() does not respect the base URL set in .withEndpoint() #1974

Open
ajmalab opened this issue Oct 18, 2024 · 3 comments

Comments

@ajmalab
Copy link

ajmalab commented Oct 18, 2024

Describe the bug
Calling getRef().delete() does not respect the base URL set in .withEndpoint() when creating the OAuth client. It uses api.github.com by default. While this would work in production, it blocks the ability to test this endpoint using local mock servers.

To Reproduce
Steps to reproduce the behavior:

  1. Create an OAuth client as follows
var githubClient = new GitHubBuilder().withOAuthToken("my-token").withEndpoint("http://localhost:8080").build();
  1. Call the method to delete a ref:
githubClient.getRepo("owner/repo").getRef("heads/my-branch").delete()
  1. If you inspect the request in a debugger, you will see that the constructed URL has the host https://api.github.com and not http://localhost:8080.

Expected behavior
The getRef().delete() method should respect the base URL passed in via withEndpoint() like the other chained methods of getRepository().

Additional context
Library version: 1.321

@bitwiseman
Copy link
Member

@ajmalab
What is the JSON that is returned by the call to getRepo and getRef()?
The library uses the returned urls to calculate the endpoint to call for delete().

It sounds like you're trying to run local test server. To do that you need to modify the response body to replace api.github.com with localhost:8080.

We use GitHubApiResponseTransformer:

private static class GitHubApiResponseTransformer extends ResponseTransformer {

Which then calls mapToMockGitHub which has a bunch of body string replacements:

body = body.replace("https://api.github.com", this.apiServer().baseUrl());

@ajmalab
Copy link
Author

ajmalab commented Oct 24, 2024

@bitwiseman
I see, I'm currently getting around the issue by doing a similar transformation within my service. It has worked as intended in all other circumstances though.

Here's the returned response for getRef():

  "ref": "refs/heads/my-test-branch-1",
  "node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlQQ==",
  "url": "https://api.github.com/repos/dummy-org/example-repo/git/refs/heads/my-test-branch-1",
  "object": {
    "type": "commit",
    "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
    "url": "https://api.github.com/repos/dummy-org/example-repo/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
  }
}

@bitwiseman
Copy link
Member

bitwiseman commented Oct 25, 2024

It sounds like you're saying the body information isn't consistent with your server URLs.

The scenario you're describing is out of scope for this library.

You are welcome to submit a PR to try and address it but we do not have the bandwidth.

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

No branches or pull requests

2 participants