From 1c146a1b678d11ef86840955a9195685d18e4a52 Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Sun, 26 May 2019 12:47:01 +0200 Subject: [PATCH] Change client default timeout value to 60 seconds add named return values for easier validation for 2FA codes --- bridge/github/config.go | 29 +++++++++-------------------- bridge/github/iterator.go | 12 ++++++------ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/bridge/github/config.go b/bridge/github/config.go index 7868156ed3d9a5ef279ec06841796d854ec412d6..dc1185b5cb52b60dab0923090fd26d05dc068ea6 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -28,7 +28,7 @@ const ( keyProject = "project" keyToken = "token" - defaultTimeout = 5 * time.Second + defaultTimeout = 60 * time.Second ) var ( @@ -243,8 +243,10 @@ func promptToken() (string, error) { func loginAndRequestToken(owner, project string) (string, error) { fmt.Println("git-bug will now generate an access token in your Github profile. Your credential are not stored and are only used to generate the token. The token is stored in the repository git config.") fmt.Println() - fmt.Println("Depending on your configuration the token will have one of the following scopes:") + fmt.Println("The access scope depend on the type of repository.") + fmt.Println("Public:") fmt.Println(" - 'user:email': to be able to read public-only users email") + fmt.Println("Private:") fmt.Println(" - 'repo' : to be able to read private repositories") // fmt.Println("The token will have the \"repo\" permission, giving it read/write access to your repositories and issues. There is no narrower scope available, sorry :-|") fmt.Println() @@ -304,12 +306,7 @@ func loginAndRequestToken(owner, project string) (string, error) { } if resp.StatusCode == http.StatusCreated { - token, err := decodeBody(resp.Body) - if err != nil { - return "", err - } - - return token, nil + return decodeBody(resp.Body) } b, _ := ioutil.ReadAll(resp.Body) @@ -403,7 +400,7 @@ func promptURL(remotes map[string]string) (string, string, error) { } } -func splitURL(url string) (string, string, string, error) { +func splitURL(url string) (shortURL string, owner string, project string, err error) { res := rxGithubURL.FindStringSubmatch(url) if res == nil { return "", "", "", fmt.Errorf("bad github project url") @@ -500,19 +497,11 @@ func prompt2FA() (string, error) { return "", err } - if len(byte2fa) != 6 { - fmt.Println("invalid 2FA code size") - continue - } - - str2fa := string(byte2fa) - _, err = strconv.Atoi(str2fa) - if err != nil { - fmt.Println("2fa code must be digits only") - continue + if len(byte2fa) > 0 { + return string(byte2fa), nil } - return str2fa, nil + fmt.Println("code is empty") } } diff --git a/bridge/github/iterator.go b/bridge/github/iterator.go index 2bb197de086fe614aadf748645da6036bf5259a4..fcf72b8f3fb258121f9721003c9416dcd1daabaf 100644 --- a/bridge/github/iterator.go +++ b/bridge/github/iterator.go @@ -70,22 +70,22 @@ func NewIterator(owner, project, token string, since time.Time) *iterator { issueEdit: indexer{-1}, commentEdit: indexer{-1}, variables: map[string]interface{}{ - keyOwner: githubv4.String(owner), - "name": githubv4.String(project), + "owner": githubv4.String(owner), + "name": githubv4.String(project), }, }, commentEdit: commentEditIterator{ index: -1, variables: map[string]interface{}{ - keyOwner: githubv4.String(owner), - "name": githubv4.String(project), + "owner": githubv4.String(owner), + "name": githubv4.String(project), }, }, issueEdit: issueEditIterator{ index: -1, variables: map[string]interface{}{ - keyOwner: githubv4.String(owner), - "name": githubv4.String(project), + "owner": githubv4.String(owner), + "name": githubv4.String(project), }, }, }