func findOrCreateToken(user, password string) (string, error) { client := octokat.NewClient().WithLogin(user, password) auths, err := client.Authorizations() if err != nil { return "", err } var token string for _, auth := range auths { if auth.NoteUrl == OAuthAppURL { token = auth.Token break } } if token == "" { authParam := octokat.AuthorizationParams{} authParam.Scopes = append(authParam.Scopes, "repo") authParam.Note = "gh" authParam.NoteUrl = OAuthAppURL auth, err := client.CreatedAuthorization(authParam) if err != nil { return "", err } token = auth.Token } return token, nil }
func (gh *GitHub) client() *octokat.Client { config := gh.config if config.User == "" { config.FetchUser() } if config.Token == "" { password := config.FetchPassword() token, err := findOrCreateToken(config.User, password) utils.Check(err) config.Token = token err = saveConfig(config) utils.Check(err) } return octokat.NewClient().WithToken(config.Token) }
func GitHub(token string) *gitHub { client := octokat.NewClient().WithToken(token) return &gitHub{client} }
func (gh *GitHub) client() *octokat.Client { config := gh.Config config.FetchCredentials() return octokat.NewClient().WithToken(config.Token) }