Add template filepath for release tool

This allows a project to have a TEMPLATE file in the root of the repo to
be used with the release tool.  If they don't have this file and did not
specify a custom file then it will use the compiled in template in the
release tool.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-10-30 13:15:56 -04:00
parent 5fb3a0e0cf
commit adc502b790
3 changed files with 37 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -13,6 +14,7 @@ import (
"strings"
"github.com/BurntSushi/toml"
"github.com/urfave/cli"
)
func loadRelease(path string) (*release, error) {
@@ -163,3 +165,23 @@ func getContributors(previous, commit string) ([]string, error) {
sort.Strings(out)
return out, nil
}
// getTemplate will use a builtin template if the template is not specified on the cli
func getTemplate(context *cli.Context) (string, error) {
path := context.GlobalString("template")
f, err := os.Open(path)
if err != nil {
// if the template file does not exist and the path is for the default template then
// return the compiled in template
if os.IsNotExist(err) && path == defaultTemplateFile {
return releaseNotes, nil
}
return "", err
}
defer f.Close()
data, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}
return string(data), nil
}