Use concrete type instead of an interface to avoid forced casting

This commit is contained in:
Mislav Marohnić 2021-01-22 21:57:46 +01:00
parent 28c2d042e7
commit 73da25a96d
2 changed files with 7 additions and 6 deletions

View file

@ -61,7 +61,7 @@ type CreateContext struct {
// This struct stores contextual data about the creation process and is for building up enough
// data to create a pull request
RepoContext *context.ResolvedRemotes
BaseRepo ghrepo.Interface
BaseRepo *api.Repository
HeadRepo ghrepo.Interface
BaseTrackingBranch string
BaseBranch string
@ -264,7 +264,7 @@ func createRun(opts *CreateOptions) (err error) {
}
}
allowMetadata := ctx.BaseRepo.(*api.Repository).ViewerCanTriage()
allowMetadata := ctx.BaseRepo.ViewerCanTriage()
action, err := shared.ConfirmSubmission(!state.HasMetadata(), allowMetadata)
if err != nil {
return fmt.Errorf("unable to confirm: %w", err)
@ -597,7 +597,7 @@ func submitPR(opts CreateOptions, ctx CreateContext, state shared.IssueMetadataS
}
opts.IO.StartProgressIndicator()
pr, err := api.CreatePullRequest(client, ctx.BaseRepo.(*api.Repository), params)
pr, err := api.CreatePullRequest(client, ctx.BaseRepo, params)
opts.IO.StopProgressIndicator()
if pr != nil {
fmt.Fprintln(opts.IO.Out, pr.URL)

View file

@ -11,6 +11,7 @@ import (
"testing"
"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/api"
"github.com/cli/cli/context"
"github.com/cli/cli/git"
"github.com/cli/cli/internal/config"
@ -873,7 +874,7 @@ func Test_generateCompareURL(t *testing.T) {
{
name: "basic",
ctx: CreateContext{
BaseRepo: ghrepo.New("OWNER", "REPO"),
BaseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"),
BaseBranch: "main",
HeadBranchLabel: "feature",
},
@ -883,7 +884,7 @@ func Test_generateCompareURL(t *testing.T) {
{
name: "with labels",
ctx: CreateContext{
BaseRepo: ghrepo.New("OWNER", "REPO"),
BaseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"),
BaseBranch: "a",
HeadBranchLabel: "b",
},
@ -896,7 +897,7 @@ func Test_generateCompareURL(t *testing.T) {
{
name: "complex branch names",
ctx: CreateContext{
BaseRepo: ghrepo.New("OWNER", "REPO"),
BaseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"),
BaseBranch: "main/trunk",
HeadBranchLabel: "owner:feature",
},