mirror of
https://github.com/LukeHagar/slinky.git
synced 2025-12-06 04:21:20 +00:00
Enhance error handling and debug output in upsertPRComment function of check.go, ensuring proper response processing and improved troubleshooting for PR comment operations.
This commit is contained in:
18
cmd/check.go
18
cmd/check.go
@@ -401,6 +401,22 @@ func upsertPRComment(repo string, prNumber int, token string, body string) error
|
|||||||
req.Header.Set("Authorization", "Bearer "+token)
|
req.Header.Set("Authorization", "Bearer "+token)
|
||||||
req.Header.Set("Accept", "application/vnd.github+json")
|
req.Header.Set("Accept", "application/vnd.github+json")
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
_, _ = http.DefaultClient.Do(req)
|
upsertResp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer upsertResp.Body.Close()
|
||||||
|
upsertRespBody, _ := io.ReadAll(upsertResp.Body)
|
||||||
|
upsertRespUnmarshalErr := json.Unmarshal(upsertRespBody, &upsertResp)
|
||||||
|
if upsertRespUnmarshalErr != nil {
|
||||||
|
return fmt.Errorf("failed to unmarshal upsert response: %s", upsertRespUnmarshalErr)
|
||||||
|
}
|
||||||
|
if shouldDebug() {
|
||||||
|
fmt.Printf("::debug:: Comment upserted Response: %s\n%s", upsertResp.Status, string(upsertRespBody))
|
||||||
|
fmt.Printf("::debug:: Comment upserted: %+v\n", upsertResp)
|
||||||
|
}
|
||||||
|
if upsertResp.StatusCode != http.StatusOK {
|
||||||
|
return fmt.Errorf("failed to upsert comment: %s", upsertResp.Status)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user