diff --git a/plugin.go b/plugin.go index 0e4ede7..480f1a7 100644 --- a/plugin.go +++ b/plugin.go @@ -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() diff --git a/release.go b/release.go index c0f61f0..3534082 100644 --- a/release.go +++ b/release.go @@ -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 } } - return nil, fmt.Errorf("Release %s not found", rc.Tag) + + 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) {