test(pr create): test --head=<remote>:<branch>

This commit is contained in:
Kynan Ware 2025-02-27 10:23:52 -07:00
parent 6db9048557
commit dc486258cb
2 changed files with 27 additions and 1 deletions

View file

@ -629,7 +629,6 @@ func NewCreateContext(opts *CreateOptions) (*CreateContext, error) {
isPushEnabled = false
// If the --head provided contains a colon, that means
// this is <remote>:<branch> syntax.
// TODO KW: write test for this syntax.
if idx := strings.IndexRune(headBranch, ':'); idx >= 0 {
headBranch = headBranch[idx+1:]
}

View file

@ -1555,6 +1555,33 @@ func Test_createRun(t *testing.T) {
expectedOut: "https://github.com/OWNER/REPO/pull/12\n",
expectedErrOut: "\nCreating pull request for monalisa:task1 into feature/feat2 in OWNER/REPO\n\n",
},
{
name: "--head contains <remote>:<branch> syntax",
httpStubs: func(reg *httpmock.Registry, t *testing.T) {
reg.Register(
httpmock.GraphQL(`mutation PullRequestCreate\b`),
httpmock.GraphQLMutation(`
{ "data": { "createPullRequest": { "pullRequest": {
"URL": "https://github.com/OWNER/REPO/pull/12"
} } } }`,
func(input map[string]interface{}) {
assert.Equal(t, "REPOID", input["repositoryId"])
assert.Equal(t, "my title", input["title"])
assert.Equal(t, "my body", input["body"])
assert.Equal(t, "master", input["baseRefName"])
assert.Equal(t, "otherowner:feature", input["headRefName"])
}))
},
setup: func(opts *CreateOptions, t *testing.T) func() {
opts.TitleProvided = true
opts.BodyProvided = true
opts.Title = "my title"
opts.Body = "my body"
opts.HeadBranch = "otherowner:feature"
return func() {}
},
expectedOut: "https://github.com/OWNER/REPO/pull/12\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {