From d6ce1bc7628fac04ac0b0989a930cc471e45955b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Ga=C4=87e=C5=A1a?= Date: Fri, 20 Jan 2023 17:06:35 +0100 Subject: [PATCH] Added gitrpc.UpdateRef (#236) --- gitrpc/common.go | 2 + gitrpc/enum/ref.go | 51 ++ gitrpc/interface.go | 8 +- gitrpc/internal/gitea/ref.go | 65 ++- gitrpc/internal/service/interface.go | 4 +- gitrpc/internal/service/ref.go | 44 +- gitrpc/internal/types/types.go | 7 - gitrpc/proto/ref.proto | 24 +- gitrpc/ref.go | 64 +-- gitrpc/rpc/ref.pb.go | 440 ++++++++++++------ gitrpc/rpc/ref_grpc.pb.go | 36 ++ internal/api/controller/pullreq/controller.go | 21 +- internal/api/controller/pullreq/pr_create.go | 13 +- .../api/controller/pullreq/review_submit.go | 7 +- 14 files changed, 574 insertions(+), 212 deletions(-) create mode 100644 gitrpc/enum/ref.go diff --git a/gitrpc/common.go b/gitrpc/common.go index ab94a8dc2..058cdbbf4 100644 --- a/gitrpc/common.go +++ b/gitrpc/common.go @@ -6,6 +6,8 @@ package gitrpc import "github.com/harness/gitness/gitrpc/rpc" +const NilSHA = "0000000000000000000000000000000000000000" + // ReadParams contains the base parameters for read operations. type ReadParams struct { RepoUID string diff --git a/gitrpc/enum/ref.go b/gitrpc/enum/ref.go new file mode 100644 index 000000000..94de6c332 --- /dev/null +++ b/gitrpc/enum/ref.go @@ -0,0 +1,51 @@ +// Copyright 2022 Harness Inc. All rights reserved. +// Use of this source code is governed by the Polyform Free Trial License +// that can be found in the LICENSE.md file for this repository. + +package enum + +import "github.com/harness/gitness/gitrpc/rpc" + +type RefType int + +const ( + RefTypeRaw RefType = iota + RefTypeBranch + RefTypeTag + RefTypePullReqHead + RefTypePullReqMerge +) + +func RefFromRPC(t rpc.RefType) (RefType, bool) { + switch t { + case rpc.RefType_RefRaw: + return RefTypeRaw, true + case rpc.RefType_RefBranch: + return RefTypeBranch, true + case rpc.RefType_RefTag: + return RefTypeTag, true + case rpc.RefType_RefPullReqHead: + return RefTypePullReqHead, true + case rpc.RefType_RefPullReqMerge: + return RefTypePullReqMerge, true + default: + return 0, false + } +} + +func RefToRPC(t RefType) (rpc.RefType, bool) { + switch t { + case RefTypeRaw: + return rpc.RefType_RefRaw, true + case RefTypeBranch: + return rpc.RefType_RefBranch, true + case RefTypeTag: + return rpc.RefType_RefTag, true + case RefTypePullReqHead: + return rpc.RefType_RefPullReqHead, true + case RefTypePullReqMerge: + return rpc.RefType_RefPullReqMerge, true + default: + return 0, false + } +} diff --git a/gitrpc/interface.go b/gitrpc/interface.go index eb3a469df..144806675 100644 --- a/gitrpc/interface.go +++ b/gitrpc/interface.go @@ -18,7 +18,13 @@ type Interface interface { CreateBranch(ctx context.Context, params *CreateBranchParams) (*CreateBranchOutput, error) DeleteBranch(ctx context.Context, params *DeleteBranchParams) error ListBranches(ctx context.Context, params *ListBranchesParams) (*ListBranchesOutput, error) - GetRef(ctx context.Context, params *GetRefParams) (*GetRefResponse, error) + + GetRef(ctx context.Context, params GetRefParams) (GetRefResponse, error) + + // UpdateRef creates, updates or deletes a git ref. If the OldValue is defined it must match the reference value + // prior to the call. To remove a ref use the zero ref as the NewValue. To require the creation of a new one and + // not update of an exiting one, set the zero ref as the OldValue. + UpdateRef(ctx context.Context, params UpdateRefParams) error /* * Commits service diff --git a/gitrpc/internal/gitea/ref.go b/gitrpc/internal/gitea/ref.go index 6be9ff4b4..a450b7620 100644 --- a/gitrpc/internal/gitea/ref.go +++ b/gitrpc/internal/gitea/ref.go @@ -11,6 +11,7 @@ import ( "math" "strings" + "github.com/harness/gitness/gitrpc/enum" "github.com/harness/gitness/gitrpc/internal/types" gitea "code.gitea.io/gitea/modules/git" @@ -126,14 +127,10 @@ func walkGiteaReferenceParser(parser *gitearef.Parser, handler types.WalkReferen return nil } -func (g Adapter) GetRef(ctx context.Context, repoPath, refName string, refType types.RefType) (string, error) { - switch refType { - case types.RefTypeBranch: - refName = gitea.BranchPrefix + refName - case types.RefTypeTag: - refName = gitea.TagPrefix + refName - default: - return "", types.ErrInvalidArgument +func (g Adapter) GetRef(ctx context.Context, repoPath, refName string, refType enum.RefType) (string, error) { + refName, errRef := getRef(refName, refType) + if errRef != nil { + return "", errRef } cmd := gitea.NewCommand(ctx, "show-ref", "--verify", "-s", "--", refName) @@ -149,3 +146,55 @@ func (g Adapter) GetRef(ctx context.Context, repoPath, refName string, refType t return strings.TrimSpace(stdout), nil } + +func (g Adapter) UpdateRef(ctx context.Context, + repoPath, refName string, refType enum.RefType, + newValue, oldValue string, +) error { + refName, errRef := getRef(refName, refType) + if errRef != nil { + return errRef + } + + args := make([]string, 0, 4) + args = append(args, "update-ref", refName, newValue) + if oldValue != "" { + args = append(args, oldValue) + } + + cmd := gitea.NewCommand(ctx, args...) + _, _, err := cmd.RunStdString(&gitea.RunOpts{ + Dir: repoPath, + }) + if err != nil { + if err.IsExitCode(128) { + return types.ErrNotFound + } + return err + } + + return nil +} + +func getRef(refName string, refType enum.RefType) (string, error) { + const ( + refPullReqPrefix = "refs/pullreq/" + refPullReqHeadSuffix = "/head" + refPullReqMergeSuffix = "/merge" + ) + + switch refType { + case enum.RefTypeRaw: + return refName, nil + case enum.RefTypeBranch: + return gitea.BranchPrefix + refName, nil + case enum.RefTypeTag: + return gitea.TagPrefix + refName, nil + case enum.RefTypePullReqHead: + return refPullReqPrefix + refName + refPullReqHeadSuffix, nil + case enum.RefTypePullReqMerge: + return refPullReqPrefix + refName + refPullReqMergeSuffix, nil + default: + return "", types.ErrInvalidArgument + } +} diff --git a/gitrpc/internal/service/interface.go b/gitrpc/internal/service/interface.go index fd93fa6d1..9c0b3e60c 100644 --- a/gitrpc/internal/service/interface.go +++ b/gitrpc/internal/service/interface.go @@ -8,6 +8,7 @@ import ( "context" "io" + "github.com/harness/gitness/gitrpc/enum" "github.com/harness/gitness/gitrpc/internal/types" ) @@ -39,7 +40,8 @@ type GitAdapter interface { 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) - GetRef(ctx context.Context, repoPath string, name string, refType types.RefType) (string, error) + GetRef(ctx context.Context, repoPath string, name string, refType enum.RefType) (string, error) + UpdateRef(ctx context.Context, repoPath, refName string, refType enum.RefType, newValue, oldValue string) error CreateTemporaryRepoForPR(ctx context.Context, reposTempPath string, pr *types.PullRequest) (string, error) Merge(ctx context.Context, pr *types.PullRequest, mergeMethod string, trackingBranch string, tmpBasePath string, mergeMsg string, env []string) error diff --git a/gitrpc/internal/service/ref.go b/gitrpc/internal/service/ref.go index c9949d433..b149942f9 100644 --- a/gitrpc/internal/service/ref.go +++ b/gitrpc/internal/service/ref.go @@ -10,6 +10,7 @@ import ( "math" "strings" + "github.com/harness/gitness/gitrpc/enum" "github.com/harness/gitness/gitrpc/internal/types" "github.com/harness/gitness/gitrpc/rpc" @@ -178,24 +179,19 @@ func wrapInstructorWithOptionalPagination(inner types.WalkReferencesInstructor, } func (s ReferenceService) GetRef(ctx context.Context, - request *rpc.GetRefRequest) (*rpc.GetRefResponse, error) { - base := request.GetBase() - if base == nil { + request *rpc.GetRefRequest, +) (*rpc.GetRefResponse, error) { + if request.Base == nil { return nil, types.ErrBaseCannotBeEmpty } - repoPath := getFullPathForRepo(s.reposRoot, base.GetRepoUid()) - - var refType types.RefType - switch request.RefType { - case rpc.GetRefRequest_Branch: - refType = types.RefTypeBranch - case rpc.GetRefRequest_Tag: - refType = types.RefTypeTag - default: - return nil, status.Error(codes.InvalidArgument, "invalid value of refType argument") + refType, ok := enum.RefFromRPC(request.GetRefType()) + if !ok { + return nil, status.Error(codes.InvalidArgument, "invalid value of RefType argument") } + repoPath := getFullPathForRepo(s.reposRoot, request.Base.GetRepoUid()) + sha, err := s.adapter.GetRef(ctx, repoPath, request.RefName, refType) if err != nil { return nil, err @@ -203,3 +199,25 @@ func (s ReferenceService) GetRef(ctx context.Context, return &rpc.GetRefResponse{Sha: sha}, nil } + +func (s ReferenceService) UpdateRef(ctx context.Context, + request *rpc.UpdateRefRequest, +) (*rpc.UpdateRefResponse, error) { + if request.Base == nil { + return nil, types.ErrBaseCannotBeEmpty + } + + refType, ok := enum.RefFromRPC(request.GetRefType()) + if !ok { + return nil, status.Error(codes.InvalidArgument, "invalid value of RefType argument") + } + + repoPath := getFullPathForRepo(s.reposRoot, request.Base.GetRepoUid()) + + err := s.adapter.UpdateRef(ctx, repoPath, request.RefName, refType, request.NewValue, request.OldValue) + if err != nil { + return nil, err + } + + return &rpc.UpdateRefResponse{}, nil +} diff --git a/gitrpc/internal/types/types.go b/gitrpc/internal/types/types.go index 692f6e13f..65b5b1913 100644 --- a/gitrpc/internal/types/types.go +++ b/gitrpc/internal/types/types.go @@ -80,13 +80,6 @@ func ParseGitReferenceField(f string) (GitReferenceField, error) { } } -type RefType int - -const ( - RefTypeBranch RefType = iota - RefTypeTag -) - type WalkInstruction int const ( diff --git a/gitrpc/proto/ref.proto b/gitrpc/proto/ref.proto index 3785b78c9..8ef1e5b4b 100644 --- a/gitrpc/proto/ref.proto +++ b/gitrpc/proto/ref.proto @@ -11,6 +11,7 @@ service ReferenceService { rpc ListBranches(ListBranchesRequest) returns (stream ListBranchesResponse); rpc ListCommitTags(ListCommitTagsRequest) returns (stream ListCommitTagsResponse); rpc GetRef(GetRefRequest) returns (GetRefResponse); + rpc UpdateRef(UpdateRefRequest) returns (UpdateRefResponse); } message CreateBranchRequest { @@ -89,12 +90,15 @@ message CommitTag { Commit commit = 7; } +enum RefType { + RefRaw = 0; + RefBranch = 1; + RefTag = 2; + RefPullReqHead = 3; + RefPullReqMerge = 4; +} + message GetRefRequest { - enum RefType { - Branch = 0; - Tag = 1; - } - ReadRequest base = 1; string ref_name = 2; RefType ref_type = 3; @@ -103,3 +107,13 @@ message GetRefRequest { message GetRefResponse { string sha = 1; } + +message UpdateRefRequest { + WriteRequest base = 1; + string ref_name = 2; + RefType ref_type = 3; + string new_value = 4; + string old_value = 5; +} + +message UpdateRefResponse {} diff --git a/gitrpc/ref.go b/gitrpc/ref.go index 9454231b1..9e341d0c2 100644 --- a/gitrpc/ref.go +++ b/gitrpc/ref.go @@ -7,42 +7,27 @@ package gitrpc import ( "context" + "github.com/harness/gitness/gitrpc/enum" "github.com/harness/gitness/gitrpc/rpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) -type RefType int - -const ( - RefTypeBranch RefType = iota - RefTypeTag -) - type GetRefParams struct { ReadParams Name string - Type RefType + Type enum.RefType } type GetRefResponse struct { SHA string } -func (c *Client) GetRef(ctx context.Context, params *GetRefParams) (*GetRefResponse, error) { - if params == nil { - return nil, ErrNoParamsProvided - } - - var refType rpc.GetRefRequest_RefType - switch params.Type { - case RefTypeBranch: - refType = rpc.GetRefRequest_Branch - case RefTypeTag: - refType = rpc.GetRefRequest_Tag - default: - return nil, ErrInvalidArgument +func (c *Client) GetRef(ctx context.Context, params GetRefParams) (GetRefResponse, error) { + refType, isOk := enum.RefToRPC(params.Type) + if !isOk { + return GetRefResponse{}, ErrInvalidArgument } result, err := c.refService.GetRef(ctx, &rpc.GetRefRequest{ @@ -51,13 +36,36 @@ func (c *Client) GetRef(ctx context.Context, params *GetRefParams) (*GetRefRespo RefType: refType, }) if s, ok := status.FromError(err); err != nil && ok && s.Code() == codes.NotFound { - return nil, ErrNotFound - } - if err != nil { - return nil, err + return GetRefResponse{}, ErrNotFound } - return &GetRefResponse{ - SHA: result.Sha, - }, nil + return GetRefResponse{SHA: result.Sha}, nil +} + +type UpdateRefParams struct { + WriteParams + Name string + Type enum.RefType + NewValue string + OldValue string +} + +func (c *Client) UpdateRef(ctx context.Context, params UpdateRefParams) error { + refType, isOk := enum.RefToRPC(params.Type) + if !isOk { + return ErrInvalidArgument + } + + _, err := c.refService.UpdateRef(ctx, &rpc.UpdateRefRequest{ + Base: mapToRPCWriteRequest(params.WriteParams), + RefName: params.Name, + RefType: refType, + NewValue: params.NewValue, + OldValue: params.OldValue, + }) + if s, ok := status.FromError(err); err != nil && ok && s.Code() == codes.NotFound { + return ErrNotFound + } + + return err } diff --git a/gitrpc/rpc/ref.pb.go b/gitrpc/rpc/ref.pb.go index 8cbfa3a7d..c0b4d7eac 100644 --- a/gitrpc/rpc/ref.pb.go +++ b/gitrpc/rpc/ref.pb.go @@ -20,6 +20,61 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type RefType int32 + +const ( + RefType_RefRaw RefType = 0 + RefType_RefBranch RefType = 1 + RefType_RefTag RefType = 2 + RefType_RefPullReqHead RefType = 3 + RefType_RefPullReqMerge RefType = 4 +) + +// Enum value maps for RefType. +var ( + RefType_name = map[int32]string{ + 0: "RefRaw", + 1: "RefBranch", + 2: "RefTag", + 3: "RefPullReqHead", + 4: "RefPullReqMerge", + } + RefType_value = map[string]int32{ + "RefRaw": 0, + "RefBranch": 1, + "RefTag": 2, + "RefPullReqHead": 3, + "RefPullReqMerge": 4, + } +) + +func (x RefType) Enum() *RefType { + p := new(RefType) + *p = x + return p +} + +func (x RefType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (RefType) Descriptor() protoreflect.EnumDescriptor { + return file_ref_proto_enumTypes[0].Descriptor() +} + +func (RefType) Type() protoreflect.EnumType { + return &file_ref_proto_enumTypes[0] +} + +func (x RefType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use RefType.Descriptor instead. +func (RefType) EnumDescriptor() ([]byte, []int) { + return file_ref_proto_rawDescGZIP(), []int{0} +} + type ListBranchesRequest_SortOption int32 const ( @@ -53,11 +108,11 @@ func (x ListBranchesRequest_SortOption) String() string { } func (ListBranchesRequest_SortOption) Descriptor() protoreflect.EnumDescriptor { - return file_ref_proto_enumTypes[0].Descriptor() + return file_ref_proto_enumTypes[1].Descriptor() } func (ListBranchesRequest_SortOption) Type() protoreflect.EnumType { - return &file_ref_proto_enumTypes[0] + return &file_ref_proto_enumTypes[1] } func (x ListBranchesRequest_SortOption) Number() protoreflect.EnumNumber { @@ -102,11 +157,11 @@ func (x ListCommitTagsRequest_SortOption) String() string { } func (ListCommitTagsRequest_SortOption) Descriptor() protoreflect.EnumDescriptor { - return file_ref_proto_enumTypes[1].Descriptor() + return file_ref_proto_enumTypes[2].Descriptor() } func (ListCommitTagsRequest_SortOption) Type() protoreflect.EnumType { - return &file_ref_proto_enumTypes[1] + return &file_ref_proto_enumTypes[2] } func (x ListCommitTagsRequest_SortOption) Number() protoreflect.EnumNumber { @@ -118,52 +173,6 @@ func (ListCommitTagsRequest_SortOption) EnumDescriptor() ([]byte, []int) { return file_ref_proto_rawDescGZIP(), []int{7, 0} } -type GetRefRequest_RefType int32 - -const ( - GetRefRequest_Branch GetRefRequest_RefType = 0 - GetRefRequest_Tag GetRefRequest_RefType = 1 -) - -// Enum value maps for GetRefRequest_RefType. -var ( - GetRefRequest_RefType_name = map[int32]string{ - 0: "Branch", - 1: "Tag", - } - GetRefRequest_RefType_value = map[string]int32{ - "Branch": 0, - "Tag": 1, - } -) - -func (x GetRefRequest_RefType) Enum() *GetRefRequest_RefType { - p := new(GetRefRequest_RefType) - *p = x - return p -} - -func (x GetRefRequest_RefType) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (GetRefRequest_RefType) Descriptor() protoreflect.EnumDescriptor { - return file_ref_proto_enumTypes[2].Descriptor() -} - -func (GetRefRequest_RefType) Type() protoreflect.EnumType { - return &file_ref_proto_enumTypes[2] -} - -func (x GetRefRequest_RefType) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use GetRefRequest_RefType.Descriptor instead. -func (GetRefRequest_RefType) EnumDescriptor() ([]byte, []int) { - return file_ref_proto_rawDescGZIP(), []int{10, 0} -} - type CreateBranchRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -831,9 +840,9 @@ type GetRefRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Base *ReadRequest `protobuf:"bytes,1,opt,name=base,proto3" json:"base,omitempty"` - RefName string `protobuf:"bytes,2,opt,name=ref_name,json=refName,proto3" json:"ref_name,omitempty"` - RefType GetRefRequest_RefType `protobuf:"varint,3,opt,name=ref_type,json=refType,proto3,enum=rpc.GetRefRequest_RefType" json:"ref_type,omitempty"` + Base *ReadRequest `protobuf:"bytes,1,opt,name=base,proto3" json:"base,omitempty"` + RefName string `protobuf:"bytes,2,opt,name=ref_name,json=refName,proto3" json:"ref_name,omitempty"` + RefType RefType `protobuf:"varint,3,opt,name=ref_type,json=refType,proto3,enum=rpc.RefType" json:"ref_type,omitempty"` } func (x *GetRefRequest) Reset() { @@ -882,11 +891,11 @@ func (x *GetRefRequest) GetRefName() string { return "" } -func (x *GetRefRequest) GetRefType() GetRefRequest_RefType { +func (x *GetRefRequest) GetRefType() RefType { if x != nil { return x.RefType } - return GetRefRequest_Branch + return RefType_RefRaw } type GetRefResponse struct { @@ -936,6 +945,123 @@ func (x *GetRefResponse) GetSha() string { return "" } +type UpdateRefRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Base *WriteRequest `protobuf:"bytes,1,opt,name=base,proto3" json:"base,omitempty"` + RefName string `protobuf:"bytes,2,opt,name=ref_name,json=refName,proto3" json:"ref_name,omitempty"` + RefType RefType `protobuf:"varint,3,opt,name=ref_type,json=refType,proto3,enum=rpc.RefType" json:"ref_type,omitempty"` + NewValue string `protobuf:"bytes,4,opt,name=new_value,json=newValue,proto3" json:"new_value,omitempty"` + OldValue string `protobuf:"bytes,5,opt,name=old_value,json=oldValue,proto3" json:"old_value,omitempty"` +} + +func (x *UpdateRefRequest) Reset() { + *x = UpdateRefRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_ref_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateRefRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateRefRequest) ProtoMessage() {} + +func (x *UpdateRefRequest) ProtoReflect() protoreflect.Message { + mi := &file_ref_proto_msgTypes[12] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateRefRequest.ProtoReflect.Descriptor instead. +func (*UpdateRefRequest) Descriptor() ([]byte, []int) { + return file_ref_proto_rawDescGZIP(), []int{12} +} + +func (x *UpdateRefRequest) GetBase() *WriteRequest { + if x != nil { + return x.Base + } + return nil +} + +func (x *UpdateRefRequest) GetRefName() string { + if x != nil { + return x.RefName + } + return "" +} + +func (x *UpdateRefRequest) GetRefType() RefType { + if x != nil { + return x.RefType + } + return RefType_RefRaw +} + +func (x *UpdateRefRequest) GetNewValue() string { + if x != nil { + return x.NewValue + } + return "" +} + +func (x *UpdateRefRequest) GetOldValue() string { + if x != nil { + return x.OldValue + } + return "" +} + +type UpdateRefResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *UpdateRefResponse) Reset() { + *x = UpdateRefResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_ref_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateRefResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateRefResponse) ProtoMessage() {} + +func (x *UpdateRefResponse) ProtoReflect() protoreflect.Message { + mi := &file_ref_proto_msgTypes[13] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateRefResponse.ProtoReflect.Descriptor instead. +func (*UpdateRefResponse) Descriptor() ([]byte, []int) { + return file_ref_proto_rawDescGZIP(), []int{13} +} + var File_ref_proto protoreflect.FileDescriptor var file_ref_proto_rawDesc = []byte{ @@ -1027,45 +1153,65 @@ var file_ref_proto_rawDesc = []byte{ 0x70, 0x63, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x06, 0x74, 0x61, 0x67, 0x67, 0x65, 0x72, 0x12, 0x23, 0x0a, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, - 0x74, 0x52, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x22, 0xa7, 0x01, 0x0a, 0x0d, 0x47, 0x65, - 0x74, 0x52, 0x65, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x04, 0x62, - 0x61, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x72, 0x70, 0x63, 0x2e, - 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, 0x62, 0x61, 0x73, - 0x65, 0x12, 0x19, 0x0a, 0x08, 0x72, 0x65, 0x66, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x66, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x35, 0x0a, 0x08, - 0x72, 0x65, 0x66, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1a, - 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x2e, 0x52, 0x65, 0x66, 0x54, 0x79, 0x70, 0x65, 0x52, 0x07, 0x72, 0x65, 0x66, 0x54, - 0x79, 0x70, 0x65, 0x22, 0x1e, 0x0a, 0x07, 0x52, 0x65, 0x66, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0a, - 0x0a, 0x06, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x61, - 0x67, 0x10, 0x01, 0x22, 0x22, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x66, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x68, 0x61, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x03, 0x73, 0x68, 0x61, 0x32, 0xe3, 0x02, 0x0a, 0x10, 0x52, 0x65, 0x66, 0x65, - 0x72, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x43, 0x0a, 0x0c, - 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x12, 0x18, 0x2e, 0x72, - 0x70, 0x63, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x43, 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x42, 0x72, 0x61, 0x6e, 0x63, - 0x68, 0x12, 0x18, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x42, 0x72, - 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x70, - 0x63, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x45, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x72, - 0x61, 0x6e, 0x63, 0x68, 0x65, 0x73, 0x12, 0x18, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, - 0x74, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x19, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x72, 0x61, 0x6e, 0x63, - 0x68, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x4b, 0x0a, - 0x0e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x54, 0x61, 0x67, 0x73, 0x12, - 0x1a, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x54, 0x61, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x72, 0x70, - 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x54, 0x61, 0x67, 0x73, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x31, 0x0a, 0x06, 0x47, 0x65, - 0x74, 0x52, 0x65, 0x66, 0x12, 0x12, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, - 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, - 0x65, 0x74, 0x52, 0x65, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x27, 0x5a, - 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x72, 0x6e, - 0x65, 0x73, 0x73, 0x2f, 0x67, 0x69, 0x74, 0x6e, 0x65, 0x73, 0x73, 0x2f, 0x67, 0x69, 0x74, 0x72, - 0x70, 0x63, 0x2f, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x52, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x22, 0x79, 0x0a, 0x0d, 0x47, 0x65, 0x74, + 0x52, 0x65, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x04, 0x62, 0x61, + 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x52, + 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, 0x62, 0x61, 0x73, 0x65, + 0x12, 0x19, 0x0a, 0x08, 0x72, 0x65, 0x66, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x66, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x27, 0x0a, 0x08, 0x72, + 0x65, 0x66, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, + 0x72, 0x70, 0x63, 0x2e, 0x52, 0x65, 0x66, 0x54, 0x79, 0x70, 0x65, 0x52, 0x07, 0x72, 0x65, 0x66, + 0x54, 0x79, 0x70, 0x65, 0x22, 0x22, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x66, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x68, 0x61, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x68, 0x61, 0x22, 0xb7, 0x01, 0x0a, 0x10, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x25, 0x0a, + 0x04, 0x62, 0x61, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x72, 0x70, + 0x63, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, + 0x62, 0x61, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x72, 0x65, 0x66, 0x5f, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x66, 0x4e, 0x61, 0x6d, 0x65, 0x12, + 0x27, 0x0a, 0x08, 0x72, 0x65, 0x66, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0e, 0x32, 0x0c, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x65, 0x66, 0x54, 0x79, 0x70, 0x65, 0x52, + 0x07, 0x72, 0x65, 0x66, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x5f, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x65, 0x77, + 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6f, 0x6c, 0x64, 0x5f, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6f, 0x6c, 0x64, 0x56, 0x61, 0x6c, + 0x75, 0x65, 0x22, 0x13, 0x0a, 0x11, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x66, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2a, 0x59, 0x0a, 0x07, 0x52, 0x65, 0x66, 0x54, 0x79, + 0x70, 0x65, 0x12, 0x0a, 0x0a, 0x06, 0x52, 0x65, 0x66, 0x52, 0x61, 0x77, 0x10, 0x00, 0x12, 0x0d, + 0x0a, 0x09, 0x52, 0x65, 0x66, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x10, 0x01, 0x12, 0x0a, 0x0a, + 0x06, 0x52, 0x65, 0x66, 0x54, 0x61, 0x67, 0x10, 0x02, 0x12, 0x12, 0x0a, 0x0e, 0x52, 0x65, 0x66, + 0x50, 0x75, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x48, 0x65, 0x61, 0x64, 0x10, 0x03, 0x12, 0x13, 0x0a, + 0x0f, 0x52, 0x65, 0x66, 0x50, 0x75, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x4d, 0x65, 0x72, 0x67, 0x65, + 0x10, 0x04, 0x32, 0x9f, 0x03, 0x0a, 0x10, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x43, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x12, 0x18, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, 0x72, + 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x43, 0x0a, 0x0c, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x12, 0x18, 0x2e, 0x72, + 0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x45, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, + 0x73, 0x12, 0x18, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x72, 0x61, 0x6e, + 0x63, 0x68, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x70, + 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x73, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x4b, 0x0a, 0x0e, 0x4c, 0x69, 0x73, 0x74, + 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x54, 0x61, 0x67, 0x73, 0x12, 0x1a, 0x2e, 0x72, 0x70, 0x63, + 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x54, 0x61, 0x67, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, + 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x54, 0x61, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x31, 0x0a, 0x06, 0x47, 0x65, 0x74, 0x52, 0x65, 0x66, 0x12, + 0x12, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x66, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x66, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3a, 0x0a, 0x09, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x66, 0x12, 0x15, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x72, + 0x70, 0x63, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x66, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x73, 0x2f, 0x67, 0x69, 0x74, 0x6e, 0x65, + 0x73, 0x73, 0x2f, 0x67, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2f, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1081,11 +1227,11 @@ func file_ref_proto_rawDescGZIP() []byte { } var file_ref_proto_enumTypes = make([]protoimpl.EnumInfo, 3) -var file_ref_proto_msgTypes = make([]protoimpl.MessageInfo, 12) +var file_ref_proto_msgTypes = make([]protoimpl.MessageInfo, 14) var file_ref_proto_goTypes = []interface{}{ - (ListBranchesRequest_SortOption)(0), // 0: rpc.ListBranchesRequest.SortOption - (ListCommitTagsRequest_SortOption)(0), // 1: rpc.ListCommitTagsRequest.SortOption - (GetRefRequest_RefType)(0), // 2: rpc.GetRefRequest.RefType + (RefType)(0), // 0: rpc.RefType + (ListBranchesRequest_SortOption)(0), // 1: rpc.ListBranchesRequest.SortOption + (ListCommitTagsRequest_SortOption)(0), // 2: rpc.ListCommitTagsRequest.SortOption (*CreateBranchRequest)(nil), // 3: rpc.CreateBranchRequest (*CreateBranchResponse)(nil), // 4: rpc.CreateBranchResponse (*DeleteBranchRequest)(nil), // 5: rpc.DeleteBranchRequest @@ -1098,44 +1244,50 @@ var file_ref_proto_goTypes = []interface{}{ (*CommitTag)(nil), // 12: rpc.CommitTag (*GetRefRequest)(nil), // 13: rpc.GetRefRequest (*GetRefResponse)(nil), // 14: rpc.GetRefResponse - (*WriteRequest)(nil), // 15: rpc.WriteRequest - (*ReadRequest)(nil), // 16: rpc.ReadRequest - (SortOrder)(0), // 17: rpc.SortOrder - (*Commit)(nil), // 18: rpc.Commit - (*Signature)(nil), // 19: rpc.Signature + (*UpdateRefRequest)(nil), // 15: rpc.UpdateRefRequest + (*UpdateRefResponse)(nil), // 16: rpc.UpdateRefResponse + (*WriteRequest)(nil), // 17: rpc.WriteRequest + (*ReadRequest)(nil), // 18: rpc.ReadRequest + (SortOrder)(0), // 19: rpc.SortOrder + (*Commit)(nil), // 20: rpc.Commit + (*Signature)(nil), // 21: rpc.Signature } var file_ref_proto_depIdxs = []int32{ - 15, // 0: rpc.CreateBranchRequest.base:type_name -> rpc.WriteRequest + 17, // 0: rpc.CreateBranchRequest.base:type_name -> rpc.WriteRequest 9, // 1: rpc.CreateBranchResponse.branch:type_name -> rpc.Branch - 15, // 2: rpc.DeleteBranchRequest.base:type_name -> rpc.WriteRequest - 16, // 3: rpc.ListBranchesRequest.base:type_name -> rpc.ReadRequest - 0, // 4: rpc.ListBranchesRequest.sort:type_name -> rpc.ListBranchesRequest.SortOption - 17, // 5: rpc.ListBranchesRequest.order:type_name -> rpc.SortOrder + 17, // 2: rpc.DeleteBranchRequest.base:type_name -> rpc.WriteRequest + 18, // 3: rpc.ListBranchesRequest.base:type_name -> rpc.ReadRequest + 1, // 4: rpc.ListBranchesRequest.sort:type_name -> rpc.ListBranchesRequest.SortOption + 19, // 5: rpc.ListBranchesRequest.order:type_name -> rpc.SortOrder 9, // 6: rpc.ListBranchesResponse.branch:type_name -> rpc.Branch - 18, // 7: rpc.Branch.commit:type_name -> rpc.Commit - 16, // 8: rpc.ListCommitTagsRequest.base:type_name -> rpc.ReadRequest - 1, // 9: rpc.ListCommitTagsRequest.sort:type_name -> rpc.ListCommitTagsRequest.SortOption - 17, // 10: rpc.ListCommitTagsRequest.order:type_name -> rpc.SortOrder + 20, // 7: rpc.Branch.commit:type_name -> rpc.Commit + 18, // 8: rpc.ListCommitTagsRequest.base:type_name -> rpc.ReadRequest + 2, // 9: rpc.ListCommitTagsRequest.sort:type_name -> rpc.ListCommitTagsRequest.SortOption + 19, // 10: rpc.ListCommitTagsRequest.order:type_name -> rpc.SortOrder 12, // 11: rpc.ListCommitTagsResponse.tag:type_name -> rpc.CommitTag - 19, // 12: rpc.CommitTag.tagger:type_name -> rpc.Signature - 18, // 13: rpc.CommitTag.commit:type_name -> rpc.Commit - 16, // 14: rpc.GetRefRequest.base:type_name -> rpc.ReadRequest - 2, // 15: rpc.GetRefRequest.ref_type:type_name -> rpc.GetRefRequest.RefType - 3, // 16: rpc.ReferenceService.CreateBranch:input_type -> rpc.CreateBranchRequest - 5, // 17: rpc.ReferenceService.DeleteBranch:input_type -> rpc.DeleteBranchRequest - 7, // 18: rpc.ReferenceService.ListBranches:input_type -> rpc.ListBranchesRequest - 10, // 19: rpc.ReferenceService.ListCommitTags:input_type -> rpc.ListCommitTagsRequest - 13, // 20: rpc.ReferenceService.GetRef:input_type -> rpc.GetRefRequest - 4, // 21: rpc.ReferenceService.CreateBranch:output_type -> rpc.CreateBranchResponse - 6, // 22: rpc.ReferenceService.DeleteBranch:output_type -> rpc.DeleteBranchResponse - 8, // 23: rpc.ReferenceService.ListBranches:output_type -> rpc.ListBranchesResponse - 11, // 24: rpc.ReferenceService.ListCommitTags:output_type -> rpc.ListCommitTagsResponse - 14, // 25: rpc.ReferenceService.GetRef:output_type -> rpc.GetRefResponse - 21, // [21:26] is the sub-list for method output_type - 16, // [16:21] is the sub-list for method input_type - 16, // [16:16] is the sub-list for extension type_name - 16, // [16:16] is the sub-list for extension extendee - 0, // [0:16] is the sub-list for field type_name + 21, // 12: rpc.CommitTag.tagger:type_name -> rpc.Signature + 20, // 13: rpc.CommitTag.commit:type_name -> rpc.Commit + 18, // 14: rpc.GetRefRequest.base:type_name -> rpc.ReadRequest + 0, // 15: rpc.GetRefRequest.ref_type:type_name -> rpc.RefType + 17, // 16: rpc.UpdateRefRequest.base:type_name -> rpc.WriteRequest + 0, // 17: rpc.UpdateRefRequest.ref_type:type_name -> rpc.RefType + 3, // 18: rpc.ReferenceService.CreateBranch:input_type -> rpc.CreateBranchRequest + 5, // 19: rpc.ReferenceService.DeleteBranch:input_type -> rpc.DeleteBranchRequest + 7, // 20: rpc.ReferenceService.ListBranches:input_type -> rpc.ListBranchesRequest + 10, // 21: rpc.ReferenceService.ListCommitTags:input_type -> rpc.ListCommitTagsRequest + 13, // 22: rpc.ReferenceService.GetRef:input_type -> rpc.GetRefRequest + 15, // 23: rpc.ReferenceService.UpdateRef:input_type -> rpc.UpdateRefRequest + 4, // 24: rpc.ReferenceService.CreateBranch:output_type -> rpc.CreateBranchResponse + 6, // 25: rpc.ReferenceService.DeleteBranch:output_type -> rpc.DeleteBranchResponse + 8, // 26: rpc.ReferenceService.ListBranches:output_type -> rpc.ListBranchesResponse + 11, // 27: rpc.ReferenceService.ListCommitTags:output_type -> rpc.ListCommitTagsResponse + 14, // 28: rpc.ReferenceService.GetRef:output_type -> rpc.GetRefResponse + 16, // 29: rpc.ReferenceService.UpdateRef:output_type -> rpc.UpdateRefResponse + 24, // [24:30] is the sub-list for method output_type + 18, // [18:24] is the sub-list for method input_type + 18, // [18:18] is the sub-list for extension type_name + 18, // [18:18] is the sub-list for extension extendee + 0, // [0:18] is the sub-list for field type_name } func init() { file_ref_proto_init() } @@ -1289,6 +1441,30 @@ func file_ref_proto_init() { return nil } } + file_ref_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateRefRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_ref_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateRefResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1296,7 +1472,7 @@ func file_ref_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_ref_proto_rawDesc, NumEnums: 3, - NumMessages: 12, + NumMessages: 14, NumExtensions: 0, NumServices: 1, }, diff --git a/gitrpc/rpc/ref_grpc.pb.go b/gitrpc/rpc/ref_grpc.pb.go index 56daa5da8..dc2b491be 100644 --- a/gitrpc/rpc/ref_grpc.pb.go +++ b/gitrpc/rpc/ref_grpc.pb.go @@ -27,6 +27,7 @@ type ReferenceServiceClient interface { ListBranches(ctx context.Context, in *ListBranchesRequest, opts ...grpc.CallOption) (ReferenceService_ListBranchesClient, error) ListCommitTags(ctx context.Context, in *ListCommitTagsRequest, opts ...grpc.CallOption) (ReferenceService_ListCommitTagsClient, error) GetRef(ctx context.Context, in *GetRefRequest, opts ...grpc.CallOption) (*GetRefResponse, error) + UpdateRef(ctx context.Context, in *UpdateRefRequest, opts ...grpc.CallOption) (*UpdateRefResponse, error) } type referenceServiceClient struct { @@ -128,6 +129,15 @@ func (c *referenceServiceClient) GetRef(ctx context.Context, in *GetRefRequest, return out, nil } +func (c *referenceServiceClient) UpdateRef(ctx context.Context, in *UpdateRefRequest, opts ...grpc.CallOption) (*UpdateRefResponse, error) { + out := new(UpdateRefResponse) + err := c.cc.Invoke(ctx, "/rpc.ReferenceService/UpdateRef", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // ReferenceServiceServer is the server API for ReferenceService service. // All implementations must embed UnimplementedReferenceServiceServer // for forward compatibility @@ -137,6 +147,7 @@ type ReferenceServiceServer interface { ListBranches(*ListBranchesRequest, ReferenceService_ListBranchesServer) error ListCommitTags(*ListCommitTagsRequest, ReferenceService_ListCommitTagsServer) error GetRef(context.Context, *GetRefRequest) (*GetRefResponse, error) + UpdateRef(context.Context, *UpdateRefRequest) (*UpdateRefResponse, error) mustEmbedUnimplementedReferenceServiceServer() } @@ -159,6 +170,9 @@ func (UnimplementedReferenceServiceServer) ListCommitTags(*ListCommitTagsRequest func (UnimplementedReferenceServiceServer) GetRef(context.Context, *GetRefRequest) (*GetRefResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetRef not implemented") } +func (UnimplementedReferenceServiceServer) UpdateRef(context.Context, *UpdateRefRequest) (*UpdateRefResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateRef not implemented") +} func (UnimplementedReferenceServiceServer) mustEmbedUnimplementedReferenceServiceServer() {} // UnsafeReferenceServiceServer may be embedded to opt out of forward compatibility for this service. @@ -268,6 +282,24 @@ func _ReferenceService_GetRef_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +func _ReferenceService_UpdateRef_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateRefRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ReferenceServiceServer).UpdateRef(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rpc.ReferenceService/UpdateRef", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ReferenceServiceServer).UpdateRef(ctx, req.(*UpdateRefRequest)) + } + return interceptor(ctx, in, info, handler) +} + // ReferenceService_ServiceDesc is the grpc.ServiceDesc for ReferenceService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -287,6 +319,10 @@ var ReferenceService_ServiceDesc = grpc.ServiceDesc{ MethodName: "GetRef", Handler: _ReferenceService_GetRef_Handler, }, + { + MethodName: "UpdateRef", + Handler: _ReferenceService_UpdateRef_Handler, + }, }, Streams: []grpc.StreamDesc{ { diff --git a/internal/api/controller/pullreq/controller.go b/internal/api/controller/pullreq/controller.go index 4b61a7ffe..b7bf55dfd 100644 --- a/internal/api/controller/pullreq/controller.go +++ b/internal/api/controller/pullreq/controller.go @@ -10,8 +10,8 @@ import ( "fmt" "github.com/harness/gitness/gitrpc" + gitrpcenum "github.com/harness/gitness/gitrpc/enum" apiauth "github.com/harness/gitness/internal/api/auth" - repoctrl "github.com/harness/gitness/internal/api/controller/repo" "github.com/harness/gitness/internal/api/usererror" "github.com/harness/gitness/internal/auth" "github.com/harness/gitness/internal/auth/authz" @@ -64,27 +64,28 @@ func NewController( func (c *Controller) verifyBranchExistence(ctx context.Context, repo *types.Repository, branch string, -) error { +) (string, error) { if branch == "" { - return usererror.BadRequest("branch name can't be empty") + return "", usererror.BadRequest("branch name can't be empty") } - _, err := c.gitRPCClient.GetRef(ctx, - &gitrpc.GetRefParams{ - ReadParams: repoctrl.CreateRPCReadParams(repo), + ref, err := c.gitRPCClient.GetRef(ctx, + gitrpc.GetRefParams{ + ReadParams: gitrpc.ReadParams{RepoUID: repo.GitUID}, Name: branch, - Type: gitrpc.RefTypeBranch}) + Type: gitrpcenum.RefTypeBranch, + }) if errors.Is(err, gitrpc.ErrNotFound) { - return usererror.BadRequest( + return "", usererror.BadRequest( fmt.Sprintf("branch %s does not exist in the repository %s", branch, repo.UID)) } if err != nil { - return fmt.Errorf( + return "", fmt.Errorf( "failed to check existence of the branch %s in the repository %s: %w", branch, repo.UID, err) } - return nil + return ref.SHA, nil } func (c *Controller) getRepoCheckAccess(ctx context.Context, diff --git a/internal/api/controller/pullreq/pr_create.go b/internal/api/controller/pullreq/pr_create.go index 87f9dcc07..80a6b1817 100644 --- a/internal/api/controller/pullreq/pr_create.go +++ b/internal/api/controller/pullreq/pr_create.go @@ -54,11 +54,14 @@ func (c *Controller) Create( return nil, usererror.BadRequest("target and source branch can't be the same") } - if errBranch := c.verifyBranchExistence(ctx, sourceRepo, in.SourceBranch); errBranch != nil { - return nil, errBranch + var sourceSHA string + + if sourceSHA, err = c.verifyBranchExistence(ctx, sourceRepo, in.SourceBranch); err != nil { + return nil, err } - if errBranch := c.verifyBranchExistence(ctx, targetRepo, in.TargetBranch); errBranch != nil { - return nil, errBranch + + if _, err = c.verifyBranchExistence(ctx, targetRepo, in.TargetBranch); err != nil { + return nil, err } if err = c.checkIfAlreadyExists(ctx, targetRepo.ID, sourceRepo.ID, in.SourceBranch, in.TargetBranch); err != nil { @@ -73,6 +76,8 @@ func (c *Controller) Create( return nil, fmt.Errorf("failed to aquire PullReqSeq number: %w", err) } + _ = fmt.Sprintf("TODO: %s", sourceSHA) // TODO: Use sourceSHA to create git PR head ref + pr := newPullReq(session, targetRepo.PullReqSeq, sourceRepo, targetRepo, in) err = c.pullreqStore.Create(ctx, pr) diff --git a/internal/api/controller/pullreq/review_submit.go b/internal/api/controller/pullreq/review_submit.go index a59676b0d..e38f88421 100644 --- a/internal/api/controller/pullreq/review_submit.go +++ b/internal/api/controller/pullreq/review_submit.go @@ -12,6 +12,7 @@ import ( "time" "github.com/harness/gitness/gitrpc" + gitrpcenum "github.com/harness/gitness/gitrpc/enum" "github.com/harness/gitness/internal/api/usererror" "github.com/harness/gitness/internal/auth" "github.com/harness/gitness/internal/store" @@ -69,16 +70,16 @@ func (c *Controller) ReviewSubmit( return nil, usererror.BadRequest("Can't submit review to own pull requests.") } - ref, err := c.gitRPCClient.GetRef(ctx, &gitrpc.GetRefParams{ + ref, err := c.gitRPCClient.GetRef(ctx, gitrpc.GetRefParams{ ReadParams: gitrpc.ReadParams{RepoUID: repo.GitUID}, Name: pr.TargetBranch, - Type: gitrpc.RefTypeBranch, + Type: gitrpcenum.RefTypeBranch, }) if err != nil { return nil, fmt.Errorf("failed to get git branch sha: %w", err) } - if ref == nil || ref.SHA == "" { + if ref.SHA == "" { return nil, usererror.BadRequest("Failed to get branch SHA. Does the branch still exist?") }