-
Notifications
You must be signed in to change notification settings - Fork 49
Add support for Github Enterprise #44
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,8 @@ import ( | |||||||||||||
| "log" | ||||||||||||||
| "os" | ||||||||||||||
| "sort" | ||||||||||||||
| "strings" | ||||||||||||||
| "strings" | ||||||||||||||
| "net/url" | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||||||||||
|
|
||||||||||||||
| "github.com/google/go-github/github" | ||||||||||||||
| gitlab "github.com/xanzy/go-gitlab" | ||||||||||||||
|
|
@@ -128,6 +129,13 @@ func githubSearch(query string) ([]Repo, error) { | |||||||||||||
|
|
||||||||||||||
| client := github.NewClient(tc) | ||||||||||||||
|
|
||||||||||||||
| if os.Getenv("GITHUB_URL") != "" { | ||||||||||||||
| baseEndpoint, _ := url.Parse(os.Getenv("GITHUB_URL")) | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should return + handle these errors
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the idea of using |
||||||||||||||
| client.BaseURL = baseEndpoint | ||||||||||||||
| uploadEndpoint, _ := url.Parse(os.Getenv("GITHUB_URL") + "upload/") | ||||||||||||||
| client.UploadURL = uploadEndpoint | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| opts := &github.SearchOptions{} | ||||||||||||||
| allRepos := map[string]*github.Repository{} | ||||||||||||||
| numProcessedResults := 0 | ||||||||||||||
|
|
@@ -155,12 +163,18 @@ func githubSearch(query string) ([]Repo, error) { | |||||||||||||
| opts.Page = resp.NextPage | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| hostname := "github.com" | ||||||||||||||
| if os.Getenv("GITHUB_URL") != "" { | ||||||||||||||
| baseEndpoint, _ := url.Parse(os.Getenv("GITHUB_URL")) | ||||||||||||||
| hostname = baseEndpoint.Hostname() | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| repos := []Repo{} | ||||||||||||||
| for _, r := range allRepos { | ||||||||||||||
| repos = append(repos, Repo{ | ||||||||||||||
| Name: r.GetName(), | ||||||||||||||
| Owner: r.Owner.GetLogin(), | ||||||||||||||
| CloneURL: fmt.Sprintf("git@github.com:%s", r.GetFullName()), | ||||||||||||||
| CloneURL: fmt.Sprintf("git@%s:%s", hostname, r.GetFullName()), | ||||||||||||||
| Provider: "github", | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 In the future, a user might run: Then, we can store the provider and providerURL on microplane/initialize/initialize.go Lines 34 to 39 in f9bb2bd
When doing all future steps, we use the stored provider values. e.g. we can make
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||||||||||
| }) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,13 @@ func GithubPush(ctx context.Context, input Input, repoLimiter *time.Ticker, push | |
| tc := oauth2.NewClient(ctx, ts) | ||
| client := github.NewClient(tc) | ||
|
|
||
| if os.Getenv("GITHUB_URL") != "" { | ||
| baseEndpoint, _ := url.Parse(os.Getenv("GITHUB_URL")) | ||
| client.BaseURL = baseEndpoint | ||
| uploadEndpoint, _ := url.Parse(os.Getenv("GITHUB_URL") + "upload/") | ||
| client.UploadURL = uploadEndpoint | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| // Open a pull request, if one doesn't exist already | ||
| head := fmt.Sprintf("%s:%s", input.RepoOwner, input.BranchName) | ||
| base := "master" | ||
|
|
||
There was a problem hiding this comment.
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.comtoo.