|
@ -8,9 +8,9 @@ import ( |
|
|
"github.com/matrix-org/go-neb/matrix" |
|
|
"github.com/matrix-org/go-neb/matrix" |
|
|
"github.com/matrix-org/go-neb/plugin" |
|
|
"github.com/matrix-org/go-neb/plugin" |
|
|
"github.com/matrix-org/go-neb/realms/github" |
|
|
"github.com/matrix-org/go-neb/realms/github" |
|
|
|
|
|
"github.com/matrix-org/go-neb/services/github/client" |
|
|
"github.com/matrix-org/go-neb/services/github/webhook" |
|
|
"github.com/matrix-org/go-neb/services/github/webhook" |
|
|
"github.com/matrix-org/go-neb/types" |
|
|
"github.com/matrix-org/go-neb/types" |
|
|
"golang.org/x/oauth2" |
|
|
|
|
|
"net/http" |
|
|
"net/http" |
|
|
"regexp" |
|
|
"regexp" |
|
|
"strconv" |
|
|
"strconv" |
|
@ -290,9 +290,9 @@ func (s *githubService) githubClientFor(userID string, allowUnauth bool) *github |
|
|
}).Print("Failed to get token for user") |
|
|
}).Print("Failed to get token for user") |
|
|
} |
|
|
} |
|
|
if token != "" { |
|
|
if token != "" { |
|
|
return githubClient(token) |
|
|
|
|
|
|
|
|
return client.New(token) |
|
|
} else if allowUnauth { |
|
|
} else if allowUnauth { |
|
|
return githubClient("") |
|
|
|
|
|
|
|
|
return client.New("") |
|
|
} else { |
|
|
} else { |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
@ -322,20 +322,6 @@ func getTokenForUser(realmID, userID string) (string, error) { |
|
|
return ghSession.AccessToken, nil |
|
|
return ghSession.AccessToken, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// githubClient returns a github Client which can perform Github API operations.
|
|
|
|
|
|
// If `token` is empty, a non-authenticated client will be created. This should be
|
|
|
|
|
|
// used sparingly where possible as you only get 60 requests/hour like that (IP locked).
|
|
|
|
|
|
func githubClient(token string) *github.Client { |
|
|
|
|
|
var tokenSource oauth2.TokenSource |
|
|
|
|
|
if token != "" { |
|
|
|
|
|
tokenSource = oauth2.StaticTokenSource( |
|
|
|
|
|
&oauth2.Token{AccessToken: token}, |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
httpCli := oauth2.NewClient(oauth2.NoContext, tokenSource) |
|
|
|
|
|
return github.NewClient(httpCli) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ownerRepoNumberFromText parses a GH issue string that looks like 'owner/repo#11'
|
|
|
// ownerRepoNumberFromText parses a GH issue string that looks like 'owner/repo#11'
|
|
|
// into its constituient parts. Returns: owner, repo, issue#.
|
|
|
// into its constituient parts. Returns: owner, repo, issue#.
|
|
|
func ownerRepoNumberFromText(ownerRepoNumberText string) (string, string, int, error) { |
|
|
func ownerRepoNumberFromText(ownerRepoNumberText string) (string, string, int, error) { |
|
|