@@ -15,7 +15,6 @@ import (
1515 "strings"
1616
1717 "github.com/MakeNowJust/heredoc"
18- "github.com/cli/cli/git"
1918 "github.com/cli/cli/internal/ghrepo"
2019 "github.com/cli/cli/pkg/cmdutil"
2120 "github.com/cli/cli/pkg/iostreams"
@@ -37,17 +36,17 @@ type ApiOptions struct {
3736 Paginate bool
3837 Silent bool
3938
40- HttpClient func () (* http.Client , error )
41- BaseRepo func () (ghrepo.Interface , error )
42- CurrentBranch func () (string , error )
39+ HttpClient func () (* http.Client , error )
40+ BaseRepo func () (ghrepo.Interface , error )
41+ Branch func () (string , error )
4342}
4443
4544func NewCmdApi (f * cmdutil.Factory , runF func (* ApiOptions ) error ) * cobra.Command {
4645 opts := ApiOptions {
47- IO : f .IOStreams ,
48- HttpClient : f .HttpClient ,
49- BaseRepo : f .BaseRepo ,
50- CurrentBranch : git . CurrentBranch ,
46+ IO : f .IOStreams ,
47+ HttpClient : f .HttpClient ,
48+ BaseRepo : f .BaseRepo ,
49+ Branch : f . Branch ,
5150 }
5251
5352 cmd := & cobra.Command {
@@ -302,27 +301,26 @@ func fillPlaceholders(value string, opts *ApiOptions) (string, error) {
302301 }
303302
304303 var branch string
305- if strings .Contains (value , ":branch" ) {
306- branch , err = opts .CurrentBranch ()
307- if err != nil {
308- return value , err
309- }
310- }
311304
312- value = placeholderRE .ReplaceAllStringFunc (value , func (m string ) string {
305+ filled : = placeholderRE .ReplaceAllStringFunc (value , func (m string ) string {
313306 switch m {
314307 case ":owner" :
315308 return baseRepo .RepoOwner ()
316309 case ":repo" :
317310 return baseRepo .RepoName ()
318311 case ":branch" :
312+ branch , err = opts .Branch ()
319313 return branch
320314 default :
321315 panic (fmt .Sprintf ("invalid placeholder: %q" , m ))
322316 }
323317 })
324318
325- return value , nil
319+ if err != nil {
320+ return value , err
321+ }
322+
323+ return filled , nil
326324}
327325
328326func printHeaders (w io.Writer , headers http.Header , colorize bool ) {
0 commit comments