Return nil instead of empty objects when err
This commit is contained in:
parent
b6cdbc9e22
commit
291370824b
3 changed files with 9 additions and 9 deletions
|
|
@ -1422,15 +1422,15 @@ func RepoLicenses(httpClient *http.Client, hostname string) ([]License, error) {
|
|||
|
||||
// RepoLicense fetches an available repository license.
|
||||
// It uses API v3 because licenses are not supported by GraphQL.
|
||||
func RepoLicense(httpClient *http.Client, hostname string, licenseName string) (License, error) {
|
||||
func RepoLicense(httpClient *http.Client, hostname string, licenseName string) (*License, error) {
|
||||
var license License
|
||||
client := NewClientFromHTTP(httpClient)
|
||||
path := fmt.Sprintf("licenses/%s", licenseName)
|
||||
err := client.REST(hostname, "GET", path, nil, &license)
|
||||
if err != nil {
|
||||
return License{}, err
|
||||
return nil, err
|
||||
}
|
||||
return license, nil
|
||||
return &license, nil
|
||||
}
|
||||
|
||||
// RepoGitIgnoreTemplates fetches available repository gitignore templates.
|
||||
|
|
@ -1440,20 +1440,20 @@ func RepoGitIgnoreTemplates(httpClient *http.Client, hostname string) ([]string,
|
|||
client := NewClientFromHTTP(httpClient)
|
||||
err := client.REST(hostname, "GET", "gitignore/templates", nil, &gitIgnoreTemplates)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
return nil, err
|
||||
}
|
||||
return gitIgnoreTemplates, nil
|
||||
}
|
||||
|
||||
// RepoGitIgnoreTemplate fetches an available repository gitignore template.
|
||||
// It uses API v3 here because gitignore template isn't supported by GraphQL.
|
||||
func RepoGitIgnoreTemplate(httpClient *http.Client, hostname string, gitIgnoreTemplateName string) (GitIgnore, error) {
|
||||
func RepoGitIgnoreTemplate(httpClient *http.Client, hostname string, gitIgnoreTemplateName string) (*GitIgnore, error) {
|
||||
var gitIgnoreTemplate GitIgnore
|
||||
client := NewClientFromHTTP(httpClient)
|
||||
path := fmt.Sprintf("gitignore/templates/%s", gitIgnoreTemplateName)
|
||||
err := client.REST(hostname, "GET", path, nil, &gitIgnoreTemplate)
|
||||
if err != nil {
|
||||
return GitIgnore{}, err
|
||||
return nil, err
|
||||
}
|
||||
return gitIgnoreTemplate, nil
|
||||
return &gitIgnoreTemplate, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ func viewRun(opts *ViewOptions) error {
|
|||
return renderGitIgnore(gitIgnore, opts)
|
||||
}
|
||||
|
||||
func renderGitIgnore(licenseTemplate api.GitIgnore, opts *ViewOptions) error {
|
||||
func renderGitIgnore(licenseTemplate *api.GitIgnore, opts *ViewOptions) error {
|
||||
// I wanted to render this in a markdown code block and benefit
|
||||
// from .gitignore syntax highlighting. But, the upstream syntax highlighter
|
||||
// does not currently support .gitignore.
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ func viewRun(opts *ViewOptions) error {
|
|||
return renderLicense(license, opts)
|
||||
}
|
||||
|
||||
func renderLicense(license api.License, opts *ViewOptions) error {
|
||||
func renderLicense(license *api.License, opts *ViewOptions) error {
|
||||
cs := opts.IO.ColorScheme()
|
||||
var out strings.Builder
|
||||
if opts.IO.IsStdoutTTY() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue