Skip to content

Commit b4ffced

Browse files
authored
Merge pull request cli#1453 from cli/pr-commands-isolate
Isolate pr review, diff, checkout commands
2 parents c8b4238 + 8cba134 commit b4ffced

File tree

21 files changed

+1006
-758
lines changed

21 files changed

+1006
-758
lines changed

api/queries_pr.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"strings"
1010

@@ -209,36 +209,28 @@ func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) {
209209
return
210210
}
211211

212-
func (c Client) PullRequestDiff(baseRepo ghrepo.Interface, prNumber int) (string, error) {
212+
func (c Client) PullRequestDiff(baseRepo ghrepo.Interface, prNumber int) (io.ReadCloser, error) {
213213
url := fmt.Sprintf("https://api.github.com/repos/%s/pulls/%d",
214214
ghrepo.FullName(baseRepo), prNumber)
215215
req, err := http.NewRequest("GET", url, nil)
216216
if err != nil {
217-
return "", err
217+
return nil, err
218218
}
219219

220220
req.Header.Set("Accept", "application/vnd.github.v3.diff; charset=utf-8")
221221

222222
resp, err := c.http.Do(req)
223223
if err != nil {
224-
return "", err
225-
}
226-
defer resp.Body.Close()
227-
228-
b, err := ioutil.ReadAll(resp.Body)
229-
if err != nil {
230-
return "", err
231-
}
232-
233-
if resp.StatusCode == 200 {
234-
return string(b), nil
224+
return nil, err
235225
}
236226

237227
if resp.StatusCode == 404 {
238-
return "", &NotFoundError{errors.New("pull request not found")}
228+
return nil, &NotFoundError{errors.New("pull request not found")}
229+
} else if resp.StatusCode != 200 {
230+
return nil, handleHTTPError(resp)
239231
}
240232

241-
return "", errors.New("pull request diff lookup failed")
233+
return resp.Body, nil
242234
}
243235

244236
func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, currentPRHeadRef, currentUsername string) (*PullRequestsPayload, error) {

api/queries_repo.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ type Repository struct {
2727
IsPrivate bool
2828
HasIssuesEnabled bool
2929
ViewerPermission string
30-
DefaultBranchRef struct {
31-
Name string
32-
}
30+
DefaultBranchRef BranchRef
3331

3432
Parent *Repository
3533

@@ -42,6 +40,11 @@ type RepositoryOwner struct {
4240
Login string
4341
}
4442

43+
// BranchRef is the branch name in a GitHub repository
44+
type BranchRef struct {
45+
Name string
46+
}
47+
4548
// RepoOwner is the login name of the owner
4649
func (r Repository) RepoOwner() string {
4750
return r.Owner.Login

command/pr.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func init() {
2727
prCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` format")
2828

2929
RootCmd.AddCommand(prCmd)
30-
prCmd.AddCommand(prCheckoutCmd)
3130
prCmd.AddCommand(prCreateCmd)
3231
prCmd.AddCommand(prStatusCmd)
3332
prCmd.AddCommand(prCloseCmd)

command/pr_diff.go

Lines changed: 0 additions & 104 deletions
This file was deleted.

command/pr_diff_test.go

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)