Add title to release
Add note to release Signed-off-by: Jonas Franz <info@jonasfranz.de>
This commit is contained in:
parent
88dc55b2e7
commit
27873f6980
16
main.go
16
main.go
@ -54,6 +54,18 @@ func main() {
|
||||
Usage: "url of the gitea instance",
|
||||
EnvVar: "PLUGIN_BASE_URL,GITEA_RELEASE_BASE_URL",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "note",
|
||||
Value: "",
|
||||
Usage: "file or string with notes for the release (example: changelog)",
|
||||
EnvVar: "PLUGIN_NOTE,GITEA_RELEASE_NOTE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "title",
|
||||
Value: "",
|
||||
Usage: "file or string for the title shown in the gitea release",
|
||||
EnvVar: "PLUGIN_TITLE,GITEA_RELEASE_TITLE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo.owner",
|
||||
Usage: "repository owner",
|
||||
@ -109,8 +121,10 @@ func run(c *cli.Context) error {
|
||||
FileExists: c.String("file-exists"),
|
||||
Checksum: c.StringSlice("checksum"),
|
||||
Draft: c.Bool("draft"),
|
||||
Prerelease: c.Bool("prerelease"),
|
||||
PreRelease: c.Bool("prerelease"),
|
||||
BaseURL: c.String("base-url"),
|
||||
Title: c.String("title"),
|
||||
Note: c.String("note"),
|
||||
},
|
||||
}
|
||||
|
||||
|
38
plugin.go
38
plugin.go
@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -28,8 +30,10 @@ type (
|
||||
FileExists string
|
||||
Checksum []string
|
||||
Draft bool
|
||||
Prerelease bool
|
||||
PreRelease bool
|
||||
BaseURL string
|
||||
Title string
|
||||
Note string
|
||||
}
|
||||
|
||||
Plugin struct {
|
||||
@ -65,6 +69,19 @@ func (p Plugin) Exec() error {
|
||||
p.Config.BaseURL = p.Config.BaseURL + "/"
|
||||
}
|
||||
|
||||
var err error
|
||||
if p.Config.Note != "" {
|
||||
if p.Config.Note, err = readStringOrFile(p.Config.Note); err != nil {
|
||||
return fmt.Errorf("error while reading %s: %v", p.Config.Note, err)
|
||||
}
|
||||
}
|
||||
|
||||
if p.Config.Title != "" {
|
||||
if p.Config.Title, err = readStringOrFile(p.Config.Title); err != nil {
|
||||
return fmt.Errorf("error while reading %s: %v", p.Config.Note, err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, glob := range p.Config.Files {
|
||||
globed, err := filepath.Glob(glob)
|
||||
|
||||
@ -97,8 +114,10 @@ func (p Plugin) Exec() error {
|
||||
Repo: p.Repo.Name,
|
||||
Tag: strings.TrimPrefix(p.Commit.Ref, "refs/tags/"),
|
||||
Draft: p.Config.Draft,
|
||||
Prerelease: p.Config.Prerelease,
|
||||
Prerelease: p.Config.PreRelease,
|
||||
FileExists: p.Config.FileExists,
|
||||
Title: p.Config.Title,
|
||||
Note: p.Config.Note,
|
||||
}
|
||||
|
||||
release, err := rc.buildRelease()
|
||||
@ -113,3 +132,18 @@ func (p Plugin) Exec() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func readStringOrFile(input string) (string, error) {
|
||||
// Check if input is a file path
|
||||
if _, err := os.Stat(input); err != nil && os.IsNotExist(err) {
|
||||
// No file found => use input as result
|
||||
return input, nil
|
||||
} else if err != nil {
|
||||
return "", err
|
||||
}
|
||||
result, err := ioutil.ReadFile(input)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(result), nil
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ type releaseClient struct {
|
||||
Draft bool
|
||||
Prerelease bool
|
||||
FileExists string
|
||||
Title string
|
||||
Note string
|
||||
}
|
||||
|
||||
func (rc *releaseClient) buildRelease() (*gitea.Release, error) {
|
||||
@ -56,9 +58,11 @@ func (rc *releaseClient) getRelease() (*gitea.Release, error) {
|
||||
|
||||
func (rc *releaseClient) newRelease() (*gitea.Release, error) {
|
||||
r := gitea.CreateReleaseOption{
|
||||
TagName: rc.Tag,
|
||||
TagName: rc.Tag,
|
||||
IsDraft: rc.Draft,
|
||||
IsPrerelease: rc.Prerelease,
|
||||
Title: rc.Title,
|
||||
Note: rc.Note,
|
||||
}
|
||||
|
||||
release, err := rc.Client.CreateRelease(rc.Owner, rc.Repo, r)
|
||||
|
Loading…
Reference in New Issue
Block a user