aboutsummaryrefslogtreecommitdiffstats
path: root/services/release/release.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-01-19 23:26:57 +0000
committerGitHub <noreply@github.com>2022-01-19 23:26:57 +0000
commit5cb0c9aa0d7eed087055b1efca79628957207d36 (patch)
treed117a514e1f17e5f6bfcda1be273f6a971112663 /services/release/release.go
parent4563148a61ba892e8f2bb66342f00a950bcd5315 (diff)
downloadgitea-5cb0c9aa0d7eed087055b1efca79628957207d36.tar.gz
gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.zip
Propagate context and ensure git commands run in request context (#17868)
This PR continues the work in #17125 by progressively ensuring that git commands run within the request context. This now means that the if there is a git repo already open in the context it will be used instead of reopening it. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/release/release.go')
-rw-r--r--services/release/release.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/services/release/release.go b/services/release/release.go
index 5fa506bc61..aebf79edc3 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -5,6 +5,7 @@
package release
import (
+ "context"
"errors"
"fmt"
"strings"
@@ -83,7 +84,7 @@ func createTag(gitRepo *git.Repository, rel *models.Release, msg string) (bool,
OldCommitID: git.EmptySHA,
NewCommitID: commit.ID.String(),
}, commits)
- notification.NotifyCreateRef(rel.Publisher, rel.Repo, "tag", git.TagPrefix+rel.TagName)
+ notification.NotifyCreateRef(rel.Publisher, rel.Repo, "tag", git.TagPrefix+rel.TagName, commit.ID.String())
rel.CreatedUnix = timeutil.TimeStampNow()
}
commit, err := gitRepo.GetTagCommit(rel.TagName)
@@ -141,7 +142,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
}
// CreateNewTag creates a new repository tag
-func CreateNewTag(doer *user_model.User, repo *repo_model.Repository, commit, tagName, msg string) error {
+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)
if err != nil {
return err
@@ -151,11 +152,11 @@ func CreateNewTag(doer *user_model.User, repo *repo_model.Repository, commit, ta
}
}
- gitRepo, err := git.OpenRepository(repo.RepoPath())
+ gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
if err != nil {
return err
}
- defer gitRepo.Close()
+ defer closer.Close()
rel := &models.Release{
RepoID: repo.ID,
@@ -283,7 +284,7 @@ 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(id int64, doer *user_model.User, delTag bool) error {
+func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, delTag bool) error {
rel, err := models.GetReleaseByID(id)
if err != nil {
return fmt.Errorf("GetReleaseByID: %v", err)
@@ -295,7 +296,7 @@ func DeleteReleaseByID(id int64, doer *user_model.User, delTag bool) error {
}
if delTag {
- if stdout, err := git.NewCommand("tag", "-d", rel.TagName).
+ if stdout, err := git.NewCommandContext(ctx, "tag", "-d", rel.TagName).
SetDescription(fmt.Sprintf("DeleteReleaseByID (git tag -d): %d", rel.ID)).
RunInDir(repo.RepoPath()); err != nil && !strings.Contains(err.Error(), "not found") {
log.Error("DeleteReleaseByID (git tag -d): %d in %v Failed:\nStdout: %s\nError: %v", rel.ID, repo, stdout, err)