Initial commit
This commit is contained in:
37
lib/github/connect.go
Normal file
37
lib/github/connect.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package github
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/google/go-github/v72/github"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
func (g *Github) Connect() error {
|
||||
httpClient := new(http.Client)
|
||||
|
||||
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: g.app.Settings().APIKey})
|
||||
tc := oauth2.NewClient(
|
||||
context.WithValue(g.app.Context(), oauth2.HTTPClient, httpClient), ts,
|
||||
)
|
||||
|
||||
client := github.NewClient(tc)
|
||||
|
||||
var err error
|
||||
|
||||
client.BaseURL, err = url.Parse("https://api.github.com/")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client.UploadURL, err = url.Parse("https://uploads.github.com/")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
g.client = client
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user