Skip to content

Commit

Permalink
Use a list of releases in the template printer
Browse files Browse the repository at this point in the history
This makes the template output more flexible; e.g. it is possible to
display only the first item of a release list (i.e. the latest release
of a project) if there are more than one with "{{with index . 0}}"...
  • Loading branch information
McKael committed Apr 7, 2018
1 parent 4895a2b commit 8cde8e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions gh/printer/templateprinter.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,16 @@ func (p *TemplatePrinter) PrintReleases(rr []gh.ReleaseList) error {
}

for _, rl := range rr {
for _, r := range rl {
data, err := json.Marshal(r)
if err != nil {
return err
}
out := map[string]interface{}{}
if err := json.Unmarshal(data, &out); err != nil {
return err
}
if err = p.safeExecute(os.Stdout, out); err != nil {
return fmt.Errorf("error executing template %q: %v", p.rawTemplate, err)
}
data, err := json.Marshal(rl)
if err != nil {
return err
}
out := []map[string]interface{}{}
if err := json.Unmarshal(data, &out); err != nil {
return err
}
if err = p.safeExecute(os.Stdout, out); err != nil {
return fmt.Errorf("error executing template %q: %v", p.rawTemplate, err)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion ghreleasechecker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ printer:
show_body: false
template_printer:
color_mode: 'auto'
template: '{{color ",,bold"}}{{.repo}}{{color "reset"}} {{color "red"}}{{.version}}{{color "reset"}} {{.tag}} {{.publish_date | tolocal}}{{"\n"}}'
template: '{{range .}}{{color ",,bold"}}{{.repo}}{{color "reset"}} {{color "red"}}{{.version}}{{color "reset"}} {{.tag}} {{.publish_date | tolocal}}{{"\n"}}{{end}}'
...

0 comments on commit 8cde8e2

Please sign in to comment.