38 lines
660 B
Go
38 lines
660 B
Go
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
|
|
}
|