-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathgithub.go
More file actions
30 lines (22 loc) · 696 Bytes
/
Copy pathgithub.go
File metadata and controls
30 lines (22 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"os"
"github.com/google/go-github/v78/github"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
// Login to github.com and return authenticated client
func Login(token string) (*github.Client, error) {
cli := github.NewClient(nil).WithAuthToken(token)
apiURL := os.Getenv("GITHUB_API_URL")
serverURL := os.Getenv("GITHUB_SERVER_URL")
if apiURL != "https://api.github.com" && serverURL != "https://github.com" {
log.Info("running on GitHub Enterprise")
c, err := cli.WithEnterpriseURLs(apiURL, serverURL)
if err != nil {
return nil, errors.Wrap(err, "error connecting to a private github instance")
}
return c, nil
}
return cli, nil
}