X Tutup
Skip to content

Commit 73da25a

Browse files
committed
Use concrete type instead of an interface to avoid forced casting
1 parent 28c2d04 commit 73da25a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

pkg/cmd/pr/create/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type CreateContext struct {
6161
// This struct stores contextual data about the creation process and is for building up enough
6262
// data to create a pull request
6363
RepoContext *context.ResolvedRemotes
64-
BaseRepo ghrepo.Interface
64+
BaseRepo *api.Repository
6565
HeadRepo ghrepo.Interface
6666
BaseTrackingBranch string
6767
BaseBranch string
@@ -264,7 +264,7 @@ func createRun(opts *CreateOptions) (err error) {
264264
}
265265
}
266266

267-
allowMetadata := ctx.BaseRepo.(*api.Repository).ViewerCanTriage()
267+
allowMetadata := ctx.BaseRepo.ViewerCanTriage()
268268
action, err := shared.ConfirmSubmission(!state.HasMetadata(), allowMetadata)
269269
if err != nil {
270270
return fmt.Errorf("unable to confirm: %w", err)
@@ -597,7 +597,7 @@ func submitPR(opts CreateOptions, ctx CreateContext, state shared.IssueMetadataS
597597
}
598598

599599
opts.IO.StartProgressIndicator()
600-
pr, err := api.CreatePullRequest(client, ctx.BaseRepo.(*api.Repository), params)
600+
pr, err := api.CreatePullRequest(client, ctx.BaseRepo, params)
601601
opts.IO.StopProgressIndicator()
602602
if pr != nil {
603603
fmt.Fprintln(opts.IO.Out, pr.URL)

pkg/cmd/pr/create/create_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212

1313
"github.com/MakeNowJust/heredoc"
14+
"github.com/cli/cli/api"
1415
"github.com/cli/cli/context"
1516
"github.com/cli/cli/git"
1617
"github.com/cli/cli/internal/config"
@@ -873,7 +874,7 @@ func Test_generateCompareURL(t *testing.T) {
873874
{
874875
name: "basic",
875876
ctx: CreateContext{
876-
BaseRepo: ghrepo.New("OWNER", "REPO"),
877+
BaseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"),
877878
BaseBranch: "main",
878879
HeadBranchLabel: "feature",
879880
},
@@ -883,7 +884,7 @@ func Test_generateCompareURL(t *testing.T) {
883884
{
884885
name: "with labels",
885886
ctx: CreateContext{
886-
BaseRepo: ghrepo.New("OWNER", "REPO"),
887+
BaseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"),
887888
BaseBranch: "a",
888889
HeadBranchLabel: "b",
889890
},
@@ -896,7 +897,7 @@ func Test_generateCompareURL(t *testing.T) {
896897
{
897898
name: "complex branch names",
898899
ctx: CreateContext{
899-
BaseRepo: ghrepo.New("OWNER", "REPO"),
900+
BaseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"),
900901
BaseBranch: "main/trunk",
901902
HeadBranchLabel: "owner:feature",
902903
},

0 commit comments

Comments
 (0)
X Tutup