aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-06-03 14:13:58 +0800
committerGitHub <noreply@github.com>2022-06-03 02:13:58 -0400
commite09fb30d34d1bab8ec51afa16745ea2d546f9355 (patch)
tree8a2f9d12ff2808500d6fdbabd841a7e7c1a296cc /services
parent0c759fd4dee1c2a82ecdb0a6019d8ee78dae2209 (diff)
downloadgitea-e09fb30d34d1bab8ec51afa16745ea2d546f9355.tar.gz
gitea-e09fb30d34d1bab8ec51afa16745ea2d546f9355.zip
improvement some release related code (#19867)
Diffstat (limited to 'services')
-rw-r--r--services/release/release.go20
-rw-r--r--services/release/release_test.go8
-rw-r--r--services/repository/push.go2
3 files changed, 13 insertions, 17 deletions
diff --git a/services/release/release.go b/services/release/release.go
index 0372e3a690..b2cbceb12d 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -112,10 +112,10 @@ func createTag(gitRepo *git.Repository, rel *models.Release, msg string) (bool,
// CreateRelease creates a new release of repository.
func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs []string, msg string) error {
- isExist, err := models.IsReleaseExist(rel.RepoID, rel.TagName)
+ has, err := models.IsReleaseExist(gitRepo.Ctx, rel.RepoID, rel.TagName)
if err != nil {
return err
- } else if isExist {
+ } else if has {
return models.ErrReleaseAlreadyExist{
TagName: rel.TagName,
}
@@ -126,7 +126,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
}
rel.LowerTagName = strings.ToLower(rel.TagName)
- if err = models.InsertRelease(rel); err != nil {
+ if err = db.Insert(gitRepo.Ctx, rel); err != nil {
return err
}
@@ -143,10 +143,10 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
// CreateNewTag creates a new repository tag
func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, commit, tagName, msg string) error {
- isExist, err := models.IsReleaseExist(repo.ID, tagName)
+ has, err := models.IsReleaseExist(ctx, repo.ID, tagName)
if err != nil {
return err
- } else if isExist {
+ } else if has {
return models.ErrTagAlreadyExists{
TagName: tagName,
}
@@ -174,11 +174,7 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R
return err
}
- if err = models.InsertRelease(rel); err != nil {
- return err
- }
-
- return err
+ return db.Insert(ctx, rel)
}
// UpdateRelease updates information, attachments of a release and will create tag if it's not a draft and tag not exist.
@@ -286,12 +282,12 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *models.R
// DeleteReleaseByID deletes a release and corresponding Git tag by given ID.
func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, delTag bool) error {
- rel, err := models.GetReleaseByID(id)
+ rel, err := models.GetReleaseByID(ctx, id)
if err != nil {
return fmt.Errorf("GetReleaseByID: %v", err)
}
- repo, err := repo_model.GetRepositoryByID(rel.RepoID)
+ repo, err := repo_model.GetRepositoryByIDCtx(ctx, rel.RepoID)
if err != nil {
return fmt.Errorf("GetRepositoryByID: %v", err)
}
diff --git a/services/release/release_test.go b/services/release/release_test.go
index 823560a092..0f5b74f70d 100644
--- a/services/release/release_test.go
+++ b/services/release/release_test.go
@@ -162,7 +162,7 @@ func TestRelease_Update(t *testing.T) {
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
release.Note = "Changed note"
assert.NoError(t, UpdateRelease(user, gitRepo, release, nil, nil, nil))
- release, err = models.GetReleaseByID(release.ID)
+ release, err = models.GetReleaseByID(db.DefaultContext, release.ID)
assert.NoError(t, err)
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
@@ -186,7 +186,7 @@ func TestRelease_Update(t *testing.T) {
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
release.Title = "Changed title"
assert.NoError(t, UpdateRelease(user, gitRepo, release, nil, nil, nil))
- release, err = models.GetReleaseByID(release.ID)
+ release, err = models.GetReleaseByID(db.DefaultContext, release.ID)
assert.NoError(t, err)
assert.Less(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
@@ -211,7 +211,7 @@ func TestRelease_Update(t *testing.T) {
release.Title = "Changed title"
release.Note = "Changed note"
assert.NoError(t, UpdateRelease(user, gitRepo, release, nil, nil, nil))
- release, err = models.GetReleaseByID(release.ID)
+ release, err = models.GetReleaseByID(db.DefaultContext, release.ID)
assert.NoError(t, err)
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
@@ -236,7 +236,7 @@ func TestRelease_Update(t *testing.T) {
tagName := release.TagName
assert.NoError(t, UpdateRelease(user, gitRepo, release, nil, nil, nil))
- release, err = models.GetReleaseByID(release.ID)
+ release, err = models.GetReleaseByID(db.DefaultContext, release.ID)
assert.NoError(t, err)
assert.Equal(t, tagName, release.TagName)
diff --git a/services/repository/push.go b/services/repository/push.go
index 5ca8c73983..5e48a19ba8 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -399,7 +399,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
}
if len(newReleases) > 0 {
- if err = models.InsertReleasesContext(ctx, newReleases); err != nil {
+ if err = db.Insert(ctx, newReleases); err != nil {
return fmt.Errorf("Insert: %v", err)
}
}