Merge pull request #3351 from cristiand391/fix-pr-reopen
Fix detecting PR status when passing branch as arg
This commit is contained in:
commit
d09896468d
7 changed files with 55 additions and 14 deletions
|
|
@ -34,7 +34,6 @@ type PullRequest struct {
|
|||
Number int
|
||||
Title string
|
||||
State string
|
||||
Closed bool
|
||||
URL string
|
||||
BaseRefName string
|
||||
HeadRefName string
|
||||
|
|
@ -165,6 +164,10 @@ func (pr PullRequest) Identifier() string {
|
|||
return pr.ID
|
||||
}
|
||||
|
||||
func (pr PullRequest) IsOpen() bool {
|
||||
return pr.State == "OPEN"
|
||||
}
|
||||
|
||||
type PullRequestReviewStatus struct {
|
||||
ChangesRequested bool
|
||||
Approved bool
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func closeRun(opts *CloseOptions) error {
|
|||
if pr.State == "MERGED" {
|
||||
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d (%s) can't be closed because it was already merged", cs.Red("!"), pr.Number, pr.Title)
|
||||
return cmdutil.SilentError
|
||||
} else if pr.Closed {
|
||||
} else if !pr.IsOpen() {
|
||||
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d (%s) is already closed\n", cs.Yellow("!"), pr.Number, pr.Title)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func TestPrClose(t *testing.T) {
|
|||
httpmock.GraphQL(`query PullRequestByNumber\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"pullRequest": { "id": "THE-ID", "number": 96, "title": "The title of the PR" }
|
||||
"pullRequest": { "id": "THE-ID", "number": 96, "title": "The title of the PR", "state": "OPEN" }
|
||||
} } }`),
|
||||
)
|
||||
http.Register(
|
||||
|
|
@ -98,7 +98,7 @@ func TestPrClose_alreadyClosed(t *testing.T) {
|
|||
httpmock.GraphQL(`query PullRequestByNumber\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"pullRequest": { "number": 101, "title": "The title of the PR", "closed": true }
|
||||
"pullRequest": { "number": 101, "title": "The title of the PR", "state": "CLOSED" }
|
||||
} } }`),
|
||||
)
|
||||
|
||||
|
|
@ -121,8 +121,13 @@ func TestPrClose_deleteBranch(t *testing.T) {
|
|||
http.Register(
|
||||
httpmock.GraphQL(`query PullRequestByNumber\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"pullRequest": { "id": "THE-ID", "number": 96, "title": "The title of the PR", "headRefName":"blueberries", "headRepositoryOwner": {"login": "OWNER"}}
|
||||
{ "data": { "repository": { "pullRequest": {
|
||||
"id": "THE-ID",
|
||||
"number": 96,
|
||||
"title": "The title of the PR",
|
||||
"headRefName":"blueberries",
|
||||
"headRepositoryOwner": {"login": "OWNER"},
|
||||
"state": "OPEN" }
|
||||
} } }`),
|
||||
)
|
||||
http.Register(
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ func readyRun(opts *ReadyOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if pr.Closed {
|
||||
if !pr.IsOpen() {
|
||||
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d is closed. Only draft pull requests can be marked as \"ready for review\"", cs.Red("!"), pr.Number)
|
||||
return cmdutil.SilentError
|
||||
} else if !pr.IsDraft {
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ func TestPRReady(t *testing.T) {
|
|||
httpmock.GraphQL(`query PullRequestByNumber\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"pullRequest": { "id": "THE-ID", "number": 444, "closed": false, "isDraft": true}
|
||||
"pullRequest": { "id": "THE-ID", "number": 444, "state": "OPEN", "isDraft": true}
|
||||
} } }`),
|
||||
)
|
||||
http.Register(
|
||||
|
|
@ -178,7 +178,7 @@ func TestPRReady_alreadyReady(t *testing.T) {
|
|||
httpmock.GraphQL(`query PullRequestByNumber\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"pullRequest": { "number": 445, "closed": false, "isDraft": false}
|
||||
"pullRequest": { "number": 445, "state": "OPEN", "isDraft": false}
|
||||
} } }`),
|
||||
)
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ func TestPRReady_closed(t *testing.T) {
|
|||
httpmock.GraphQL(`query PullRequestByNumber\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"pullRequest": { "number": 446, "closed": true, "isDraft": true}
|
||||
"pullRequest": { "number": 446, "state": "CLOSED", "isDraft": true}
|
||||
} } }`),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func reopenRun(opts *ReopenOptions) error {
|
|||
return cmdutil.SilentError
|
||||
}
|
||||
|
||||
if !pr.Closed {
|
||||
if pr.IsOpen() {
|
||||
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d (%s) is already open\n", cs.Yellow("!"), pr.Number, pr.Title)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ func TestPRReopen(t *testing.T) {
|
|||
httpmock.GraphQL(`query PullRequestByNumber\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"pullRequest": { "id": "THE-ID", "number": 666, "title": "The title of the PR", "closed": true}
|
||||
"pullRequest": { "id": "THE-ID", "number": 666, "title": "The title of the PR", "state": "CLOSED" }
|
||||
} } }`),
|
||||
)
|
||||
http.Register(
|
||||
|
|
@ -86,6 +86,39 @@ func TestPRReopen(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPRReopen_BranchArg(t *testing.T) {
|
||||
http := &httpmock.Registry{}
|
||||
defer http.Verify(t)
|
||||
|
||||
http.Register(
|
||||
httpmock.GraphQL(`query PullRequestForBranch\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": { "pullRequests": {
|
||||
"nodes": [
|
||||
{ "id": "THE-ID", "number": 666, "title": "The title of the PR", "headRefName": "fix-bug", "state": "CLOSED" }
|
||||
]
|
||||
} } } }`),
|
||||
)
|
||||
http.Register(
|
||||
httpmock.GraphQL(`mutation PullRequestReopen\b`),
|
||||
httpmock.GraphQLMutation(`{"id": "THE-ID"}`,
|
||||
func(inputs map[string]interface{}) {
|
||||
assert.Equal(t, inputs["pullRequestId"], "THE-ID")
|
||||
}),
|
||||
)
|
||||
|
||||
output, err := runCommand(http, true, "fix-bug")
|
||||
if err != nil {
|
||||
t.Fatalf("error running command `pr reopen`: %v", err)
|
||||
}
|
||||
|
||||
r := regexp.MustCompile(`Reopened pull request #666 \(The title of the PR\)`)
|
||||
|
||||
if !r.MatchString(output.Stderr()) {
|
||||
t.Fatalf("output did not match regexp /%s/\n> output\n%q\n", r, output.Stderr())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPRReopen_alreadyOpen(t *testing.T) {
|
||||
http := &httpmock.Registry{}
|
||||
defer http.Verify(t)
|
||||
|
|
@ -94,7 +127,7 @@ func TestPRReopen_alreadyOpen(t *testing.T) {
|
|||
httpmock.GraphQL(`query PullRequestByNumber\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"pullRequest": { "number": 666, "title": "The title of the PR", "closed": false}
|
||||
"pullRequest": { "number": 666, "title": "The title of the PR", "state": "OPEN" }
|
||||
} } }`),
|
||||
)
|
||||
|
||||
|
|
@ -118,7 +151,7 @@ func TestPRReopen_alreadyMerged(t *testing.T) {
|
|||
httpmock.GraphQL(`query PullRequestByNumber\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"pullRequest": { "number": 666, "title": "The title of the PR", "closed": true, "state": "MERGED"}
|
||||
"pullRequest": { "number": 666, "title": "The title of the PR", "state": "MERGED"}
|
||||
} } }`),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue