From ac29e29e79651ab24da565e3edaa556b9207585f Mon Sep 17 00:00:00 2001 From: Anton Zadvorny Date: Fri, 8 May 2020 02:54:27 +0300 Subject: [PATCH] Support branches --- main.go | 10 ++++++++-- plugin.go | 16 +++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index be98125..ce3f88a 100644 --- a/main.go +++ b/main.go @@ -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", @@ -112,8 +117,9 @@ func run(c *cli.Context) error { plugin := Plugin{ Repo: Repo{ - Owner: c.String("repo.owner"), - Name: c.String("repo.name"), + Owner: c.String("repo.owner"), + Name: c.String("repo.name"), + Branch: c.String("repo.branch"), }, Build: Build{ Event: c.String("build.event"), diff --git a/plugin.go b/plugin.go index b59dfcc..0e4ede7 100644 --- a/plugin.go +++ b/plugin.go @@ -15,8 +15,9 @@ import ( type ( Repo struct { - Owner string - Name string + 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,