mirror of
https://github.com/harness/drone.git
synced 2025-05-10 22:21:22 +08:00
fix: Update CreateTagRequest to include tagger details
This commit is contained in:
parent
d3991994fe
commit
a06e6e223e
@ -14,10 +14,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/harness/gitness/gitrpc/internal/types"
|
||||
"github.com/harness/gitness/gitrpc/rpc"
|
||||
|
||||
gitea "code.gitea.io/gitea/modules/git"
|
||||
"github.com/harness/gitness/gitrpc/internal/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -65,10 +63,13 @@ func (g Adapter) GetAnnotatedTags(ctx context.Context, repoPath string, shas []s
|
||||
func (g Adapter) CreateAnnotatedTag(
|
||||
ctx context.Context,
|
||||
repoPath string,
|
||||
request *rpc.CreateTagRequest,
|
||||
env []string,
|
||||
request *types.CreateTagRequest,
|
||||
) error {
|
||||
cmd := gitea.NewCommand(ctx, "tag", "-a", "-m", request.GetMessage(), "--", request.GetTagName(), request.GetSha())
|
||||
cmd := gitea.NewCommand(ctx, "tag", "-a", "-m", request.Message, "--", request.Name, request.TargetSha)
|
||||
env := []string{
|
||||
"GIT_COMMITTER_NAME=" + request.TaggerName,
|
||||
"GIT_COMMITTER_EMAIL=" + request.TaggerEmail,
|
||||
}
|
||||
_, _, err := cmd.RunStdString(&gitea.RunOpts{Dir: repoPath, Env: env})
|
||||
if err != nil {
|
||||
return processGiteaErrorf(err, "Service failed to create a tag")
|
||||
@ -76,15 +77,6 @@ func (g Adapter) CreateAnnotatedTag(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g Adapter) DeleteTag(ctx context.Context, repoPath string, ref string, env []string) error {
|
||||
cmd := gitea.NewCommand(ctx, "tag", "-d", ref)
|
||||
_, stdErr, err := cmd.RunStdString(&gitea.RunOpts{Dir: repoPath, Env: env})
|
||||
if err != nil {
|
||||
return processGiteaErrorf(err, "Service failed to delete tag with error: %v", stdErr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// giteaGetAnnotatedTag is a custom implementation to retrieve an annotated tag from a sha.
|
||||
// The code is following parts of the gitea implementation.
|
||||
//
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/harness/gitness/gitrpc/enum"
|
||||
"github.com/harness/gitness/gitrpc/internal/types"
|
||||
"github.com/harness/gitness/gitrpc/rpc"
|
||||
)
|
||||
|
||||
// GitAdapter for accessing git commands from gitea.
|
||||
@ -40,8 +39,7 @@ type GitAdapter interface {
|
||||
GetFullCommitID(ctx context.Context, repoPath, shortID string) (string, error)
|
||||
GetAnnotatedTag(ctx context.Context, repoPath string, sha string) (*types.Tag, error)
|
||||
GetAnnotatedTags(ctx context.Context, repoPath string, shas []string) ([]types.Tag, error)
|
||||
CreateAnnotatedTag(ctx context.Context, repoPath string, request *rpc.CreateTagRequest, env []string) error
|
||||
DeleteTag(ctx context.Context, repoPath string, ref string, env []string) error
|
||||
CreateAnnotatedTag(ctx context.Context, repoPath string, request *types.CreateTagRequest) error
|
||||
GetBranch(ctx context.Context, repoPath string, branchName string) (*types.Branch, error)
|
||||
GetCommitDivergences(ctx context.Context, repoPath string,
|
||||
requests []types.CommitDivergenceRequest, max int32) ([]types.CommitDivergence, error)
|
||||
|
@ -321,6 +321,12 @@ func (r *SharedRepo) PushTag(ctx context.Context, writeRequest *rpc.WriteRequest
|
||||
return r.push(ctx, writeRequest, refTag, refTag)
|
||||
}
|
||||
|
||||
func (r *SharedRepo) PushDeleteTag(ctx context.Context, writeRequest *rpc.WriteRequest,
|
||||
tagName string) error {
|
||||
refTag := GetReferenceFromTagName(tagName)
|
||||
return r.push(ctx, writeRequest, "", refTag)
|
||||
}
|
||||
|
||||
// push pushes the provided references to the provided branch in the original repository.
|
||||
func (r *SharedRepo) push(ctx context.Context, writeRequest *rpc.WriteRequest,
|
||||
sourceRef, destinationRef string) error {
|
||||
|
@ -200,7 +200,6 @@ func (s ReferenceService) CreateTag(
|
||||
if err != nil {
|
||||
return nil, processGitErrorf(err, "failed to open repo")
|
||||
}
|
||||
defer repo.Close()
|
||||
|
||||
sharedRepo, err := NewSharedRepo(s.tmpDir, base.GetRepoUid(), repo)
|
||||
if err != nil {
|
||||
@ -214,12 +213,14 @@ func (s ReferenceService) CreateTag(
|
||||
return nil, processGitErrorf(err, "failed to clone shared repo with branch '%s'", request.GetSha())
|
||||
}
|
||||
actor := request.GetBase().GetActor()
|
||||
env := append(CreateEnvironmentForPush(ctx, base),
|
||||
"GIT_COMMITTER_NAME="+actor.GetName(),
|
||||
"GIT_COMMITTER_EMAIL="+actor.GetEmail(),
|
||||
)
|
||||
|
||||
err = s.adapter.CreateAnnotatedTag(ctx, sharedRepo.repo.Path, request, env)
|
||||
createTagRequest := types.CreateTagRequest{
|
||||
Name: request.GetTagName(),
|
||||
TargetSha: request.GetSha(),
|
||||
Message: request.GetMessage(),
|
||||
TaggerEmail: actor.GetEmail(),
|
||||
TaggerName: actor.GetName(),
|
||||
}
|
||||
err = s.adapter.CreateAnnotatedTag(ctx, sharedRepo.tmpPath, &createTagRequest)
|
||||
|
||||
if err != nil {
|
||||
return nil, processGitErrorf(err, "Failed to create tag %s - %s", request.GetTagName(), err.Error())
|
||||
@ -253,7 +254,6 @@ func (s ReferenceService) DeleteTag(
|
||||
if err != nil {
|
||||
return nil, processGitErrorf(err, "failed to open repo")
|
||||
}
|
||||
defer repo.Close()
|
||||
|
||||
sharedRepo, err := NewSharedRepo(s.tmpDir, base.GetRepoUid(), repo)
|
||||
if err != nil {
|
||||
@ -262,22 +262,12 @@ func (s ReferenceService) DeleteTag(
|
||||
|
||||
defer sharedRepo.Close(ctx)
|
||||
|
||||
err = sharedRepo.Clone(ctx, "")
|
||||
err = sharedRepo.Clone(ctx, request.GetTagName())
|
||||
if err != nil {
|
||||
return nil, processGitErrorf(err, "failed to clone shared repo with tag '%s'", request.GetTagName())
|
||||
}
|
||||
actor := request.GetBase().GetActor()
|
||||
env := append(CreateEnvironmentForPush(ctx, base),
|
||||
"GIT_COMMITTER_NAME="+actor.GetName(),
|
||||
"GIT_COMMITTER_EMAIL="+actor.GetEmail(),
|
||||
)
|
||||
|
||||
err = s.adapter.DeleteTag(ctx, repoPath, request.TagName, env)
|
||||
if err != nil {
|
||||
return nil, processGitErrorf(err, "Failed to delete tag '%s' from remote repo", request.GetTagName())
|
||||
}
|
||||
|
||||
if err = sharedRepo.push(ctx, base, "", GetReferenceFromTagName(request.GetTagName())); err != nil {
|
||||
if err = sharedRepo.PushDeleteTag(ctx, base, request.GetTagName()); err != nil {
|
||||
return nil, processGitErrorf(err, "Failed to push the tag %s to remote", request.GetTagName())
|
||||
}
|
||||
|
||||
|
@ -150,6 +150,14 @@ type Tag struct {
|
||||
Tagger Signature
|
||||
}
|
||||
|
||||
type CreateTagRequest struct {
|
||||
Name string
|
||||
TargetSha string
|
||||
Message string
|
||||
TaggerName string
|
||||
TaggerEmail string
|
||||
}
|
||||
|
||||
// Signature represents the Author or Committer information.
|
||||
type Signature struct {
|
||||
Identity Identity
|
||||
|
Loading…
Reference in New Issue
Block a user