Skip to content

Conversation

@castler
Copy link

@castler castler commented Mar 19, 2025

GitHub can be hosted by companies for their own usage (under their own URL).
This changset removes the hard-coded url to github.com and makes it confligurable for a user, which GitHub-instances shall be supported.

Closes #134

@castler
Copy link
Author

castler commented Apr 29, 2025

@mikelalcon @hsudhof

Sorry to bother.
Is there any chance of getting this, or similar versions, merged? Otherwise I would close the PR - to not have unfinished work.

Thanks for your feedback!


boolean isGitHubUrl = false;
try{
GitHubOptions githubOptions = options.get(GitHubOptions.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we move this outside of the try catch block?

GitHubOptions githubOptions = options.get(GitHubOptions.class);
GitHubHost ghHost = githubOptions.getGitHubHost(url);
isGitHubUrl = ghHost.isGitHubUrl(url);
} catch (EvalException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty catch blocks are a bit of an anti-pattern, and I'd like to avoid having these if possible. is there any way you can refactor this into a method in GitHubOptions that returns whether a url belongs to one of the GH hosts?

if you must keep the empty catch block, please leave a comment explaining why we catch and swallow the exception

!ghHost.isGitHubUrl(url),
"Git origins with github should use github approval providers!");
} catch(EvalException e){
// nothing to-do, apparently this is no GitHub URL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments as above

public GitHubApiTransportImpl(GitRepository repo, HttpTransport httpTransport,
String storePath, boolean bearerAuth, Console console) {
public GitHubApiTransportImpl(GitHubHost ghHost, GitRepository repo, HttpTransport httpTransport,
String storePath, boolean bearerAuth, Console console) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra whitespace

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a test that checks if a origin URL is considered a valid GitHub URL when that host is set as a GitHub host?

Copy link
Contributor

@chris-campos chris-campos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY for the contribution! Please see line comments.

@castler
Copy link
Author

castler commented May 6, 2025

Great, I will try to solve that in the next days!

@castler castler force-pushed the support_github_enterprise branch from c3f8282 to 3f87086 Compare May 7, 2025 09:34
@castler
Copy link
Author

castler commented May 7, 2025

names = "--github-allowed-hosts",
description = "If using GitHub Enterprise, one needs to specify valid hosts. By default only `github.com` is supported."
)
public List<String> gitHubAllowedHosts = ImmutableList.of("github.com");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this more, I'm realizing that a flag to set the "allowed" GitHub hosts is not going to scale well for our internal use, and it might not be user friendly for our OSS users. We should avoid using a flag for setting the host allowlist.

I see why the flag was needed in the first place: git.origin was allowed to accept GitHub use cases, which in retrospect was not ideal. However, we also have git.github_origin (GitHub specific) in the module, which gives me an idea.

What if we make it so that git.github_origin assumes that the host in the URL is a valid GitHub host? i.e., if a user says the repo URL is foo.com, then we just treat it as if it has GitHub APIs?

As for the standard git.origin, github.com can be considered the only valid GitHub host. Therefore, Github enterprise specific origins should use git.github_origin

In this way, we are:

  • leveraging the user's intent in choosing github_origin to set it as a valid GitHub host as that is the most likely intent
  • preserving the existing behavior for legacy git.origin users.

what do you think? please LMK if you have any questions, and thank you again for working on this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood - I am afraid of cases where no github specific function is available. I am not that familiar yet with CopyBara in order to judge this out of my head if such cases exist.

So I will give this a try in the next days.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@castler Hello!

I just wanted to follow up on this and how your progress is going on this change. We are really interested in adding this feature into Copybara.

If you can no longer work on it, do you mind if we clone your change and continue work on it? We are also happy to answer any questions you may have.

Thanks again for this great contribution thus far!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chris-campos so sorry that I did not answer...I was now on vacation now for two weeks.

Apparently I got some work at my company todo. So if anybody wants to continue right now - feel free. Otherwise I can try to find some time next week hopefully.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I will see if I can make the changes I suggested above.

Copy link
Contributor

@chris-campos chris-campos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the code changes! Left one more comment about the added flag, LMK what you think

@chris-campos chris-campos self-assigned this Jul 22, 2025
@chris-campos chris-campos force-pushed the support_github_enterprise branch 2 times, most recently from 38c43aa to b635851 Compare July 28, 2025 21:35
@chris-campos chris-campos force-pushed the support_github_enterprise branch from b635851 to d7184da Compare August 1, 2025 19:29
castler and others added 2 commits August 4, 2025 13:33
GitHub can be hosted by companies for their own usage (under their own
URL).
This changset removes the hard-coded url to `github.com` and makes it
confligurable for a user, which GitHub-instances shall be supported.

Closes google#134
To better support GitHub enterprise, the GitHub Origin will just assume any host it's given is a GitHub or Github enterprise host.

GitOrigin will continue to accept GitHub.com URLs.
@chris-campos chris-campos force-pushed the support_github_enterprise branch from d7184da to ea48ff4 Compare August 4, 2025 17:33
@sainathseelam
Copy link

Hi @castler and @chris-campos,

This PR is really important for GitHub Enterprise support in our workflow. It would be great to prioritize resolving the remaining comments and failing checks so it can be merged. Happy to help with testing or questions to get this done.

Thanks!

@chris-campos
Copy link
Contributor

@sainathseelam Hi there! We are now working on this internally.

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

Successfully merging this pull request may close these issues.

Github enterprise support

3 participants