summaryrefslogtreecommitdiffstats
path: root/models/release.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-10-01 00:10:00 +0800
committerGitHub <noreply@github.com>2019-10-01 00:10:00 +0800
commit3249c0ccba5b3082fe60f4b571159016db6d57d7 (patch)
tree300f96f564ad68833a439c765defe347fbbcb350 /models/release.go
parentecd4bfd2844346e0f2af795d9815e2224556ef47 (diff)
downloadgitea-3249c0ccba5b3082fe60f4b571159016db6d57d7.tar.gz
gitea-3249c0ccba5b3082fe60f4b571159016db6d57d7.zip
Extract actions on deletereleasebyid from models to release service (#8219)
* extract actions on deletereleasebyid from models to release service * fix tests
Diffstat (limited to 'models/release.go')
-rw-r--r--models/release.go71
1 files changed, 4 insertions, 67 deletions
diff --git a/models/release.go b/models/release.go
index 85a758becf..3729a6f690 100644
--- a/models/release.go
+++ b/models/release.go
@@ -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 {
- 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
+// DeleteReleaseByID deletes a release from database by given ID.
+func DeleteReleaseByID(id int64) error {
+ _, err := x.ID(id).Delete(new(Release))
+ return err
}
// SyncReleasesWithTags synchronizes release table with repository tags