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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Triage Party is a stateless Go web application, configured via YAML. While it ha
* Easily open groups of issues into browser tabs (must allow pop-ups)
* Queries across multiple repositories
* "Shift-Reload" for live data pull
* GitHub Enterprise support (via `--github-api-url` cli flag)

## Triage Party in production

Expand Down
6 changes: 4 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"syscall"
"time"

"github.com/google/go-github/v31/github"
"golang.org/x/oauth2"
"k8s.io/klog/v2"

Expand All @@ -48,6 +47,9 @@ import (
)

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

// shared with tester
configPath = flag.String("config", "", "configuration path")
persistBackend = flag.String("persist-backend", "", "Cache persistence backend (disk, mysql, cloudsql)")
Expand Down Expand Up @@ -78,7 +80,7 @@ func main() {

ctx := context.Background()

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

Expand Down
6 changes: 4 additions & 2 deletions cmd/tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import (
"github.com/google/triage-party/pkg/persist"
"github.com/google/triage-party/pkg/triage"

"github.com/google/go-github/v31/github"
"golang.org/x/oauth2"
"k8s.io/klog/v2"
)

var (
// custom GitHub API URLs
githubAPIRawURL = flag.String("github-api-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.")

// shared with server
configPath = flag.String("config", "", "configuration path")
persistBackend = flag.String("persist-backend", "", "Cache persistence backend (disk, mysql, cloudsql)")
Expand All @@ -58,7 +60,7 @@ func main() {
}

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

Expand Down
13 changes: 13 additions & 0 deletions pkg/triage/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package triage

import (
"fmt"
"github.com/google/go-github/v31/github"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
Expand Down Expand Up @@ -45,3 +47,14 @@ func MustReadToken(path string, env string) string {
}
return token
}

func MustCreateGithubClient(githubAPIRawURL string, httpClient *http.Client) *github.Client {
if githubAPIRawURL != "" {
client, err := github.NewEnterpriseClient(githubAPIRawURL, githubAPIRawURL, httpClient)
if err != nil {
klog.Exitf("unable to create GitHub client: %v", err)
}
return client
}
return github.NewClient(httpClient)
}