Skip to content

Add support for Github Enterprise#44

Closed
Line-Noise wants to merge 2 commits intoClever:masterfrom
Line-Noise:master
Closed

Add support for Github Enterprise#44
Line-Noise wants to merge 2 commits intoClever:masterfrom
Line-Noise:master

Conversation

@Line-Noise
Copy link
Copy Markdown

This PR adds basic support for Github Enterprise through a GITHUB_URL environment variable.

@Line-Noise Line-Noise requested a review from rgarcia as a code owner August 13, 2019 04:16
Copy link
Copy Markdown
Contributor

@nathanleiby nathanleiby left a comment

Choose a reason for hiding this comment

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

@Line-Noise Thanks very much for your contribution!

I have a few suggestions that I'd love to see before merging this in. If you don't have time to do them, please let me know, and I'll try to get to them soon.

Comment thread README.md
The `GITHUB_API_TOKEN` environment variable must be set for Github. This should be a [GitHub Token](https://github.com/settings/tokens) with `repo` scope.

Optionally: The `GITHUB_URL` environment variable can be set to use a Github Enterprise setup, otherwise it will use https://github.com.
The `GITHUB_URL` **must** be a valid URL for the API endpoint including a trailing slash: e.g. `https://git.yourcompany.com/api/v3/`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: consistency re: backticks + URLs ... suggest using backticks around https://github.com too.

Comment thread initialize/initialize.go
"sort"
"strings"
"strings"
"net/url"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

needs a go fmt

Copy link
Copy Markdown
Author

@Line-Noise Line-Noise Aug 15, 2019

Choose a reason for hiding this comment

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

Oops. That'll teach me to edit stuff directly in GitHub's editor. It converted the tab to spaces when I fixed the merge conflict. I'll fix it up.

Comment thread initialize/initialize.go
client := github.NewClient(tc)

if os.Getenv("GITHUB_URL") != "" {
baseEndpoint, _ := url.Parse(os.Getenv("GITHUB_URL"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should return + handle these errors

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I basically cribbed the code direct from https://github.com/google/go-github/blob/master/github/github.go#L310

Perhaps we should be using NewEnterpriseClient if GITHUB_URL is defined and let it do the error handling?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the idea of using NewEnterpriseClient 👍

Comment thread push/push.go
client.BaseURL = baseEndpoint
uploadEndpoint, _ := url.Parse(os.Getenv("GITHUB_URL") + "upload/")
client.UploadURL = uploadEndpoint
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

by "rule of 3" would love if we could refactor this logic (perhaps all of createGithubClient) into a helper fn so it's not repeated throughout

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, I was thinking this as I was adding the same code in all these different places.

Comment thread initialize/initialize.go
Owner: r.Owner.GetLogin(),
CloneURL: fmt.Sprintf("git@github.com:%s", r.GetFullName()),
CloneURL: fmt.Sprintf("git@%s:%s", hostname, r.GetFullName()),
Provider: "github",
Copy link
Copy Markdown
Contributor

@nathanleiby nathanleiby Aug 13, 2019

Choose a reason for hiding this comment

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

Ultimately, I think I would like to refactor this a bit.. No need to do that within this PR but what do you think of the following?

I believe a it's OK to constrain microplane flow to use only one provider (e.g. all repos come from 1 Github enterprise instance). If so, then we can abstract out the idea of a provider a bit more, make it more explicit, and fix edge cases (e.g. currently, it's possible that the env var value could change and the API URL would be different between push and merge!)

In the future, a user might run: mp init --provider github --provider-url <your API URL> (these flags would be optional and have defaults)

Then, we can store the provider and providerURL on initialize.Output

// Output for Initialize
type Output struct {
Version string
Repos []Repo
}

When doing all future steps, we use the stored provider values. e.g. we can make CloneURL() a function that generates a string based on provider values, and we can remove URL parsing logic in later steps.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is a great idea! I didn't think about what would happen if someone changed GITHUB_URL part way through the process. It should definitely be made idempotent.

@Line-Noise
Copy link
Copy Markdown
Author

I'll fix up a few things based on your comments but I'm not a go programmer (I'm not a programmer at all, I'm a sysadmin!). This is my first time touching go. :-)

@nathanleiby
Copy link
Copy Markdown
Contributor

Pretty impressive that you jumped right into a new language!

@VasuBhaskar
Copy link
Copy Markdown

@nathanleiby it would be great if the support for git enterprise can be merged. This tool can be used widely only if supports enterprise

@VasuBhaskar
Copy link
Copy Markdown

I started to use this and eventually realized, that there is no support for enterprise :-(

@rgarcia rgarcia removed their request for review May 20, 2020 13:13
@gtorre
Copy link
Copy Markdown

gtorre commented Mar 1, 2021

@nathanleiby @Line-Noise any chance this work will be picked up again?

@nathanleiby
Copy link
Copy Markdown
Contributor

@gtorre Thanks for the follow-up! When I took a look awhile back, I wasn't able to make progress because I didn't have a Github enterprise account to test against.

It looks like I'm able to make a 14d free trial for Github Enterprise, so I'll try that and get back to you if I'm able to make this work.

@gtorre
Copy link
Copy Markdown

gtorre commented Mar 1, 2021

Thanks @nathanleiby !

@nathanleiby
Copy link
Copy Markdown
Contributor

@Line-Noise thanks for starting this so long ago and apologies we weren't able to make it happen at the time.

I'm revisiting this now and have created two new PRs

  1. refactoring the provider: Create a Provider (Github/Gitlab) during init and pass it on to other steps #73
  2. then adding support for Github enterprise: Support Github enterprise #74

I'll close this PR for now, given that the same work lives on in those. Thank you again!

cc @gtorre @VasuBhaskar

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.

5 participants