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