Delete release and create new one if build event is not tag
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Anton Zadvorny 2020-05-08 03:24:56 +03:00
parent dd743c2de9
commit 2cc57167b8
2 changed files with 19 additions and 2 deletions

View File

@ -136,6 +136,7 @@ func (p Plugin) Exec() error {
FileExists: p.Config.FileExists,
Title: p.Config.Title,
Note: p.Config.Note,
Event: p.Build.Event,
}
release, err := rc.buildRelease()

View File

@ -19,6 +19,7 @@ type releaseClient struct {
FileExists string
Title string
Note string
Event string
}
func (rc *releaseClient) buildRelease() (*gitea.Release, error) {
@ -47,13 +48,28 @@ func (rc *releaseClient) getRelease() (*gitea.Release, error) {
return nil, err
}
var r *gitea.Release
for _, release := range releases {
if release.TagName == rc.Tag {
fmt.Printf("Successfully retrieved %s release\n", rc.Tag)
return release, nil
r = release
}
}
if r == nil {
return nil, fmt.Errorf("Release %s not found", rc.Tag)
}
if rc.Event != "tag" {
if err := rc.Client.DeleteRelease(rc.Owner, rc.Repo, r.ID); err != nil {
return nil, fmt.Errorf("Failed to delete a release: %s", err)
}
fmt.Printf("Successfully deleted %s release", rc.Tag)
return nil, nil
}
return r, nil
}
func (rc *releaseClient) newRelease() (*gitea.Release, error) {