Support branches

This commit is contained in:
Anton Zadvorny 2020-05-08 02:54:27 +03:00
parent a3e29cee46
commit 14b428aed4
2 changed files with 17 additions and 9 deletions

View File

@ -82,6 +82,11 @@ func main() {
Usage: "repository name",
EnvVar: "DRONE_REPO_NAME",
},
cli.StringFlag{
Name: "repo.branch",
Usage: "repository branch",
EnvVar: "DRONE_REPO_BRANCH",
},
cli.StringFlag{
Name: "build.event",
Value: "push",
@ -114,6 +119,7 @@ func run(c *cli.Context) error {
Repo: Repo{
Owner: c.String("repo.owner"),
Name: c.String("repo.name"),
Branch: c.String("repo.branch"),
},
Build: Build{
Event: c.String("build.event"),

View File

@ -17,6 +17,7 @@ type (
Repo struct {
Owner string
Name string
Branch string
}
Build struct {
@ -53,10 +54,6 @@ func (p Plugin) Exec() error {
files []string
)
if p.Build.Event != "tag" {
return fmt.Errorf("The Gitea Release plugin is only available for tags")
}
if p.Config.APIKey == "" {
return fmt.Errorf("You must provide an API key")
}
@ -124,11 +121,16 @@ func (p Plugin) Exec() error {
client.SetHTTPClient(insecureClient)
}
tag := p.Repo.Branch
if p.Build.Event == "tag" {
tag = strings.TrimPrefix(p.Commit.Ref, "refs/tags/")
}
rc := releaseClient{
Client: client,
Owner: p.Repo.Owner,
Repo: p.Repo.Name,
Tag: strings.TrimPrefix(p.Commit.Ref, "refs/tags/"),
Tag: tag,
Draft: p.Config.Draft,
Prerelease: p.Config.PreRelease,
FileExists: p.Config.FileExists,