"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/cmd/pr/merge/merge_test.go" between
gh-cli-1.12.1.tar.gz and gh-cli-1.13.1.tar.gz

About: GitHub CLI is GitHub’s official command line tool.

merge_test.go  (gh-cli-1.12.1):merge_test.go  (gh-cli-1.13.1)
skipping to change at line 260 skipping to change at line 260
return &httpmock.Registry{} return &httpmock.Registry{}
} }
func TestPrMerge(t *testing.T) { func TestPrMerge(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"1", "1",
&api.PullRequest{ &api.PullRequest{
ID: "THE-ID", ID: "THE-ID",
Number: 1, Number: 1,
State: "OPEN", State: "OPEN",
Title: "The title of the PR", Title: "The title of the PR",
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
http.Register( http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`), httpmock.GraphQL(`mutation PullRequestMerge\b`),
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) { httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
assert.Equal(t, "THE-ID", input["pullRequestId"].(string) ) assert.Equal(t, "THE-ID", input["pullRequestId"].(string) )
assert.Equal(t, "MERGE", input["mergeMethod"].(string)) assert.Equal(t, "MERGE", input["mergeMethod"].(string))
assert.NotContains(t, input, "commitHeadline") assert.NotContains(t, input, "commitHeadline")
skipping to change at line 291 skipping to change at line 292
t.Fatalf("error running command `pr merge`: %v", err) t.Fatalf("error running command `pr merge`: %v", err)
} }
r := regexp.MustCompile(`Merged pull request #1 \(The title of the PR\)`) r := regexp.MustCompile(`Merged pull request #1 \(The title of the PR\)`)
if !r.MatchString(output.Stderr()) { if !r.MatchString(output.Stderr()) {
t.Fatalf("output did not match regexp /%s/\n> output\n%q\n", r, o utput.Stderr()) t.Fatalf("output did not match regexp /%s/\n> output\n%q\n", r, o utput.Stderr())
} }
} }
func TestPrMerge_blocked(t *testing.T) {
http := initFakeHTTP()
defer http.Verify(t)
shared.RunCommandFinder(
"1",
&api.PullRequest{
ID: "THE-ID",
Number: 1,
State: "OPEN",
Title: "The title of the PR",
MergeStateStatus: "BLOCKED",
},
baseRepo("OWNER", "REPO", "master"),
)
_, cmdTeardown := run.Stub()
defer cmdTeardown(t)
output, err := runCommand(http, "master", true, "pr merge 1 --merge")
assert.EqualError(t, err, "SilentError")
assert.Equal(t, "", output.String())
assert.Equal(t, heredoc.Docf(`
X Pull request #1 is not mergeable: the base branch policy prohib
its the merge.
To have the pull request merged after all the requirements have b
een met, add the %[1]s--auto%[1]s flag.
`, "`"), output.Stderr())
}
func TestPrMerge_nontty(t *testing.T) { func TestPrMerge_nontty(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"1", "1",
&api.PullRequest{ &api.PullRequest{
ID: "THE-ID", ID: "THE-ID",
Number: 1, Number: 1,
State: "OPEN", State: "OPEN",
Title: "The title of the PR", Title: "The title of the PR",
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
http.Register( http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`), httpmock.GraphQL(`mutation PullRequestMerge\b`),
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) { httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
assert.Equal(t, "THE-ID", input["pullRequestId"].(string) ) assert.Equal(t, "THE-ID", input["pullRequestId"].(string) )
assert.Equal(t, "MERGE", input["mergeMethod"].(string)) assert.Equal(t, "MERGE", input["mergeMethod"].(string))
assert.NotContains(t, input, "commitHeadline") assert.NotContains(t, input, "commitHeadline")
skipping to change at line 333 skipping to change at line 364
assert.Equal(t, "", output.Stderr()) assert.Equal(t, "", output.Stderr())
} }
func TestPrMerge_withRepoFlag(t *testing.T) { func TestPrMerge_withRepoFlag(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"1", "1",
&api.PullRequest{ &api.PullRequest{
ID: "THE-ID", ID: "THE-ID",
Number: 1, Number: 1,
State: "OPEN", State: "OPEN",
Title: "The title of the PR", Title: "The title of the PR",
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
http.Register( http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`), httpmock.GraphQL(`mutation PullRequestMerge\b`),
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) { httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
assert.Equal(t, "THE-ID", input["pullRequestId"].(string) ) assert.Equal(t, "THE-ID", input["pullRequestId"].(string) )
assert.Equal(t, "MERGE", input["mergeMethod"].(string)) assert.Equal(t, "MERGE", input["mergeMethod"].(string))
assert.NotContains(t, input, "commitHeadline") assert.NotContains(t, input, "commitHeadline")
skipping to change at line 371 skipping to change at line 403
} }
} }
func TestPrMerge_deleteBranch(t *testing.T) { func TestPrMerge_deleteBranch(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"", "",
&api.PullRequest{ &api.PullRequest{
ID: "PR_10", ID: "PR_10",
Number: 10, Number: 10,
State: "OPEN", State: "OPEN",
Title: "Blueberries are a good fruit", Title: "Blueberries are a good fruit",
HeadRefName: "blueberries", HeadRefName: "blueberries",
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
http.Register( http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`), httpmock.GraphQL(`mutation PullRequestMerge\b`),
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) { httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
assert.Equal(t, "PR_10", input["pullRequestId"].(string)) assert.Equal(t, "PR_10", input["pullRequestId"].(string))
assert.Equal(t, "MERGE", input["mergeMethod"].(string)) assert.Equal(t, "MERGE", input["mergeMethod"].(string))
assert.NotContains(t, input, "commitHeadline") assert.NotContains(t, input, "commitHeadline")
skipping to change at line 417 skipping to change at line 450
`), output.Stderr()) `), output.Stderr())
} }
func TestPrMerge_deleteNonCurrentBranch(t *testing.T) { func TestPrMerge_deleteNonCurrentBranch(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"blueberries", "blueberries",
&api.PullRequest{ &api.PullRequest{
ID: "PR_10", ID: "PR_10",
Number: 10, Number: 10,
State: "OPEN", State: "OPEN",
Title: "Blueberries are a good fruit", Title: "Blueberries are a good fruit",
HeadRefName: "blueberries", HeadRefName: "blueberries",
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
http.Register( http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`), httpmock.GraphQL(`mutation PullRequestMerge\b`),
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) { httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
assert.Equal(t, "PR_10", input["pullRequestId"].(string)) assert.Equal(t, "PR_10", input["pullRequestId"].(string))
assert.Equal(t, "MERGE", input["mergeMethod"].(string)) assert.Equal(t, "MERGE", input["mergeMethod"].(string))
assert.NotContains(t, input, "commitHeadline") assert.NotContains(t, input, "commitHeadline")
skipping to change at line 460 skipping to change at line 494
✓ Merged pull request #10 (Blueberries are a good fruit) ✓ Merged pull request #10 (Blueberries are a good fruit)
✓ Deleted branch blueberries ✓ Deleted branch blueberries
`), output.Stderr()) `), output.Stderr())
} }
func Test_nonDivergingPullRequest(t *testing.T) { func Test_nonDivergingPullRequest(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
pr := &api.PullRequest{ pr := &api.PullRequest{
ID: "PR_10", ID: "PR_10",
Number: 10, Number: 10,
Title: "Blueberries are a good fruit", Title: "Blueberries are a good fruit",
State: "OPEN", State: "OPEN",
MergeStateStatus: "CLEAN",
} }
stubCommit(pr, "COMMITSHA1") stubCommit(pr, "COMMITSHA1")
prFinder := shared.RunCommandFinder("", pr, baseRepo("OWNER", "REPO", "ma ster")) prFinder := shared.RunCommandFinder("", pr, baseRepo("OWNER", "REPO", "ma ster"))
prFinder.ExpectFields([]string{"id", "number", "state", "title", "lastCom mit", "mergeable", "headRepositoryOwner", "headRefName"}) prFinder.ExpectFields([]string{"id", "number", "state", "title", "lastCom mit", "mergeStateStatus", "headRepositoryOwner", "headRefName"})
http.Register( http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`), httpmock.GraphQL(`mutation PullRequestMerge\b`),
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) { httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
assert.Equal(t, "PR_10", input["pullRequestId"].(string)) assert.Equal(t, "PR_10", input["pullRequestId"].(string))
assert.Equal(t, "MERGE", input["mergeMethod"].(string)) assert.Equal(t, "MERGE", input["mergeMethod"].(string))
assert.NotContains(t, input, "commitHeadline") assert.NotContains(t, input, "commitHeadline")
})) }))
cs, cmdTeardown := run.Stub() cs, cmdTeardown := run.Stub()
skipping to change at line 498 skipping to change at line 533
assert.Equal(t, heredoc.Doc(` assert.Equal(t, heredoc.Doc(`
✓ Merged pull request #10 (Blueberries are a good fruit) ✓ Merged pull request #10 (Blueberries are a good fruit)
`), output.Stderr()) `), output.Stderr())
} }
func Test_divergingPullRequestWarning(t *testing.T) { func Test_divergingPullRequestWarning(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
pr := &api.PullRequest{ pr := &api.PullRequest{
ID: "PR_10", ID: "PR_10",
Number: 10, Number: 10,
Title: "Blueberries are a good fruit", Title: "Blueberries are a good fruit",
State: "OPEN", State: "OPEN",
MergeStateStatus: "CLEAN",
} }
stubCommit(pr, "COMMITSHA1") stubCommit(pr, "COMMITSHA1")
prFinder := shared.RunCommandFinder("", pr, baseRepo("OWNER", "REPO", "ma ster")) prFinder := shared.RunCommandFinder("", pr, baseRepo("OWNER", "REPO", "ma ster"))
prFinder.ExpectFields([]string{"id", "number", "state", "title", "lastCom mit", "mergeable", "headRepositoryOwner", "headRefName"}) prFinder.ExpectFields([]string{"id", "number", "state", "title", "lastCom mit", "mergeStateStatus", "headRepositoryOwner", "headRefName"})
http.Register( http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`), httpmock.GraphQL(`mutation PullRequestMerge\b`),
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) { httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
assert.Equal(t, "PR_10", input["pullRequestId"].(string)) assert.Equal(t, "PR_10", input["pullRequestId"].(string))
assert.Equal(t, "MERGE", input["mergeMethod"].(string)) assert.Equal(t, "MERGE", input["mergeMethod"].(string))
assert.NotContains(t, input, "commitHeadline") assert.NotContains(t, input, "commitHeadline")
})) }))
cs, cmdTeardown := run.Stub() cs, cmdTeardown := run.Stub()
skipping to change at line 539 skipping to change at line 575
`), output.Stderr()) `), output.Stderr())
} }
func Test_pullRequestWithoutCommits(t *testing.T) { func Test_pullRequestWithoutCommits(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"", "",
&api.PullRequest{ &api.PullRequest{
ID: "PR_10", ID: "PR_10",
Number: 10, Number: 10,
Title: "Blueberries are a good fruit", Title: "Blueberries are a good fruit",
State: "OPEN", State: "OPEN",
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
http.Register( http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`), httpmock.GraphQL(`mutation PullRequestMerge\b`),
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) { httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
assert.Equal(t, "PR_10", input["pullRequestId"].(string)) assert.Equal(t, "PR_10", input["pullRequestId"].(string))
assert.Equal(t, "MERGE", input["mergeMethod"].(string)) assert.Equal(t, "MERGE", input["mergeMethod"].(string))
assert.NotContains(t, input, "commitHeadline") assert.NotContains(t, input, "commitHeadline")
skipping to change at line 575 skipping to change at line 612
`), output.Stderr()) `), output.Stderr())
} }
func TestPrMerge_rebase(t *testing.T) { func TestPrMerge_rebase(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"2", "2",
&api.PullRequest{ &api.PullRequest{
ID: "THE-ID", ID: "THE-ID",
Number: 2, Number: 2,
Title: "The title of the PR", Title: "The title of the PR",
State: "OPEN", State: "OPEN",
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
http.Register( http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`), httpmock.GraphQL(`mutation PullRequestMerge\b`),
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) { httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
assert.Equal(t, "THE-ID", input["pullRequestId"].(string) ) assert.Equal(t, "THE-ID", input["pullRequestId"].(string) )
assert.Equal(t, "REBASE", input["mergeMethod"].(string)) assert.Equal(t, "REBASE", input["mergeMethod"].(string))
assert.NotContains(t, input, "commitHeadline") assert.NotContains(t, input, "commitHeadline")
skipping to change at line 613 skipping to change at line 651
} }
} }
func TestPrMerge_squash(t *testing.T) { func TestPrMerge_squash(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"3", "3",
&api.PullRequest{ &api.PullRequest{
ID: "THE-ID", ID: "THE-ID",
Number: 3, Number: 3,
Title: "The title of the PR", Title: "The title of the PR",
State: "OPEN", State: "OPEN",
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
http.Register( http.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`), httpmock.GraphQL(`mutation PullRequestMerge\b`),
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) { httpmock.GraphQLMutation(`{}`, func(input map[string]interface{}) {
assert.Equal(t, "THE-ID", input["pullRequestId"].(string) ) assert.Equal(t, "THE-ID", input["pullRequestId"].(string) )
assert.Equal(t, "SQUASH", input["mergeMethod"].(string)) assert.Equal(t, "SQUASH", input["mergeMethod"].(string))
assert.NotContains(t, input, "commitHeadline") assert.NotContains(t, input, "commitHeadline")
skipping to change at line 650 skipping to change at line 689
`), output.Stderr()) `), output.Stderr())
} }
func TestPrMerge_alreadyMerged(t *testing.T) { func TestPrMerge_alreadyMerged(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"4", "4",
&api.PullRequest{ &api.PullRequest{
ID: "THE-ID", ID: "THE-ID",
Number: 4, Number: 4,
State: "MERGED", State: "MERGED",
HeadRefName: "blueberries", HeadRefName: "blueberries",
BaseRefName: "master", BaseRefName: "master",
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
cs, cmdTeardown := run.Stub() cs, cmdTeardown := run.Stub()
defer cmdTeardown(t) defer cmdTeardown(t)
cs.Register(`git checkout master`, 0, "") cs.Register(`git checkout master`, 0, "")
cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "") cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "")
cs.Register(`git branch -D blueberries`, 0, "") cs.Register(`git branch -D blueberries`, 0, "")
skipping to change at line 687 skipping to change at line 727
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"4", "4",
&api.PullRequest{ &api.PullRequest{
ID: "THE-ID", ID: "THE-ID",
Number: 4, Number: 4,
State: "MERGED", State: "MERGED",
HeadRepositoryOwner: api.Owner{Login: "monalisa"}, HeadRepositoryOwner: api.Owner{Login: "monalisa"},
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
_, cmdTeardown := run.Stub() _, cmdTeardown := run.Stub()
defer cmdTeardown(t) defer cmdTeardown(t)
output, err := runCommand(http, "blueberries", true, "pr merge 4 --merge" ) output, err := runCommand(http, "blueberries", true, "pr merge 4 --merge" )
if err != nil { if err != nil {
t.Fatalf("Got unexpected error running `pr merge` %s", err) t.Fatalf("Got unexpected error running `pr merge` %s", err)
skipping to change at line 710 skipping to change at line 751
assert.Equal(t, "! Pull request #4 was already merged\n", output.Stderr() ) assert.Equal(t, "! Pull request #4 was already merged\n", output.Stderr() )
} }
func TestPRMerge_interactive(t *testing.T) { func TestPRMerge_interactive(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"", "",
&api.PullRequest{ &api.PullRequest{
ID: "THE-ID", ID: "THE-ID",
Number: 3, Number: 3,
Title: "It was the best of times", Title: "It was the best of times",
HeadRefName: "blueberries", HeadRefName: "blueberries",
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
http.Register( http.Register(
httpmock.GraphQL(`query RepositoryInfo\b`), httpmock.GraphQL(`query RepositoryInfo\b`),
httpmock.StringResponse(` httpmock.StringResponse(`
{ "data": { "repository": { { "data": { "repository": {
"mergeCommitAllowed": true, "mergeCommitAllowed": true,
"rebaseMergeAllowed": true, "rebaseMergeAllowed": true,
skipping to change at line 760 skipping to change at line 802
test.ExpectLines(t, output.Stderr(), "Merged pull request #3") test.ExpectLines(t, output.Stderr(), "Merged pull request #3")
} }
func TestPRMerge_interactiveWithDeleteBranch(t *testing.T) { func TestPRMerge_interactiveWithDeleteBranch(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"", "",
&api.PullRequest{ &api.PullRequest{
ID: "THE-ID", ID: "THE-ID",
Number: 3, Number: 3,
Title: "It was the best of times", Title: "It was the best of times",
HeadRefName: "blueberries", HeadRefName: "blueberries",
MergeStateStatus: "CLEAN",
}, },
baseRepo("OWNER", "REPO", "master"), baseRepo("OWNER", "REPO", "master"),
) )
http.Register( http.Register(
httpmock.GraphQL(`query RepositoryInfo\b`), httpmock.GraphQL(`query RepositoryInfo\b`),
httpmock.StringResponse(` httpmock.StringResponse(`
{ "data": { "repository": { { "data": { "repository": {
"mergeCommitAllowed": true, "mergeCommitAllowed": true,
"rebaseMergeAllowed": true, "rebaseMergeAllowed": true,
skipping to change at line 862 skipping to change at line 905
err := mergeRun(&MergeOptions{ err := mergeRun(&MergeOptions{
IO: io, IO: io,
Editor: testEditor{}, Editor: testEditor{},
HttpClient: func() (*http.Client, error) { HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: tr}, nil return &http.Client{Transport: tr}, nil
}, },
SelectorArg: "https://github.com/OWNER/REPO/pull/123", SelectorArg: "https://github.com/OWNER/REPO/pull/123",
InteractiveMode: true, InteractiveMode: true,
Finder: shared.NewMockFinder( Finder: shared.NewMockFinder(
"https://github.com/OWNER/REPO/pull/123", "https://github.com/OWNER/REPO/pull/123",
&api.PullRequest{ID: "THE-ID", Number: 123, Title: "title "}, &api.PullRequest{ID: "THE-ID", Number: 123, Title: "title ", MergeStateStatus: "CLEAN"},
ghrepo.New("OWNER", "REPO"), ghrepo.New("OWNER", "REPO"),
), ),
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "", stdout.String()) assert.Equal(t, "", stdout.String())
assert.Equal(t, "✓ Squashed and merged pull request #123 (title)\n", stde rr.String()) assert.Equal(t, "✓ Squashed and merged pull request #123 (title)\n", stde rr.String())
} }
func TestPRMerge_interactiveCancelled(t *testing.T) { func TestPRMerge_interactiveCancelled(t *testing.T) {
http := initFakeHTTP() http := initFakeHTTP()
defer http.Verify(t) defer http.Verify(t)
shared.RunCommandFinder( shared.RunCommandFinder(
"", "",
&api.PullRequest{ID: "THE-ID", Number: 123}, &api.PullRequest{ID: "THE-ID", Number: 123, MergeStateStatus: "CL EAN"},
ghrepo.New("OWNER", "REPO"), ghrepo.New("OWNER", "REPO"),
) )
http.Register( http.Register(
httpmock.GraphQL(`query RepositoryInfo\b`), httpmock.GraphQL(`query RepositoryInfo\b`),
httpmock.StringResponse(` httpmock.StringResponse(`
{ "data": { "repository": { { "data": { "repository": {
"mergeCommitAllowed": true, "mergeCommitAllowed": true,
"rebaseMergeAllowed": true, "rebaseMergeAllowed": true,
"squashMergeAllowed": true "squashMergeAllowed": true
skipping to change at line 950 skipping to change at line 993
err := mergeRun(&MergeOptions{ err := mergeRun(&MergeOptions{
IO: io, IO: io,
HttpClient: func() (*http.Client, error) { HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: tr}, nil return &http.Client{Transport: tr}, nil
}, },
SelectorArg: "https://github.com/OWNER/REPO/pull/123", SelectorArg: "https://github.com/OWNER/REPO/pull/123",
AutoMergeEnable: true, AutoMergeEnable: true,
MergeMethod: PullRequestMergeMethodSquash, MergeMethod: PullRequestMergeMethodSquash,
Finder: shared.NewMockFinder( Finder: shared.NewMockFinder(
"https://github.com/OWNER/REPO/pull/123", "https://github.com/OWNER/REPO/pull/123",
&api.PullRequest{ID: "THE-ID", Number: 123}, &api.PullRequest{ID: "THE-ID", Number: 123, MergeStateSta tus: "BLOCKED"},
ghrepo.New("OWNER", "REPO"), ghrepo.New("OWNER", "REPO"),
), ),
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "", stdout.String()) assert.Equal(t, "", stdout.String())
assert.Equal(t, "✓ Pull request #123 will be automatically merged via squ ash when all requirements are met\n", stderr.String()) assert.Equal(t, "✓ Pull request #123 will be automatically merged via squ ash when all requirements are met\n", stderr.String())
} }
func TestMergeRun_autoMerge_directMerge(t *testing.T) {
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true)
io.SetStderrTTY(true)
tr := initFakeHTTP()
defer tr.Verify(t)
tr.Register(
httpmock.GraphQL(`mutation PullRequestMerge\b`),
httpmock.GraphQLMutation(`{}`, func(input map[string]interface{})
{
assert.Equal(t, "THE-ID", input["pullRequestId"].(string)
)
assert.Equal(t, "MERGE", input["mergeMethod"].(string))
assert.NotContains(t, input, "commitHeadline")
}))
_, cmdTeardown := run.Stub()
defer cmdTeardown(t)
err := mergeRun(&MergeOptions{
IO: io,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: tr}, nil
},
SelectorArg: "https://github.com/OWNER/REPO/pull/123",
AutoMergeEnable: true,
MergeMethod: PullRequestMergeMethodMerge,
Finder: shared.NewMockFinder(
"https://github.com/OWNER/REPO/pull/123",
&api.PullRequest{ID: "THE-ID", Number: 123, MergeStateSta
tus: "CLEAN"},
ghrepo.New("OWNER", "REPO"),
),
})
assert.NoError(t, err)
assert.Equal(t, "", stdout.String())
assert.Equal(t, "✓ Merged pull request #123 ()\n", stderr.String())
}
func TestMergeRun_disableAutoMerge(t *testing.T) { func TestMergeRun_disableAutoMerge(t *testing.T) {
io, _, stdout, stderr := iostreams.Test() io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(true) io.SetStdoutTTY(true)
io.SetStderrTTY(true) io.SetStderrTTY(true)
tr := initFakeHTTP() tr := initFakeHTTP()
defer tr.Verify(t) defer tr.Verify(t)
tr.Register( tr.Register(
httpmock.GraphQL(`mutation PullRequestAutoMergeDisable\b`), httpmock.GraphQL(`mutation PullRequestAutoMergeDisable\b`),
httpmock.GraphQLQuery(`{}`, func(s string, m map[string]interface {}) { httpmock.GraphQLQuery(`{}`, func(s string, m map[string]interface {}) {
 End of changes. 21 change blocks. 
60 lines changed or deleted 146 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)