|
|
|
@ -7,13 +7,10 @@ package models
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"sort"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/git"
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
|
"code.gitea.io/gitea/modules/process"
|
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
|
|
|
@ -319,70 +316,10 @@ func SortReleases(rels []*Release) {
|
|
|
|
|
sort.Sort(sorter)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteReleaseByID deletes a release and corresponding Git tag by given ID.
|
|
|
|
|
func DeleteReleaseByID(id int64, doer *User, delTag bool) error {
|
|
|
|
|
rel, err := GetReleaseByID(id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("GetReleaseByID: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
repo, err := GetRepositoryByID(rel.RepoID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("GetRepositoryByID: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if delTag {
|
|
|
|
|
_, stderr, err := process.GetManager().ExecDir(-1, repo.RepoPath(),
|
|
|
|
|
fmt.Sprintf("DeleteReleaseByID (git tag -d): %d", rel.ID),
|
|
|
|
|
git.GitExecutable, "tag", "-d", rel.TagName)
|
|
|
|
|
if err != nil && !strings.Contains(stderr, "not found") {
|
|
|
|
|
return fmt.Errorf("git tag -d: %v - %s", err, stderr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, err = x.ID(rel.ID).Delete(new(Release)); err != nil {
|
|
|
|
|
return fmt.Errorf("Delete: %v", err)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rel.IsTag = true
|
|
|
|
|
rel.IsDraft = false
|
|
|
|
|
rel.IsPrerelease = false
|
|
|
|
|
rel.Title = ""
|
|
|
|
|
rel.Note = ""
|
|
|
|
|
|
|
|
|
|
if _, err = x.ID(rel.ID).AllCols().Update(rel); err != nil {
|
|
|
|
|
return fmt.Errorf("Update: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rel.Repo = repo
|
|
|
|
|
if err = rel.LoadAttributes(); err != nil {
|
|
|
|
|
return fmt.Errorf("LoadAttributes: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, err := x.Delete(&Attachment{ReleaseID: id}); err != nil {
|
|
|
|
|
// DeleteReleaseByID deletes a release from database by given ID.
|
|
|
|
|
func DeleteReleaseByID(id int64) error {
|
|
|
|
|
_, err := x.ID(id).Delete(new(Release))
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := range rel.Attachments {
|
|
|
|
|
attachment := rel.Attachments[i]
|
|
|
|
|
if err := os.RemoveAll(attachment.LocalPath()); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mode, _ := AccessLevel(doer, rel.Repo)
|
|
|
|
|
if err := PrepareWebhooks(rel.Repo, HookEventRelease, &api.ReleasePayload{
|
|
|
|
|
Action: api.HookReleaseDeleted,
|
|
|
|
|
Release: rel.APIFormat(),
|
|
|
|
|
Repository: rel.Repo.APIFormat(mode),
|
|
|
|
|
Sender: doer.APIFormat(),
|
|
|
|
|
}); err != nil {
|
|
|
|
|
log.Error("PrepareWebhooks: %v", err)
|
|
|
|
|
} else {
|
|
|
|
|
go HookQueue.Add(rel.Repo.ID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SyncReleasesWithTags synchronizes release table with repository tags
|
|
|
|
|