@@ -15,6 +15,7 @@ import (
1515 "strings"
1616
1717 "github.com/MakeNowJust/heredoc"
18+ "github.com/cli/cli/git"
1819 "github.com/cli/cli/internal/ghrepo"
1920 "github.com/cli/cli/pkg/cmdutil"
2021 "github.com/cli/cli/pkg/iostreams"
@@ -36,15 +37,17 @@ type ApiOptions struct {
3637 Paginate bool
3738 Silent bool
3839
39- HttpClient func () (* http.Client , error )
40- BaseRepo func () (ghrepo.Interface , error )
40+ HttpClient func () (* http.Client , error )
41+ BaseRepo func () (ghrepo.Interface , error )
42+ CurrentBranch func () (string , error )
4143}
4244
4345func NewCmdApi (f * cmdutil.Factory , runF func (* ApiOptions ) error ) * cobra.Command {
4446 opts := ApiOptions {
45- IO : f .IOStreams ,
46- HttpClient : f .HttpClient ,
47- BaseRepo : f .BaseRepo ,
47+ IO : f .IOStreams ,
48+ HttpClient : f .HttpClient ,
49+ BaseRepo : f .BaseRepo ,
50+ CurrentBranch : git .CurrentBranch ,
4851 }
4952
5053 cmd := & cobra.Command {
@@ -285,7 +288,7 @@ func processResponse(resp *http.Response, opts *ApiOptions, headersOutputStream
285288 return
286289}
287290
288- var placeholderRE = regexp .MustCompile (`\:(owner|repo)\b` )
291+ var placeholderRE = regexp .MustCompile (`\:(owner|repo|branch )\b` )
289292
290293// fillPlaceholders populates `:owner` and `:repo` placeholders with values from the current repository
291294func fillPlaceholders (value string , opts * ApiOptions ) (string , error ) {
@@ -304,6 +307,12 @@ func fillPlaceholders(value string, opts *ApiOptions) (string, error) {
304307 return baseRepo .RepoOwner ()
305308 case ":repo" :
306309 return baseRepo .RepoName ()
310+ case ":branch" :
311+ branch , err := opts .CurrentBranch ()
312+ if err != nil {
313+ panic (err )
314+ }
315+ return branch
307316 default :
308317 panic (fmt .Sprintf ("invalid placeholder: %q" , m ))
309318 }
0 commit comments