mirror of
https://github.com/drone-plugins/drone-gitea-release.git
synced 2026-07-16 16:10:55 +08:00
Add title to release
Add note to release Signed-off-by: Jonas Franz <info@jonasfranz.de>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user