Don't panic
This commit is contained in:
parent
c956bf8d27
commit
3420220b5a
2 changed files with 22 additions and 11 deletions
|
|
@ -49,14 +49,20 @@ func graphQL(query string, variables map[string]string, v interface{}) error {
|
|||
url := "https://api.github.com/graphql"
|
||||
reqBody, err := json.Marshal(map[string]interface{}{"query": query, "variables": variables})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(reqBody))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Authorization", "token "+getToken())
|
||||
|
||||
token, err := getToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("Authorization", "token "+token)
|
||||
req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||
req.Header.Set("User-Agent", "GitHub CLI "+version.Version)
|
||||
|
||||
|
|
@ -65,7 +71,7 @@ func graphQL(query string, variables map[string]string, v interface{}) error {
|
|||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
|
@ -132,18 +138,18 @@ func debugResponse(resp *http.Response, body string) {
|
|||
}
|
||||
|
||||
// TODO: Everything below this line will be removed when Nate's context work is complete
|
||||
func getToken() string {
|
||||
func getToken() (string, error) {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
content, err := ioutil.ReadFile(usr.HomeDir + "/.config/hub")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
r := regexp.MustCompile(`oauth_token: (\w+)`)
|
||||
token := r.FindStringSubmatch(string(content))
|
||||
return token[1]
|
||||
return token[1], nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,14 +27,17 @@ var prListCmd = &cobra.Command{
|
|||
Use: "list",
|
||||
Short: "List pull requests",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ExecutePr()
|
||||
err := ExecutePr()
|
||||
if err != nil {
|
||||
panic(err) // In the future this should handle the error better, but for now panic seems like a valid reaction
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func ExecutePr() {
|
||||
func ExecutePr() error {
|
||||
prPayload, err := api.PullRequests()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return error
|
||||
}
|
||||
|
||||
fmt.Printf("Current Pr\n")
|
||||
|
|
@ -49,6 +52,8 @@ func ExecutePr() {
|
|||
for _, pr := range prPayload.ReviewRequested {
|
||||
printPr(pr)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func printPr(pr api.PullRequest) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue