feat(github): implement PRReader + FileReader client (#80) #93

Closed
rodin wants to merge 16 commits from review-bot-issue-80 into feature/github-support
3 changed files with 9 additions and 8 deletions
Showing only changes of commit 5b2fa0b9af - Show all commits
+3 -3
View File
16
@@ -199,7 +199,7 @@ func (c *Client) doRequest(ctx context.Context, method, reqURL string, accept st
timer := time.NewTimer(delay) timer := time.NewTimer(delay)
select { select {
case <-timer.C: case <-timer.C:
// Timer already fired; Stop() is a no-op here. // Backoff elapsed, proceed with retry.
case <-ctx.Done(): case <-ctx.Done():
timer.Stop() timer.Stop()
return nil, ctx.Err() return nil, ctx.Err()
8
@@ -259,8 +259,8 @@ func (c *Client) doRequest(ctx context.Context, method, reqURL string, accept st
if attempt < len(backoff) { if attempt < len(backoff) {
backoff[attempt] = delay backoff[attempt] = delay
} }
} else if t, err := http.ParseTime(ra); err == nil { } else if retryAt, err := http.ParseTime(ra); err == nil {
delay := time.Until(t) delay := time.Until(retryAt)
Review

[NIT] In doRequest, after the handleResponse call, there's a check if resp.StatusCode == http.StatusTooManyRequests but resp could theoretically have been closed by handleResponse. The body is closed, but the resp.StatusCode field is still accessible on the struct. This is correct and safe in Go's net/http — just worth being aware of.

**[NIT]** In `doRequest`, after the `handleResponse` call, there's a check `if resp.StatusCode == http.StatusTooManyRequests` but `resp` could theoretically have been closed by `handleResponse`. The body is closed, but the `resp.StatusCode` field is still accessible on the struct. This is correct and safe in Go's net/http — just worth being aware of.
if delay < 0 { if delay < 0 {
delay = 0 delay = 0
} }
+2
View File
4
@@ -48,6 +48,8 @@ func (c *Client) ListContents(ctx context.Context, owner, repo, path string) ([]
if err2 := json.Unmarshal(body, &single); err2 != nil { if err2 := json.Unmarshal(body, &single); err2 != nil {
return nil, fmt.Errorf("parse contents JSON: %w", err2) return nil, fmt.Errorf("parse contents JSON: %w", err2)
} }
// Guard against empty objects ({}) or unexpected shapes that
// unmarshal successfully but carry no useful data.
if single.Name == "" && single.Path == "" && single.Type == "" { if single.Name == "" && single.Path == "" && single.Type == "" {
return nil, fmt.Errorf("parse contents JSON: unexpected response format") return nil, fmt.Errorf("parse contents JSON: unexpected response format")
} }
4
+4 -5
View File
20
@@ -194,7 +194,7 @@ func (c *Client) GetCommitStatuses(ctx context.Context, owner, repo, sha string)
for _, cr := range checkResp.CheckRuns { for _, cr := range checkResp.CheckRuns {
result = append(result, vcs.CommitStatus{ result = append(result, vcs.CommitStatus{
Review

[MINOR] The mapCheckRunStatus mapping treats cancelled, skipped, and neutral as "success" (non-blocking). This is a policy decision that should be documented more prominently — cancelled in particular could reasonably be mapped to failure in some contexts. The comment // non-blocking is brief; a note explaining the design rationale (e.g. 'these do not indicate a blocking failure per GitHub's check suite semantics') would help future maintainers.

**[MINOR]** The `mapCheckRunStatus` mapping treats `cancelled`, `skipped`, and `neutral` as `"success"` (non-blocking). This is a policy decision that should be documented more prominently — `cancelled` in particular could reasonably be mapped to `failure` in some contexts. The comment `// non-blocking` is brief; a note explaining the design rationale (e.g. 'these do not indicate a blocking failure per GitHub's check suite semantics') would help future maintainers.
Context: cr.Name, Context: cr.Name,
Status: mapCheckRunStatus(cr.Conclusion, cr.Status), Status: mapCheckRunStatus(cr.Conclusion),
Description: derefString(cr.Conclusion), Description: derefString(cr.Conclusion),
TargetURL: cr.HTMLURL, TargetURL: cr.HTMLURL,
}) })
1
@@ -208,10 +208,9 @@ func (c *Client) GetCommitStatuses(ctx context.Context, owner, repo, sha string)
} }
// mapCheckRunStatus maps a check run conclusion to a vcs.CommitStatus status string. // mapCheckRunStatus maps a check run conclusion to a vcs.CommitStatus status string.
// The second parameter (check run status field, e.g. "completed", "in_progress") is // Conclusion alone determines the mapped state: nil conclusion means the run is
// unused because conclusion alone determines the mapped state: nil conclusion means // still in progress (pending), regardless of the status field value.
// the run is still in progress (pending), regardless of the status field value. func mapCheckRunStatus(conclusion *string) string {
func mapCheckRunStatus(conclusion *string, _ string) string {
if conclusion == nil { if conclusion == nil {
// Still running or queued // Still running or queued
return "pending" return "pending"