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

Support GitHub Enterprise #64

Merged
merged 1 commit into from
May 7, 2020
Merged

Conversation

everpeace
Copy link
Contributor

@everpeace everpeace commented May 6, 2020

Fixes #63
The PR enables just to configure GitHub API endpoints.

I didn't use github.NewEnterpriseClient() method because this method does have a bug (google/go-github#1510) in upload URL completion which has been fixed only on the master branch.

Although I'm not sure how to test my change (I mean CI actually), I confirmed this PR works for my own GitHub Enterprise manually.

Copy link
Collaborator

@tstromberg tstromberg left a comment

Choose a reason for hiding this comment

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

Thank you! I am super pumped about this PR. I didn't realize it would be so easy!

@@ -48,6 +49,10 @@ import (
)

var (
// custom GitHub API URLs
githubAPIRawURL = flag.String("github-api-base-url", "", "base URL for GitHub API. Please set this when you use GitHub Enterprise. This often is your GitHub Enterprise hostname. If the base URL does not have the suffix \"/api/v3/\", it will be added automatically.")
githubAPIRawUploadURL = flag.String("github-api-upload-url", "", "upload URL for GitHub API. This must be set when you set --github-api-base-url. This often is your GitHub Enterprise hostname. If the upload URL does not have the suffix \"/api/uploads\", it will be added automatically.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this flag be removed?

  • Triage Party should not perform uploads - it's read-only.
  • As far as I know, the upload URL is usually the same as the base URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that's good news. I will remove it.

As far as I know, the upload URL is usually the same as the base URL.

actually, it is slightly different.

  • baseURL: https://my.github.enterprise/api/v3/
  • uploadURL: https://my.github.enterprise/api/uploads/

But, it's not a problem anyway.

ctx := context.Background()

client := github.NewClient(oauth2.NewClient(ctx, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: triage.MustReadToken(*githubTokenFile, "GITHUB_TOKEN")},
)))

// set GitHub API endpoints to client if custom endpoint was set.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same logic should also be applied to cmd/tester/main.go.

Do you mind moving this code to pkg/triage/github.go? This is where I've been sneaking the logic that is shared between the two programs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the catch. I will do it.

@everpeace
Copy link
Contributor Author

I resolved your review comments and squashed. Please take a look!

@@ -45,3 +47,11 @@ func MustReadToken(path string, env string) string {
}
return token
}

func MustCreateGithubClient(githubAPIRawURL string, httpClient *http.Client) (*github.Client, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be named just GitHubClient: Must as a prefix is reserved in go for functions which panic or otherwise exit on failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to keep the name and change the method to exit when error.


func MustCreateGithubClient(githubAPIRawURL string, httpClient *http.Client) (*github.Client, error) {
if githubAPIRawURL != "" {
// passing base url to uplaod URL is safe because triage-party does NOT upload anything.
Copy link
Collaborator

Choose a reason for hiding this comment

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

the comment isn't really necessary, but if you want to keep it, fix the spelling of "upload". Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I'll remove it.

Copy link
Collaborator

@tstromberg tstromberg left a comment

Choose a reason for hiding this comment

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

Just two tiny nits. Looks good to merge otherwise!

@everpeace
Copy link
Contributor Author

I fixed MustCreateGithubClient so that is exits when error. Please take a look!

@tstromberg
Copy link
Collaborator

tstromberg commented May 7, 2020 via email

@tstromberg tstromberg merged commit 5ad3265 into google:master May 7, 2020
@tstromberg
Copy link
Collaborator

Thank you! I am so glad that this feature landed before v1.0.

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.

Support GitHub Enterprise
2 participants