in commands/api/api.go [358:413]
func fillPlaceholders(value string, opts *ApiOptions) (string, error) {
if !placeholderRE.MatchString(value) {
return value, nil
}
baseRepo, err := opts.BaseRepo()
if err != nil {
return value, err
}
filled := placeholderRE.ReplaceAllStringFunc(value, func(m string) string {
switch m {
case ":id":
h, _ := opts.HttpClient()
project, e := baseRepo.Project(h)
if e == nil && project != nil {
return strconv.Itoa(project.ID)
}
err = e
return ""
case ":group/:namespace/:repo", ":fullpath":
return url.PathEscape(baseRepo.FullName())
case ":namespace/:repo":
return url.PathEscape(baseRepo.RepoNamespace() + "/" + baseRepo.RepoName())
case ":group":
return baseRepo.RepoGroup()
case ":user", ":username":
h, _ := opts.HttpClient()
u, e := api.CurrentUser(h)
if e == nil && u != nil {
return u.Username
}
err = e
return m
case ":namespace":
return baseRepo.RepoNamespace()
case ":repo":
return baseRepo.RepoName()
case ":branch":
branch, e := opts.Branch()
if e != nil {
err = e
}
return branch
default:
err = fmt.Errorf("invalid placeholder: %q", m)
return ""
}
})
if err != nil {
return value, err
}
return filled, nil
}