systray.Quit()
case <-mDoSetup.ClickedCh:
fmt.Println("Performing setup")
- startGithubDeviceAuth(cancel)
+ err := startGithubDeviceAuth(cancel)
+ if err == nil {
+ fmt.Println("Setup complete")
+ cancel()
+ return
+ }
}
}
} else {
}
}
}()
-
}
func onReady() {
setupMenu(ctx, cancel)
for {
select {
+ case <-ctx.Done():
+ ctx, cancel = context.WithCancel(context.Background())
+ fmt.Println("Refreshing menu after auth")
+ setupMenu(ctx, cancel)
case <-ticker.C:
- // refresh the menu every 15 minutes
cancel()
ctx, cancel = context.WithCancel(context.Background())
fmt.Println("Refreshing menu")
}()
}
-func startGithubDeviceAuth(cancel context.CancelFunc) {
+func startGithubDeviceAuth(cancel context.CancelFunc) error {
formData := url.Values{
"client_id": []string{GH_CLIENT_ID},
"scope": []string{"notifications repo"},
strings.NewReader(encodedForm))
if err != nil {
errorOut("Error building request to the Github API", err.Error())
- return
+ return err
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
errorOut("Github API error", err.Error())
- return
+ return err
}
if resp.StatusCode != 200 {
- return
+ return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
errorOut("Error reading response body", err.Error())
- return
+ return err
}
// Parse the form-encoded response
parsedResponse, err := url.ParseQuery(string(body))
if err != nil {
errorOut("Github API error", err.Error())
- return
+ return err
}
device_code, ok := parsedResponse["device_code"]
if !ok {
errorOut("Missing device code!",
"The Github API did not return us a device code, please retry in a bit.")
- return
+ return err
}
user_code, ok := parsedResponse["user_code"]
if !ok {
errorOut("Missing user code!",
"The Github API did not return us a user code, please retry in a bit.")
- return
+ return err
}
verification_uri, ok := parsedResponse["verification_uri"]
if !ok {
errorOut("Missing verification uri!",
"The Github API did not return us a verification uri, please retry in a bit.")
- return
+ return err
}
writeToClipboard(user_code[0])
err = open.Run(verification_uri[0])
if err != nil {
errorOut("Error opening the browser", err.Error())
- return
+ return err
}
err = pollGithubDeviceAuth(device_code[0], cancel)
if err != nil {
- return
+ return err
}
+
+ return nil
}
func pollGithubDeviceAuth(deviceCode string, cancel context.CancelFunc) error {
}
// Save the access token and scope
+ fmt.Println("Saving access token and scope")
c := Config{OAuthToken: access_token[0], Scope: scope[0]}
c.save()
cancel()
"fmt"
"io/ioutil"
"net/http"
+ "time"
)
type buildStatus int
subject := pr["subject"].(map[string]interface{})
prAPIUrl := subject["url"].(string)
+ fmt.Println("Fetching PR data", prAPIUrl)
prData, err := fetchOneRESTObject(prAPIUrl, token)
if err == errNoAccessToPR {
// Skip PRs we don't have access to
}
if prSHA != "" && repoFullName != "" {
+ fmt.Println("Fetching build status", repoFullName, prSHA)
prStatus, err = getBuildStatus(repoFullName, prSHA, token)
if err != nil {
prStatus = buildPending
buildStatus: prStatus,
})
}
+
+ time.Sleep(1 * time.Second)
}
return myPRs, otherPRs, nil