fix: [CODE-199]: Merge to main

This commit is contained in:
Akhilesh Pandey 2023-05-18 15:58:23 +05:30
commit 9a1b539267
65 changed files with 503 additions and 377 deletions

View File

@ -112,17 +112,6 @@ linters-settings:
# Default: 30
max-func-lines: 30
nolintlint:
# Exclude following linters from requiring an explanation.
# Default: []
allow-no-explanation: [ funlen, gocognit, lll ]
# Enable to require an explanation of nonzero length after each nolint directive.
# Default: false
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed.
# Default: false
require-specific: true
rowserrcheck:
# database/sql is always checked
# Default: []
@ -217,7 +206,7 @@ linters:
- exhaustive # checks exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # forbids identifiers
- funlen # tool for detection of long functions
#- funlen # tool for detection of long functions
#- gochecknoglobals # checks that no global variables exist
#- gochecknoinits # checks that no init functions are present in Go code
- gocognit # computes and checks the cognitive complexity of functions
@ -238,7 +227,7 @@ linters:
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
- noctx # finds sending http request without context.Context
- nolintlint # reports ill-formed or insufficient nolint directives
# - nolintlint # reports ill-formed or insufficient nolint directives
# - nonamedreturns # reports all named returns
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
- predeclared # finds code that shadows one of Go's predeclared identifiers
@ -283,7 +272,7 @@ linters:
#- importas # enforces consistent import aliases
#- logrlint # [owner archived repository] checks logr arguments
#- maintidx # measures the maintainability index of each function
#- misspell # [useless] finds commonly misspelled English words in comments
- misspell # [useless] finds commonly misspelled English words in comments
#- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
#- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
#- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers

View File

@ -53,7 +53,7 @@ func getArguments() []string {
command := os.Args[0]
args := os.Args[1:]
// in case of githooks, translate the arguments comming from git to work with gitness.
// in case of githooks, translate the arguments coming from git to work with gitness.
if gitArgs, fromGit := githook.SanitizeArgsForGit(command, args); fromGit {
return append([]string{hooks.ParamHooks}, gitArgs...)
}

View File

@ -7,6 +7,7 @@ package server
import (
"context"
"github.com/harness/gitness/events"
"github.com/harness/gitness/gitrpc"
server2 "github.com/harness/gitness/gitrpc/server"
@ -176,7 +177,7 @@ func initSystem(ctx context.Context, config *types.Config) (*system, error) {
if err != nil {
return nil, err
}
cronManager := cron.ProvideCronManager(serverConfig)
manager := cron.ProvideManager(serverConfig)
repoGitInfoView := database.ProvideRepoGitInfoView(db)
repoGitInfoCache := cache.ProvideRepoGitInfoCache(repoGitInfoView)
pubsubConfig := pubsub.ProvideConfig(config)
@ -186,6 +187,6 @@ func initSystem(ctx context.Context, config *types.Config) (*system, error) {
return nil, err
}
servicesServices := services.ProvideServices(webhookService, pullreqService)
serverSystem := newSystem(bootstrapBootstrap, serverServer, server3, cronManager, servicesServices)
serverSystem := newSystem(bootstrapBootstrap, serverServer, server3, manager, servicesServices)
return serverSystem, nil
}

View File

@ -7,6 +7,7 @@ package server
import (
"context"
"github.com/harness/gitness/events"
"github.com/harness/gitness/gitrpc"
server2 "github.com/harness/gitness/gitrpc/server"
@ -143,7 +144,7 @@ func initSystem(ctx context.Context, config *types.Config) (*system, error) {
if err != nil {
return nil, err
}
cronManager := cron.ProvideCronManager(serverConfig)
manager := cron.ProvideManager(serverConfig)
repoGitInfoView := database.ProvideRepoGitInfoView(db)
repoGitInfoCache := cache.ProvideRepoGitInfoCache(repoGitInfoView)
pubsubConfig := pubsub.ProvideConfig(config)
@ -153,6 +154,6 @@ func initSystem(ctx context.Context, config *types.Config) (*system, error) {
return nil, err
}
servicesServices := services.ProvideServices(webhookService, pullreqService)
serverSystem := newSystem(bootstrapBootstrap, serverServer, server3, cronManager, servicesServices)
serverSystem := newSystem(bootstrapBootstrap, serverServer, server3, manager, servicesServices)
return serverSystem, nil
}

View File

@ -18,12 +18,12 @@ type system struct {
server *server.Server
gitRPCServer *gitrpcserver.Server
services services.Services
gitRPCCronMngr *gitrpccron.CronManager
gitRPCCronMngr *gitrpccron.Manager
}
// newSystem returns a new system structure.
func newSystem(bootstrap bootstrap.Bootstrap, server *server.Server, gitRPCServer *gitrpcserver.Server,
gitrpccron *gitrpccron.CronManager, services services.Services) *system {
gitrpccron *gitrpccron.Manager, services services.Services) *system {
return &system{
bootstrap: bootstrap,
server: server,

View File

@ -60,7 +60,7 @@ func (f *ReaderFactory[R]) Launch(ctx context.Context,
category: f.category,
}
// create new reader (could return the innerReader itself, but also allows to launch costumized readers)
// create new reader (could return the innerReader itself, but also allows to launch customized readers)
reader, err := f.readerFactoryFn(innerReader)
if err != nil {
//nolint:gocritic // only way to achieve this AFAIK - lint proposal is not building
@ -165,7 +165,7 @@ func ReaderRegisterEvent[T interface{}](reader *GenericReader,
}
// retrieve bytes from raw event
// NOTE: Redis returns []byte as string - to avoid unnecessary convertion we handle both types here.
// NOTE: Redis returns []byte as string - to avoid unnecessary conversion we handle both types here.
var eventBytes []byte
switch v := eventRaw.(type) {
case string:

View File

@ -76,6 +76,8 @@ type ListCommitsParams struct {
Page int32
Limit int32
Path string
Since int64
Until int64
}
type RenameDetails struct {
@ -100,6 +102,8 @@ func (c *Client) ListCommits(ctx context.Context, params *ListCommitsParams) (*L
Page: params.Page,
Limit: params.Limit,
Path: params.Path,
Since: params.Since,
Until: params.Until,
})
if err != nil {
return nil, fmt.Errorf("failed to start stream for commits: %w", err)

View File

@ -1,3 +1,7 @@
// 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"

View File

@ -81,23 +81,26 @@ func getGiteaCommits(giteaRepo *gitea.Repository, commitIDs []string) ([]*gitea.
return giteaCommits, nil
}
func (g Adapter) listCommitSHAs(giteaRepo *gitea.Repository,
ref string, afterRef string,
page int, limit int, path string,
func (g Adapter) listCommitSHAs(
giteaRepo *gitea.Repository,
ref string,
page int,
limit int,
filter types.CommitFilter,
) ([]string, error) {
args := make([]string, 0, 8)
args := make([]string, 0, 16)
args = append(args, "rev-list")
// return commits only up to a certain reference if requested
if afterRef != "" {
if filter.AfterRef != "" {
// ^REF tells the rev-list command to return only commits that aren't reachable by SHA
args = append(args, fmt.Sprintf("^%s", afterRef))
args = append(args, fmt.Sprintf("^%s", filter.AfterRef))
}
// add refCommitSHA as starting point
args = append(args, ref)
if len(path) != 0 {
args = append(args, "--", path)
if len(filter.Path) != 0 {
args = append(args, "--", filter.Path)
}
// add pagination if requested
@ -110,6 +113,16 @@ func (g Adapter) listCommitSHAs(giteaRepo *gitea.Repository,
}
}
if filter.Since > 0 || filter.Until > 0 {
args = append(args, "--date", "unix")
}
if filter.Since > 0 {
args = append(args, "--since", strconv.FormatInt(filter.Since, 10))
}
if filter.Until > 0 {
args = append(args, "--until", strconv.FormatInt(filter.Until, 10))
}
stdout, _, runErr := gitea.NewCommand(giteaRepo.Ctx, args...).RunStdBytes(&gitea.RunOpts{Dir: giteaRepo.Path})
if runErr != nil {
// TODO: handle error in case they don't have a common merge base!
@ -122,10 +135,13 @@ func (g Adapter) listCommitSHAs(giteaRepo *gitea.Repository,
// ListCommitSHAs lists the commits reachable from ref.
// Note: ref & afterRef can be Branch / Tag / CommitSHA.
// Note: commits returned are [ref->...->afterRef).
func (g Adapter) ListCommitSHAs(ctx context.Context,
func (g Adapter) ListCommitSHAs(
ctx context.Context,
repoPath string,
ref string, afterRef string,
page int, limit int, path string,
ref string,
page int,
limit int,
filter types.CommitFilter,
) ([]string, error) {
giteaRepo, err := gitea.OpenRepository(ctx, repoPath)
if err != nil {
@ -133,7 +149,7 @@ func (g Adapter) ListCommitSHAs(ctx context.Context,
}
defer giteaRepo.Close()
return g.listCommitSHAs(giteaRepo, ref, afterRef, page, limit, path)
return g.listCommitSHAs(giteaRepo, ref, page, limit, filter)
}
// ListCommits lists the commits reachable from ref.
@ -141,8 +157,8 @@ func (g Adapter) ListCommitSHAs(ctx context.Context,
// Note: commits returned are [ref->...->afterRef).
func (g Adapter) ListCommits(ctx context.Context,
repoPath string,
ref string, afterRef string,
page int, limit int, path string,
ref string,
page int, limit int, filter types.CommitFilter,
) ([]types.Commit, *types.PathRenameDetails, error) {
giteaRepo, err := gitea.OpenRepository(ctx, repoPath)
if err != nil {
@ -150,7 +166,7 @@ func (g Adapter) ListCommits(ctx context.Context,
}
defer giteaRepo.Close()
commitSHAs, err := g.listCommitSHAs(giteaRepo, ref, afterRef, page, limit, path)
commitSHAs, err := g.listCommitSHAs(giteaRepo, ref, page, limit, filter)
if err != nil {
return nil, nil, err
}
@ -170,8 +186,8 @@ func (g Adapter) ListCommits(ctx context.Context,
commits[i] = *commit
}
if len(path) != 0 {
renameDetails, err := giteaGetRenameDetails(giteaRepo, commits[0].SHA, path)
if len(filter.Path) != 0 {
renameDetails, err := giteaGetRenameDetails(giteaRepo, commits[0].SHA, filter.Path)
if err != nil {
return nil, nil, err
}

View File

@ -18,9 +18,9 @@ import (
"github.com/harness/gitness/gitrpc/enum"
"github.com/harness/gitness/gitrpc/internal/tempdir"
"github.com/harness/gitness/gitrpc/internal/types"
"github.com/rs/zerolog/log"
"code.gitea.io/gitea/modules/git"
"github.com/rs/zerolog/log"
)
// CreateTemporaryRepo creates a temporary repo with "base" for pr.BaseBranch and "tracking" for pr.HeadBranch
@ -251,6 +251,9 @@ func commitAndSignNoAuthor(
return nil
}
// Merge merges changes between 2 refs (branch, commits or tags).
//
//nolint:gocognit,nestif
func (g Adapter) Merge(
ctx context.Context,
pr *types.PullRequest,
@ -288,7 +291,7 @@ func (g Adapter) Merge(
// Merge with squash
cmd := git.NewCommand(ctx, "merge", "--squash", trackingBranch)
if err := runMergeCommand(ctx, pr, mergeMethod, cmd, tmpBasePath, env); err != nil {
return fmt.Errorf("unable to merge --squash tracking into base: %v", err)
return fmt.Errorf("unable to merge --squash tracking into base: %w", err)
}
if signArg == "" {
@ -322,7 +325,10 @@ func (g Adapter) Merge(
Stdout: &outbuf,
Stderr: &errbuf,
}); err != nil {
return fmt.Errorf("git checkout base prior to merge post staging rebase [%s -> %s]: %v\n%s\n%s", pr.HeadBranch, pr.BaseBranch, err, outbuf.String(), errbuf.String())
return fmt.Errorf(
"git checkout base prior to merge post staging rebase [%s -> %s]: %w\n%s\n%s",
pr.HeadBranch, pr.BaseBranch, err, outbuf.String(), errbuf.String(),
)
}
outbuf.Reset()
errbuf.Reset()
@ -337,25 +343,35 @@ func (g Adapter) Merge(
// Rebase will leave a REBASE_HEAD file in .git if there is a conflict
if _, statErr := os.Stat(filepath.Join(tmpBasePath, ".git", "REBASE_HEAD")); statErr == nil {
var commitSha string
// TBD git version we will support
// failingCommitPath := filepath.Join(tmpBasePath, ".git", "rebase-apply", "original-commit") // Git < 2.26
// if _, statErr := os.Stat(failingCommitPath); statErr != nil {
// return fmt.Errorf("git rebase staging on to base [%s -> %s]: %v\n%s\n%s", pr.HeadBranch, pr.BaseBranch, err, outbuf.String(), errbuf.String())
// if _, cpErr := os.Stat(failingCommitPath); statErr != nil {
// return fmt.Errorf("git rebase staging on to base [%s -> %s]: %v\n%s\n%s",
// pr.HeadBranch, pr.BaseBranch, cpErr, outbuf.String(), errbuf.String())
// }
failingCommitPath := filepath.Join(tmpBasePath, ".git", "rebase-merge", "stopped-sha") // Git >= 2.26
if _, statErr := os.Stat(failingCommitPath); statErr != nil {
return fmt.Errorf("git rebase staging on to base [%s -> %s]: %v\n%s\n%s", pr.HeadBranch, pr.BaseBranch, err, outbuf.String(), errbuf.String())
if _, cpErr := os.Stat(failingCommitPath); cpErr != nil {
return fmt.Errorf(
"git rebase staging on to base [%s -> %s]: %w\n%s\n%s",
pr.HeadBranch, pr.BaseBranch, cpErr, outbuf.String(), errbuf.String(),
)
}
commitShaBytes, readErr := os.ReadFile(failingCommitPath)
if readErr != nil {
// Abandon this attempt to handle the error
return fmt.Errorf("git rebase staging on to base [%s -> %s]: %v\n%s\n%s", pr.HeadBranch, pr.BaseBranch, err, outbuf.String(), errbuf.String())
return fmt.Errorf(
"git rebase staging on to base [%s -> %s]: %w\n%s\n%s",
pr.HeadBranch, pr.BaseBranch, readErr, outbuf.String(), errbuf.String(),
)
}
commitSha = strings.TrimSpace(string(commitShaBytes))
log.Debug().Msgf("RebaseConflict at %s [%s -> %s]: %v\n%s\n%s", commitSha, pr.HeadBranch, pr.BaseBranch, err, outbuf.String(), errbuf.String())
log.Debug().Msgf("RebaseConflict at %s [%s -> %s]: %v\n%s\n%s",
commitSha, pr.HeadBranch, pr.BaseBranch, err, outbuf.String(), errbuf.String(),
)
return &types.MergeConflictsError{
Method: mergeMethod,
CommitSHA: commitSha,
@ -364,7 +380,10 @@ func (g Adapter) Merge(
Err: err,
}
}
return fmt.Errorf("git rebase staging on to base [%s -> %s]: %v\n%s\n%s", pr.HeadBranch, pr.BaseBranch, err, outbuf.String(), errbuf.String())
return fmt.Errorf(
"git rebase staging on to base [%s -> %s]: %w\n%s\n%s",
pr.HeadBranch, pr.BaseBranch, err, outbuf.String(), errbuf.String(),
)
}
outbuf.Reset()
errbuf.Reset()
@ -376,7 +395,10 @@ func (g Adapter) Merge(
Stdout: &outbuf,
Stderr: &errbuf,
}); err != nil {
return fmt.Errorf("git checkout base prior to merge post staging rebase [%s -> %s]: %v\n%s\n%s", pr.HeadBranch, pr.BaseBranch, err, outbuf.String(), errbuf.String())
return fmt.Errorf(
"git checkout base prior to merge post staging rebase [%s -> %s]: %w\n%s\n%s",
pr.HeadBranch, pr.BaseBranch, err, outbuf.String(), errbuf.String(),
)
}
outbuf.Reset()
errbuf.Reset()

View File

@ -9,13 +9,13 @@ import (
"context"
"errors"
"fmt"
"github.com/harness/gitness/gitrpc/rpc"
"io"
"strconv"
"strings"
"time"
"github.com/harness/gitness/gitrpc/internal/types"
"github.com/harness/gitness/gitrpc/rpc"
gitea "code.gitea.io/gitea/modules/git"
)
@ -62,7 +62,12 @@ func (g Adapter) GetAnnotatedTags(ctx context.Context, repoPath string, shas []s
return tags, nil
}
func (g Adapter) CreateAnnotatedTag(ctx context.Context, repoPath string, request *rpc.CreateTagRequest, env []string) error {
func (g Adapter) CreateAnnotatedTag(
ctx context.Context,
repoPath string,
request *rpc.CreateTagRequest,
env []string,
) error {
cmd := gitea.NewCommand(ctx, "tag", "-a", "-m", request.GetMessage(), "--", request.GetTagName(), request.GetSha())
_, _, err := cmd.RunStdString(&gitea.RunOpts{Dir: repoPath, Env: env})
if err != nil {
@ -75,7 +80,7 @@ func (g Adapter) DeleteTag(ctx context.Context, repoPath string, ref string, env
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", stdErr)
return processGiteaErrorf(err, "Service failed to delete tag with error: %v", stdErr)
}
return nil
}
@ -200,7 +205,7 @@ func giteaParseCatFileLine(data []byte, start int, header string) (string, int,
return "", 0, fmt.Errorf("expected '%s' but started with '%s'", header, string(data[:lenHeader]))
}
// get end of line and start of next line (used externaly, transpose with provided start index)
// get end of line and start of next line (used externally, transpose with provided start index)
lineEnd := bytes.IndexByte(data, '\n')
externalNextLine := start + lineEnd + 1
if lineEnd == -1 {

View File

@ -70,7 +70,7 @@ func (g Adapter) GetTreeNode(ctx context.Context, repoPath string,
func (g Adapter) ListTreeNodes(ctx context.Context, repoPath string,
ref string, treePath string, recursive bool, includeLatestCommit bool) ([]types.TreeNodeWithCommit, error) {
if recursive && includeLatestCommit {
// To avoid potential performance catastrophies, block recursive with includeLatestCommit
// To avoid potential performance catastrophe, block recursive with includeLatestCommit
// TODO: this should return bad error to caller if needed?
// TODO: should this be refactored in two methods?
return nil, fmt.Errorf("latest commit with recursive query is not supported")

View File

@ -175,7 +175,7 @@ func (s ReferenceService) ListBranches(request *rpc.ListBranchesRequest,
ctx := stream.Context()
repoPath := getFullPathForRepo(s.reposRoot, base.GetRepoUid())
// get all required information from git refrences
// get all required information from git references
branches, err := s.listBranchesLoadReferenceData(ctx, repoPath, request)
if err != nil {
return err

View File

@ -56,7 +56,10 @@ func (s RepositoryService) ListCommits(request *rpc.ListCommitsRequest,
repoPath := getFullPathForRepo(s.reposRoot, base.GetRepoUid())
gitCommits, renameDetails, err := s.adapter.ListCommits(ctx, repoPath, request.GetGitRef(),
request.GetAfter(), int(request.GetPage()), int(request.GetLimit()), request.GetPath())
int(request.GetPage()), int(request.GetLimit()), types.CommitFilter{AfterRef: request.After,
Path: request.Path,
Since: request.Since,
Until: request.Until})
if err != nil {
return processGitErrorf(err, "failed to get list of commits")
}

View File

@ -124,7 +124,8 @@ func (s DiffService) DiffCut(
return nil, processGitErrorf(err, "failed to find merge base")
}
sourceCommits, err := s.adapter.ListCommitSHAs(ctx, repoPath, r.SourceBranch, r.TargetBranch, 0, 1, "")
sourceCommits, err := s.adapter.ListCommitSHAs(ctx, repoPath, r.SourceBranch, 0, 1,
types.CommitFilter{AfterRef: r.TargetBranch})
if err != nil || len(sourceCommits) == 0 {
return nil, processGitErrorf(err, "failed to get list of source branch commits")
}

View File

@ -6,11 +6,11 @@ package service
import (
"context"
"github.com/harness/gitness/gitrpc/rpc"
"io"
"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.
@ -33,9 +33,9 @@ type GitAdapter interface {
GetCommit(ctx context.Context, repoPath string, ref string) (*types.Commit, error)
GetCommits(ctx context.Context, repoPath string, refs []string) ([]types.Commit, error)
ListCommits(ctx context.Context, repoPath string,
ref string, afterRef string, page int, limit int, path string) ([]types.Commit, *types.PathRenameDetails, error)
ref string, page int, limit int, filter types.CommitFilter) ([]types.Commit, *types.PathRenameDetails, error)
ListCommitSHAs(ctx context.Context, repoPath string,
ref string, afterRef string, page int, limit int, path string) ([]string, error)
ref string, page int, limit int, filter types.CommitFilter) ([]string, error)
GetLatestCommit(ctx context.Context, repoPath string, ref string, treePath string) (*types.Commit, error)
GetFullCommitID(ctx context.Context, repoPath, shortID string) (string, error)
GetAnnotatedTag(ctx context.Context, repoPath string, sha string) (*types.Tag, error)

View File

@ -66,7 +66,7 @@ func (s MergeService) Merge(
defer func() {
rmErr := tempdir.RemoveTemporaryPath(tmpBasePath)
if rmErr != nil {
log.Ctx(ctx).Warn().Msgf("Removing temporary location %s for merge operation was not successfull", tmpBasePath)
log.Ctx(ctx).Warn().Msgf("Removing temporary location %s for merge operation was not successful", tmpBasePath)
}
}()

View File

@ -87,7 +87,7 @@ func (s *CommitFilesService) CommitFiles(stream rpc.CommitFilesService_CommitFil
// check if repo is empty
// IMPORTANT: we don't use gitea's repo.IsEmpty() as that only checks whether the default branch exists (in HEAD).
// This can be an issue in case someone created a branch already in the repo (just default branch is missing).
// In that case the user can accidentaly create separate git histories (which most likely is unintended).
// In that case the user can accidentally create separate git histories (which most likely is unintended).
// If the user wants to actually build a disconnected commit graph they can use the cli.
isEmpty, err := repoHasBranches(ctx, repo)
if err != nil {
@ -225,7 +225,7 @@ func (s *CommitFilesService) validateAndPrepareHeader(repo *git.Repository, isEm
header.BranchName = strings.TrimPrefix(strings.TrimSpace(header.GetBranchName()), gitReferenceNamePrefixBranch)
header.NewBranchName = strings.TrimPrefix(strings.TrimSpace(header.GetNewBranchName()), gitReferenceNamePrefixBranch)
// if the repo is empty then we can skip branch existance checks
// if the repo is empty then we can skip branch existence checks
if isEmpty {
return nil
}

View File

@ -10,7 +10,7 @@ import (
)
// getFullPathForRepo returns the full path of a repo given the root dir of repos and the uid of the repo.
// NOTE: Split repos into subfolders using their prefix to distribute repos accross a set of folders.
// NOTE: Split repos into subfolders using their prefix to distribute repos across a set of folders.
func getFullPathForRepo(reposRoot, uid string) string {
// ASSUMPTION: repoUID is of lenth at least 4 - otherwise we have trouble either way.
return filepath.Join(

View File

@ -78,7 +78,7 @@ func createReferenceWalkPatternsFromQuery(basePath string, query string) []strin
return []string{}
}
// ensure non-empty basepath ends with "/" for proper matching and concatination.
// ensure non-empty basepath ends with "/" for proper matching and concatenation.
if basePath != "" && basePath[len(basePath)-1] != '/' {
basePath += "/"
}

View File

@ -5,11 +5,13 @@
package service
import (
"code.gitea.io/gitea/modules/git"
"context"
"fmt"
"github.com/harness/gitness/gitrpc/internal/types"
"github.com/harness/gitness/gitrpc/rpc"
"code.gitea.io/gitea/modules/git"
"github.com/rs/zerolog/log"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@ -183,7 +185,10 @@ func listCommitTagsWalkReferencesHandler(tags *[]*rpc.CommitTag) types.WalkRefer
return nil
}
}
func (s ReferenceService) CreateTag(ctx context.Context, request *rpc.CreateTagRequest) (*rpc.CreateTagResponse, error) {
func (s ReferenceService) CreateTag(
ctx context.Context,
request *rpc.CreateTagRequest,
) (*rpc.CreateTagResponse, error) {
base := request.GetBase()
if base == nil {
return nil, types.ErrBaseCannotBeEmpty
@ -233,7 +238,10 @@ func (s ReferenceService) CreateTag(ctx context.Context, request *rpc.CreateTagR
return &rpc.CreateTagResponse{Tag: commitTag}, nil
}
func (s ReferenceService) DeleteTag(ctx context.Context, request *rpc.DeleteTagRequest) (*rpc.UpdateRefResponse, error) {
func (s ReferenceService) DeleteTag(
ctx context.Context,
request *rpc.DeleteTagRequest,
) (*rpc.UpdateRefResponse, error) {
base := request.GetBase()
if base == nil {
return nil, types.ErrBaseCannotBeEmpty
@ -263,6 +271,7 @@ func (s ReferenceService) DeleteTag(ctx context.Context, request *rpc.DeleteTagR
"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())

View File

@ -296,3 +296,10 @@ type PathRenameDetails struct {
OldPath string
NewPath string
}
type CommitFilter struct {
Path string
AfterRef string
Since int64
Until int64
}

View File

@ -208,7 +208,7 @@ func mapRPCTreeNodeType(t rpc.TreeNodeType) (TreeNodeType, error) {
case rpc.TreeNodeType_TreeNodeTypeTree:
return TreeNodeTypeTree, nil
default:
return TreeNodeTypeBlob, fmt.Errorf("unkown rpc tree node type: %d", t)
return TreeNodeTypeBlob, fmt.Errorf("unknown rpc tree node type: %d", t)
}
}
@ -225,7 +225,7 @@ func mapRPCTreeNodeMode(m rpc.TreeNodeMode) (TreeNodeMode, error) {
case rpc.TreeNodeMode_TreeNodeModeTree:
return TreeNodeModeTree, nil
default:
return TreeNodeModeFile, fmt.Errorf("unkown rpc tree node mode: %d", m)
return TreeNodeModeFile, fmt.Errorf("unknown rpc tree node mode: %d", m)
}
}

View File

@ -98,6 +98,8 @@ message ListCommitsRequest {
int32 page = 4;
int32 limit = 5;
string path = 6;
int64 since = 7;
int64 until = 8;
}
message ListCommitsResponse {

View File

@ -766,6 +766,8 @@ type ListCommitsRequest struct {
Page int32 `protobuf:"varint,4,opt,name=page,proto3" json:"page,omitempty"`
Limit int32 `protobuf:"varint,5,opt,name=limit,proto3" json:"limit,omitempty"`
Path string `protobuf:"bytes,6,opt,name=path,proto3" json:"path,omitempty"`
Since int64 `protobuf:"varint,7,opt,name=since,proto3" json:"since,omitempty"`
Until int64 `protobuf:"varint,8,opt,name=until,proto3" json:"until,omitempty"`
}
func (x *ListCommitsRequest) Reset() {
@ -842,6 +844,20 @@ func (x *ListCommitsRequest) GetPath() string {
return ""
}
func (x *ListCommitsRequest) GetSince() int64 {
if x != nil {
return x.Since
}
return 0
}
func (x *ListCommitsRequest) GetUntil() int64 {
if x != nil {
return x.Until
}
return 0
}
type ListCommitsResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -1826,7 +1842,7 @@ var file_repo_proto_rawDesc = []byte{
0x69, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x23, 0x0a, 0x06, 0x63, 0x6f,
0x6d, 0x6d, 0x69, 0x74, 0x18, 0x01, 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, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x73, 0x52,
0xd3, 0x01, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x73, 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, 0x17, 0x0a, 0x07,
@ -1836,156 +1852,159 @@ var file_repo_proto_rawDesc = []byte{
0x61, 0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x70, 0x61, 0x67, 0x65, 0x12,
0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05,
0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x06, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x22, 0x75, 0x0a, 0x13, 0x4c, 0x69, 0x73,
0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x12, 0x23, 0x0a, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x18, 0x01, 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, 0x12, 0x39, 0x0a, 0x0e, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x5f,
0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e,
0x72, 0x70, 0x63, 0x2e, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c,
0x73, 0x52, 0x0d, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73,
0x22, 0x64, 0x0a, 0x0d, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c,
0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x64,
0x12, 0x19, 0x0a, 0x08, 0x6f, 0x6c, 0x64, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x07, 0x6f, 0x6c, 0x64, 0x50, 0x61, 0x74, 0x68, 0x12, 0x19, 0x0a, 0x08, 0x6e,
0x65, 0x77, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e,
0x65, 0x77, 0x50, 0x61, 0x74, 0x68, 0x22, 0x67, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f,
0x62, 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, 0x10,
0x0a, 0x03, 0x73, 0x68, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x68, 0x61,
0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x03,
0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x73, 0x69, 0x7a, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22,
0x6b, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x12, 0x34, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x48, 0x00,
0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74,
0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x07, 0x63, 0x6f, 0x6e,
0x74, 0x65, 0x6e, 0x74, 0x42, 0x06, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x60, 0x0a, 0x15,
0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x48,
0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x68, 0x61, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x03, 0x73, 0x68, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18,
0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x63,
0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28,
0x03, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x53, 0x69, 0x7a, 0x65, 0x22, 0x68,
0x0a, 0x13, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 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, 0x17, 0x0a, 0x07, 0x67,
0x69, 0x74, 0x5f, 0x72, 0x65, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x69,
0x74, 0x52, 0x65, 0x66, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x22, 0x44, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x53,
0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x12, 0x2c, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x18, 0x01, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64,
0x75, 0x6c, 0x65, 0x52, 0x09, 0x73, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x22, 0x31,
0x0a, 0x09, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e,
0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12,
0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72,
0x6c, 0x22, 0x9a, 0x01, 0x0a, 0x1b, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44,
0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x69, 0x6e,
0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x69, 0x6e, 0x63, 0x65, 0x12,
0x14, 0x0a, 0x05, 0x75, 0x6e, 0x74, 0x69, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05,
0x75, 0x6e, 0x74, 0x69, 0x6c, 0x22, 0x75, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d,
0x6d, 0x69, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x23, 0x0a, 0x06,
0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x18, 0x01, 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, 0x12, 0x39, 0x0a, 0x0e, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x64, 0x65, 0x74, 0x61,
0x69, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x72, 0x70, 0x63, 0x2e,
0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x52, 0x0d, 0x72,
0x65, 0x6e, 0x61, 0x6d, 0x65, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x22, 0x64, 0x0a, 0x0d,
0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x12, 0x1d, 0x0a,
0x0a, 0x69, 0x73, 0x5f, 0x72, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x08, 0x52, 0x09, 0x69, 0x73, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x64, 0x12, 0x19, 0x0a, 0x08,
0x6f, 0x6c, 0x64, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
0x6f, 0x6c, 0x64, 0x50, 0x61, 0x74, 0x68, 0x12, 0x19, 0x0a, 0x08, 0x6e, 0x65, 0x77, 0x5f, 0x70,
0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x77, 0x50, 0x61,
0x74, 0x68, 0x22, 0x67, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 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, 0x10, 0x0a, 0x03, 0x73, 0x68,
0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x68, 0x61, 0x12, 0x1d, 0x0a, 0x0a,
0x73, 0x69, 0x7a, 0x65, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03,
0x52, 0x09, 0x73, 0x69, 0x7a, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x6b, 0x0a, 0x0f, 0x47,
0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x34,
0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a,
0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x48, 0x00, 0x52, 0x06, 0x68, 0x65,
0x61, 0x64, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18,
0x02, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
0x42, 0x06, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x60, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x42,
0x6c, 0x6f, 0x62, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x48, 0x65, 0x61, 0x64, 0x65,
0x72, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x68, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
0x73, 0x68, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
0x03, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x65,
0x6e, 0x74, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x63,
0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x53, 0x69, 0x7a, 0x65, 0x22, 0x68, 0x0a, 0x13, 0x47, 0x65,
0x74, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 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, 0x1b, 0x0a, 0x09, 0x6d, 0x61, 0x78, 0x5f, 0x63,
0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x6d, 0x61, 0x78, 0x43,
0x6f, 0x75, 0x6e, 0x74, 0x12, 0x38, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73,
0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6f, 0x6d,
0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x22, 0x3d,
0x0a, 0x17, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e,
0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f,
0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x0e, 0x0a,
0x02, 0x74, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x74, 0x6f, 0x22, 0x57, 0x0a,
0x1c, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67,
0x65, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x37, 0x0a,
0x0b, 0x64, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03,
0x28, 0x0b, 0x32, 0x15, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44,
0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x0b, 0x64, 0x69, 0x76, 0x65, 0x72,
0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x22, 0x40, 0x0a, 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x68,
0x65, 0x61, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x61, 0x68, 0x65, 0x61, 0x64,
0x12, 0x16, 0x0a, 0x06, 0x62, 0x65, 0x68, 0x69, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05,
0x52, 0x06, 0x62, 0x65, 0x68, 0x69, 0x6e, 0x64, 0x22, 0x40, 0x0a, 0x17, 0x44, 0x65, 0x6c, 0x65,
0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 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, 0x22, 0x1a, 0x0a, 0x18, 0x44, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x60, 0x0a, 0x10, 0x4d, 0x65, 0x72, 0x67, 0x65, 0x42,
0x61, 0x73, 0x65, 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, 0x12, 0x0a, 0x04, 0x72, 0x65, 0x66, 0x31, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x72, 0x65, 0x66, 0x31, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x65, 0x66, 0x32, 0x18, 0x03, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x72, 0x65, 0x66, 0x32, 0x22, 0x39, 0x0a, 0x11, 0x4d, 0x65, 0x72, 0x67,
0x65, 0x42, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a,
0x0e, 0x6d, 0x65, 0x72, 0x67, 0x65, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6d, 0x65, 0x72, 0x67, 0x65, 0x42, 0x61, 0x73, 0x65,
0x53, 0x68, 0x61, 0x2a, 0x52, 0x0a, 0x0c, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54,
0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54,
0x79, 0x70, 0x65, 0x54, 0x72, 0x65, 0x65, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65,
0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x10, 0x01, 0x12,
0x16, 0x0a, 0x12, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x43,
0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x10, 0x02, 0x2a, 0x81, 0x01, 0x0a, 0x0c, 0x54, 0x72, 0x65, 0x65,
0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65,
0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x10, 0x00, 0x12, 0x17,
0x0a, 0x13, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x53, 0x79,
0x6d, 0x6c, 0x69, 0x6e, 0x6b, 0x10, 0x01, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e,
0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x45, 0x78, 0x65, 0x63, 0x10, 0x02, 0x12, 0x14, 0x0a,
0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x54, 0x72, 0x65,
0x65, 0x10, 0x03, 0x12, 0x16, 0x0a, 0x12, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d,
0x6f, 0x64, 0x65, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x10, 0x04, 0x32, 0xd9, 0x05, 0x0a, 0x11,
0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x12, 0x51, 0x0a, 0x10, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73,
0x69, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x1c, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x72, 0x65, 0x61,
0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
0x74, 0x52, 0x04, 0x62, 0x61, 0x73, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x67, 0x69, 0x74, 0x5f, 0x72,
0x65, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x69, 0x74, 0x52, 0x65, 0x66,
0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x70, 0x61, 0x74, 0x68, 0x22, 0x44, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6d, 0x6f,
0x64, 0x75, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x09,
0x73, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x0e, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x52,
0x09, 0x73, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x22, 0x31, 0x0a, 0x09, 0x53, 0x75,
0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75,
0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x9a, 0x01,
0x0a, 0x1b, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72,
0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 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, 0x1b, 0x0a, 0x09, 0x6d, 0x61, 0x78, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74,
0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x6d, 0x61, 0x78, 0x43, 0x6f, 0x75, 0x6e, 0x74,
0x12, 0x38, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03,
0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44,
0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x22, 0x3d, 0x0a, 0x17, 0x43, 0x6f,
0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x6f, 0x18,
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x74, 0x6f, 0x22, 0x57, 0x0a, 0x1c, 0x47, 0x65, 0x74,
0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65,
0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x37, 0x0a, 0x0b, 0x64, 0x69, 0x76,
0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15,
0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72,
0x67, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x0b, 0x64, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63,
0x65, 0x73, 0x22, 0x40, 0x0a, 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65,
0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x68, 0x65, 0x61, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x61, 0x68, 0x65, 0x61, 0x64, 0x12, 0x16, 0x0a, 0x06,
0x62, 0x65, 0x68, 0x69, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x65,
0x68, 0x69, 0x6e, 0x64, 0x22, 0x40, 0x0a, 0x17, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65,
0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 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, 0x22, 0x1a, 0x0a, 0x18, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65,
0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x28, 0x01, 0x12, 0x40, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e,
0x6f, 0x64, 0x65, 0x12, 0x17, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x65,
0x65, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x72,
0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x48, 0x0a, 0x0d, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x72,
0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x19, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69,
0x73, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x72, 0x65,
0x65, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01,
0x12, 0x43, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
0x12, 0x18, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64,
0x75, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x70, 0x63,
0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x36, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62,
0x12, 0x13, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x42,
0x6c, 0x6f, 0x62, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x42, 0x0a,
0x0b, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x73, 0x12, 0x17, 0x2e, 0x72,
0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x73, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74,
0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30,
0x01, 0x12, 0x3a, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x12, 0x15,
0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43,
0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5b, 0x0a,
0x14, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67,
0x65, 0x6e, 0x63, 0x65, 0x73, 0x12, 0x20, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43,
0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x73,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65,
0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63,
0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4f, 0x0a, 0x10, 0x44, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x1c,
0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73,
0x69, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x72,
0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74,
0x6f, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3a, 0x0a, 0x09, 0x4d,
0x65, 0x72, 0x67, 0x65, 0x42, 0x61, 0x73, 0x65, 0x12, 0x15, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4d,
0x65, 0x72, 0x67, 0x65, 0x42, 0x61, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x16, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4d, 0x65, 0x72, 0x67, 0x65, 0x42, 0x61, 0x73, 0x65, 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,
0x73, 0x65, 0x22, 0x60, 0x0a, 0x10, 0x4d, 0x65, 0x72, 0x67, 0x65, 0x42, 0x61, 0x73, 0x65, 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, 0x12, 0x0a, 0x04,
0x72, 0x65, 0x66, 0x31, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x65, 0x66, 0x31,
0x12, 0x12, 0x0a, 0x04, 0x72, 0x65, 0x66, 0x32, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x72, 0x65, 0x66, 0x32, 0x22, 0x39, 0x0a, 0x11, 0x4d, 0x65, 0x72, 0x67, 0x65, 0x42, 0x61, 0x73,
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x0e, 0x6d, 0x65, 0x72,
0x67, 0x65, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x0c, 0x6d, 0x65, 0x72, 0x67, 0x65, 0x42, 0x61, 0x73, 0x65, 0x53, 0x68, 0x61, 0x2a,
0x52, 0x0a, 0x0c, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12,
0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x54,
0x72, 0x65, 0x65, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64,
0x65, 0x54, 0x79, 0x70, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x10, 0x01, 0x12, 0x16, 0x0a, 0x12, 0x54,
0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x43, 0x6f, 0x6d, 0x6d, 0x69,
0x74, 0x10, 0x02, 0x2a, 0x81, 0x01, 0x0a, 0x0c, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65,
0x4d, 0x6f, 0x64, 0x65, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65,
0x4d, 0x6f, 0x64, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x10, 0x00, 0x12, 0x17, 0x0a, 0x13, 0x54, 0x72,
0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x53, 0x79, 0x6d, 0x6c, 0x69, 0x6e,
0x6b, 0x10, 0x01, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d,
0x6f, 0x64, 0x65, 0x45, 0x78, 0x65, 0x63, 0x10, 0x02, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65,
0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x54, 0x72, 0x65, 0x65, 0x10, 0x03, 0x12,
0x16, 0x0a, 0x12, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x43,
0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x10, 0x04, 0x32, 0xd9, 0x05, 0x0a, 0x11, 0x52, 0x65, 0x70, 0x6f,
0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x51, 0x0a,
0x10, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72,
0x79, 0x12, 0x1c, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65,
0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x1d, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f,
0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01,
0x12, 0x40, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x12,
0x17, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64,
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47,
0x65, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x12, 0x48, 0x0a, 0x0d, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f,
0x64, 0x65, 0x73, 0x12, 0x19, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x72,
0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a,
0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64,
0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x43, 0x0a, 0x0c,
0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x18, 0x2e, 0x72,
0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74,
0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x36, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x12, 0x13, 0x2e, 0x72,
0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x14, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x42, 0x0a, 0x0b, 0x4c, 0x69, 0x73,
0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x73, 0x12, 0x17, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c,
0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x18, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d,
0x69, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x3a, 0x0a,
0x09, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x12, 0x15, 0x2e, 0x72, 0x70, 0x63,
0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x16, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69,
0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5b, 0x0a, 0x14, 0x47, 0x65, 0x74,
0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65,
0x73, 0x12, 0x20, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69,
0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d,
0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4f, 0x0a, 0x10, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65,
0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x1c, 0x2e, 0x72, 0x70, 0x63,
0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72,
0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44,
0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3a, 0x0a, 0x09, 0x4d, 0x65, 0x72, 0x67, 0x65,
0x42, 0x61, 0x73, 0x65, 0x12, 0x15, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4d, 0x65, 0x72, 0x67, 0x65,
0x42, 0x61, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x72, 0x70,
0x63, 0x2e, 0x4d, 0x65, 0x72, 0x67, 0x65, 0x42, 0x61, 0x73, 0x65, 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 (

View File

@ -1,3 +1,7 @@
// 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 cron
import (
@ -7,10 +11,11 @@ import (
"path/filepath"
"github.com/harness/gitness/gitrpc/server"
"github.com/rs/zerolog/log"
)
// cleanup repository graveyard
// cleanupRepoGraveyard cleanups repository graveyard.
func cleanupRepoGraveyard(ctx context.Context, graveyardpath string) error {
logger := log.Ctx(ctx)
repolist, err := os.ReadDir(graveyardpath)
@ -32,7 +37,7 @@ func cleanupRepoGraveyard(ctx context.Context, graveyardpath string) error {
return nil
}
func AddAllGitRPCCronJobs(cm *CronManager, gitrpcconfig server.Config) error {
func AddAllGitRPCCronJobs(cm *Manager, gitrpcconfig server.Config) error {
// periodic repository graveyard cleanup
graveyardpath := filepath.Join(gitrpcconfig.GitRoot, server.ReposGraveyardSubdirName)
err := cm.NewCronTask(Nightly, func(ctx context.Context) error { return cleanupRepoGraveyard(ctx, graveyardpath) })

View File

@ -1,8 +1,11 @@
// 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 cron
import (
"context"
"io/ioutil"
"os"
"testing"
)
@ -10,8 +13,8 @@ import (
func TestCleanupRepoGraveyardFunc(t *testing.T) {
ctx := context.Background()
tmpDir := t.TempDir()
//create a dummy repository
testRepo, _ := ioutil.TempDir(tmpDir, "TestRepo100")
// create a dummy repository
testRepo, _ := os.MkdirTemp(tmpDir, "TestRepo100")
err := cleanupRepoGraveyard(ctx, tmpDir)
if err != nil {
t.Error("cleanupRepoGraveyard failed")

View File

@ -1,3 +1,7 @@
// 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 cron
import (
@ -9,8 +13,8 @@ import (
"github.com/rs/zerolog/log"
)
// Format: seconds minute(0-59) hour(0-23) day of month(1-31) month(1-12) day of week(0-6).
const (
//Format: seconds minute(0-59) hour(0-23) day of month(1-31) month(1-12) day of week(0-6)
Hourly = "0 0 * * * *" // once an hour at minute 0
Nightly = "0 0 0 * * *" // once a day at midnight
Weekly = "0 0 0 * * 0" // once a week on Sun midnight
@ -18,25 +22,25 @@ const (
EverySecond = "* * * * * *" // every second (for testing)
)
var ErrFatal = errors.New("fatal error occured")
var ErrFatal = errors.New("fatal error occurred")
type CronManager struct {
type Manager struct {
c *cron.Cron
ctx context.Context
cancel context.CancelFunc
fatal chan error
}
// options could be location, logger, etc.
func NewCronManager() *CronManager {
return &CronManager{
// NewManager creates a cron manager.
func NewManager() *Manager {
return &Manager{
c: cron.New(cron.WithSeconds()),
fatal: make(chan error),
}
}
// add a new func to cron job
func (c *CronManager) NewCronTask(sepc string, job func(ctx context.Context) error) error {
// NewCronTask adds a new func to cron job.
func (c *Manager) NewCronTask(sepc string, job func(ctx context.Context) error) error {
_, err := c.c.AddFunc(sepc, func() {
jerr := job(c.ctx)
if jerr != nil { // check different severity of errors
@ -55,7 +59,7 @@ func (c *CronManager) NewCronTask(sepc string, job func(ctx context.Context) err
}
// Run the cron scheduler, or no-op if already running.
func (c *CronManager) Run(ctx context.Context) error {
func (c *Manager) Run(ctx context.Context) error {
c.ctx, c.cancel = context.WithCancel(ctx)
var err error
go func() {
@ -63,7 +67,7 @@ func (c *CronManager) Run(ctx context.Context) error {
case <-ctx.Done():
err = fmt.Errorf("context done: %w", ctx.Err())
case fErr := <-c.fatal:
err = fmt.Errorf("fatal error occured: %w", fErr)
err = fmt.Errorf("fatal error occurred: %w", fErr)
}
// stop scheduling of new jobs.

View File

@ -1,3 +1,7 @@
// 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 cron
import (
@ -8,7 +12,7 @@ import (
"time"
)
func run(cmngr *CronManager, ctx context.Context) chan error {
func run(ctx context.Context, cmngr *Manager) chan error {
cron := make(chan error)
go func() {
cron <- cmngr.Run(ctx)
@ -17,14 +21,14 @@ func run(cmngr *CronManager, ctx context.Context) chan error {
}
func TestCronManagerFatalErr(t *testing.T) {
cmngr := NewCronManager()
cmngr := NewManager()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_ = cmngr.NewCronTask(EverySecond, func(ctx context.Context) error {
return fmt.Errorf("inner: %w", ErrFatal)
})
select {
case ferr := <-run(cmngr, ctx):
case ferr := <-run(ctx, cmngr):
if ferr == nil {
t.Error("Cronmanager failed to receive fatal error")
}
@ -34,14 +38,14 @@ func TestCronManagerFatalErr(t *testing.T) {
}
func TestCronManagerNonFatalErr(t *testing.T) {
cmngr := NewCronManager()
cmngr := NewManager()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_ = cmngr.NewCronTask(EverySecond, func(ctx context.Context) error {
return errors.New("dummy error")
})
select {
case ferr := <-run(cmngr, ctx):
case ferr := <-run(ctx, cmngr):
if ferr != nil {
t.Error("Cronmanager failed at a non fatal error")
}
@ -50,7 +54,7 @@ func TestCronManagerNonFatalErr(t *testing.T) {
}
}
func TestCronManagerNewTask(t *testing.T) {
cmngr := NewCronManager()
cmngr := NewManager()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
a := 0
@ -61,7 +65,7 @@ func TestCronManagerNewTask(t *testing.T) {
})
select {
case cerr := <-run(cmngr, ctx):
case cerr := <-run(ctx, cmngr):
if cerr != nil {
t.Error("Cronmanager failed at Run:", cerr)
}
@ -73,7 +77,7 @@ func TestCronManagerNewTask(t *testing.T) {
}
func TestCronManagerStopOnCtxCancel(t *testing.T) {
cmngr := NewCronManager()
cmngr := NewManager()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
@ -88,7 +92,7 @@ func TestCronManagerStopOnCtxCancel(t *testing.T) {
}
func TestCronManagerStopOnCtxTimeout(t *testing.T) {
cmngr := NewCronManager()
cmngr := NewManager()
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()

View File

@ -1,15 +1,20 @@
// 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 cron
import (
"github.com/google/wire"
"github.com/harness/gitness/gitrpc/server"
"github.com/google/wire"
)
// WireSet provides a wire set for this package.
var WireSet = wire.NewSet(ProvideCronManager)
var WireSet = wire.NewSet(ProvideManager)
func ProvideCronManager(gitrpcconfig server.Config) *CronManager {
cmngr := NewCronManager()
func ProvideManager(gitrpcconfig server.Config) *Manager {
cmngr := NewManager()
_ = AddAllGitRPCCronJobs(cmngr, gitrpcconfig)
return cmngr
}

View File

@ -60,13 +60,13 @@ func (p *CreateTagParams) Validate() error {
}
if p.Name == "" {
return errors.New("Tag name cannot be empty")
return errors.New("tag name cannot be empty")
}
if p.SHA == "" {
return errors.New("Target cannot be empty")
return errors.New("target cannot be empty")
}
if p.Message == "" {
return errors.New("Message cannot be empty")
return errors.New("message cannot be empty")
}
return nil
}
@ -140,7 +140,6 @@ func (c *Client) ListCommitTags(ctx context.Context, params *ListCommitTagsParam
return output, nil
}
func (c *Client) CreateTag(ctx context.Context, params *CreateTagParams) (*CreateTagOutput, error) {
err := params.Validate()
if err != nil {
@ -167,11 +166,9 @@ func (c *Client) CreateTag(ctx context.Context, params *CreateTagParams) (*Creat
return &CreateTagOutput{
CommitTag: *commitTag,
}, nil
}
func (c *Client) DeleteTag(ctx context.Context, params *DeleteTagParams) error {
err := params.Validate()
if err != nil {

View File

@ -64,7 +64,7 @@ func (c *Controller) CommentStatus(
return errValidate
}
act, err = c.getCommentCheckChangeStatusAccess(ctx, session, pr, commentID)
act, err = c.getCommentCheckChangeStatusAccess(ctx, pr, commentID)
if err != nil {
return fmt.Errorf("failed to get comment: %w", err)
}

View File

@ -122,7 +122,7 @@ func (c *Controller) getRepoCheckAccess(ctx context.Context,
}
func (c *Controller) getCommentCheckModifyAccess(ctx context.Context,
session *auth.Session, pr *types.PullReq, commentID int64,
pr *types.PullReq, commentID int64,
) (*types.PullReqActivity, error) {
if commentID <= 0 {
return nil, usererror.BadRequest("A valid comment ID must be provided.")
@ -155,7 +155,7 @@ func (c *Controller) getCommentCheckModifyAccess(ctx context.Context,
func (c *Controller) getCommentCheckEditAccess(ctx context.Context,
session *auth.Session, pr *types.PullReq, commentID int64,
) (*types.PullReqActivity, error) {
comment, err := c.getCommentCheckModifyAccess(ctx, session, pr, commentID)
comment, err := c.getCommentCheckModifyAccess(ctx, pr, commentID)
if err != nil {
return nil, err
}
@ -168,9 +168,9 @@ func (c *Controller) getCommentCheckEditAccess(ctx context.Context,
}
func (c *Controller) getCommentCheckChangeStatusAccess(ctx context.Context,
session *auth.Session, pr *types.PullReq, commentID int64,
pr *types.PullReq, commentID int64,
) (*types.PullReqActivity, error) {
comment, err := c.getCommentCheckModifyAccess(ctx, session, pr, commentID)
comment, err := c.getCommentCheckModifyAccess(ctx, pr, commentID)
if err != nil {
return nil, err
}

View File

@ -29,7 +29,7 @@ type MergeInput struct {
// Merge merges the pull request.
//
//nolint:funlen // no need to refactor
//nolint:gocognit
func (c *Controller) Merge(
ctx context.Context,
session *auth.Session,
@ -84,11 +84,15 @@ func (c *Controller) Merge(
}
if pr.UnresolvedCount > 0 {
return types.MergeResponse{}, usererror.BadRequest("Pull requests with unresolved comments can't be merged. Resolve all the comments first.")
return types.MergeResponse{}, usererror.BadRequest(
"Pull requests with unresolved comments can't be merged. Resolve all the comments first.",
)
}
if pr.IsDraft {
return types.MergeResponse{}, usererror.BadRequest("Draft pull requests can't be merged. Clear the draft flag first.")
return types.MergeResponse{}, usererror.BadRequest(
"Draft pull requests can't be merged. Clear the draft flag first.",
)
}
reviewers, err := c.reviewerStore.List(ctx, pr.ID)

View File

@ -92,7 +92,7 @@ func (c *Controller) Create(
return nil
})
if err != nil {
return nil, fmt.Errorf("failed to aquire PullReqSeq number: %w", err)
return nil, fmt.Errorf("failed to acquire PullReqSeq number: %w", err)
}
pr := newPullReq(session, targetRepo.PullReqSeq, sourceRepo, targetRepo, in, sourceSHA, mergeBaseSHA)

View File

@ -7,6 +7,7 @@ package repo
import (
"context"
"fmt"
"github.com/harness/gitness/gitrpc"
apiauth "github.com/harness/gitness/internal/api/auth"
"github.com/harness/gitness/internal/auth"
@ -57,7 +58,7 @@ func (c *Controller) CreateTag(ctx context.Context, session *auth.Session,
commitTag, err := mapCommitTag(rpcOut.CommitTag)
if err != nil {
return nil, fmt.Errorf("failed to map tag recieved from service output: %w", err)
return nil, fmt.Errorf("failed to map tag received from service output: %w", err)
}
return &commitTag, nil
}

View File

@ -27,7 +27,7 @@ type CommitDivergenceRequest struct {
// From is the ref from which the counting of the diverging commits starts.
From string `json:"from"`
// To is the ref at which the counting of the diverging commits ends.
// If the value is empty the divergence is caluclated to the default branch of the repo.
// If the value is empty the divergence is calculated to the default branch of the repo.
To string `json:"to"`
}

View File

@ -20,7 +20,7 @@ import (
* ListCommits lists the commits of a repo.
*/
func (c *Controller) ListCommits(ctx context.Context, session *auth.Session,
repoRef string, gitRef string, filter *types.CommitFilter, path string) ([]types.Commit, *types.RenameDetails, error) {
repoRef string, gitRef string, filter *types.CommitFilter) ([]types.Commit, *types.RenameDetails, error) {
repo, err := c.repoStore.FindByRef(ctx, repoRef)
if err != nil {
return nil, nil, err
@ -41,7 +41,9 @@ func (c *Controller) ListCommits(ctx context.Context, session *auth.Session,
After: filter.After,
Page: int32(filter.Page),
Limit: int32(filter.Limit),
Path: path,
Path: filter.Path,
Since: filter.Since,
Until: filter.Until,
})
if err != nil {
return nil, nil, err

View File

@ -13,7 +13,7 @@ import (
"github.com/harness/gitness/types/enum"
)
// Delete deletes a sevice account.
// Delete deletes a service account.
func (c *Controller) Delete(ctx context.Context, session *auth.Session,
saUID string) error {
sa, err := findServiceAccountFromUID(ctx, c.principalStore, saUID)

View File

@ -15,7 +15,7 @@ import (
"github.com/rs/zerolog/log"
)
// DeleteToken deletes a token of a sevice account.
// DeleteToken deletes a token of a service account.
func (c *Controller) DeleteToken(ctx context.Context, session *auth.Session,
saUID string, tokenUID string) error {
sa, err := findServiceAccountFromUID(ctx, c.principalStore, saUID)

View File

@ -35,8 +35,13 @@ func (c *Controller) Delete(ctx context.Context, session *auth.Session, spaceRef
}
// DeleteNoAuth bypasses these permission
// PermissionSpaceDelete, PermissionSpaceView, PermissionRepoView, PermissionRepoDelete
func (c *Controller) DeleteNoAuth(ctx context.Context, session *auth.Session, spaceID int64, filter *types.SpaceFilter) error {
// PermissionSpaceDelete, PermissionSpaceView, PermissionRepoView, PermissionRepoDelete.
func (c *Controller) DeleteNoAuth(
ctx context.Context,
session *auth.Session,
spaceID int64,
filter *types.SpaceFilter,
) error {
subSpaces, _, err := c.ListSpacesNoAuth(ctx, spaceID, filter)
if err != nil {
return fmt.Errorf("failed to list space %d sub spaces: %w", spaceID, err)

View File

@ -1,3 +1,7 @@
// 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 space
import (
@ -11,7 +15,7 @@ import (
)
// deleteRepositoriesNoAuth does not check PermissionRepoView, and PermissionRepoDelete permissions
// Call this through Delete(Space) api to make sure the caller has DeleteSpace permission
// Call this through Delete(Space) api to make sure the caller has DeleteSpace permission.
func (c *Controller) deleteRepositoriesNoAuth(ctx context.Context, session *auth.Session, spaceID int64) error {
filter := &types.RepoFilter{
Page: 1,

View File

@ -26,11 +26,14 @@ func (c *Controller) ListRepositories(ctx context.Context, session *auth.Session
return nil, 0, err
}
return c.ListRepositoriesNoAuth(ctx, space.ID, filter)
}
// ListRepositoriesNoAuth list repositories WITHOUT checking for PermissionRepoView.
func (c *Controller) ListRepositoriesNoAuth(ctx context.Context, spaceID int64, filter *types.RepoFilter) ([]*types.Repository, int64, error) {
func (c *Controller) ListRepositoriesNoAuth(
ctx context.Context,
spaceID int64,
filter *types.RepoFilter,
) ([]*types.Repository, int64, error) {
count, err := c.repoStore.Count(ctx, spaceID, filter)
if err != nil {
return nil, 0, fmt.Errorf("failed to count child repos: %w", err)

View File

@ -29,7 +29,11 @@ func (c *Controller) ListSpaces(ctx context.Context, session *auth.Session,
}
// List spaces WITHOUT checking PermissionSpaceView.
func (c *Controller) ListSpacesNoAuth(ctx context.Context, spaceID int64, filter *types.SpaceFilter) ([]*types.Space, int64, error) {
func (c *Controller) ListSpacesNoAuth(
ctx context.Context,
spaceID int64,
filter *types.SpaceFilter,
) ([]*types.Space, int64, error) {
count, err := c.spaceStore.Count(ctx, spaceID, filter)
if err != nil {
return nil, 0, fmt.Errorf("failed to count child spaces: %w", err)

View File

@ -7,8 +7,10 @@ package controller
import (
"context"
"errors"
"github.com/harness/gitness/internal/store"
"github.com/harness/gitness/internal/store/database/dbtx"
"github.com/jmoiron/sqlx"
)
@ -16,7 +18,7 @@ type TxOptionRetryCount int
// TxOptLock runs the provided function inside a database transaction. If optimistic lock error occurs
// during the operation, the function will retry the whole transaction again (to the maximum of 5 times,
// but this can be overridden by providing an additional TxOptionRetryCount option)
// but this can be overridden by providing an additional TxOptionRetryCount option).
func TxOptLock(ctx context.Context,
db *sqlx.DB,
txFn func(ctx context.Context) error,

View File

@ -28,9 +28,13 @@ func HandleListCommits(repoCtrl *repo.Controller) http.HandlerFunc {
gitRef := request.GetGitRefFromQueryOrDefault(r, "")
filter := request.ParseCommitFilter(r)
filter, err := request.ParseCommitFilter(r)
if err != nil {
render.TranslatedUserError(w, err)
return
}
commits, _, err := repoCtrl.ListCommits(ctx, session, repoRef, gitRef, filter, "")
commits, _, err := repoCtrl.ListCommits(ctx, session, repoRef, gitRef, filter)
if err != nil {
render.TranslatedUserError(w, err)
return
@ -58,11 +62,13 @@ func HandleListCommitsV2(repoCtrl *repo.Controller) http.HandlerFunc {
gitRef := request.GetGitRefFromQueryOrDefault(r, "")
filter := request.ParseCommitFilter(r)
filter, err := request.ParseCommitFilter(r)
if err != nil {
render.TranslatedUserError(w, err)
return
}
path := request.GetPathFromQueryOrDefault(r, "")
commits, renameDetails, err := repoCtrl.ListCommits(ctx, session, repoRef, gitRef, filter, path)
commits, renameDetails, err := repoCtrl.ListCommits(ctx, session, repoRef, gitRef, filter)
if err != nil {
render.TranslatedUserError(w, err)
return

View File

@ -19,25 +19,25 @@ import (
// Attempt returns an http.HandlerFunc middleware that authenticates
// the http.Request if authentication payload is available.
func Attempt(authenticator authn.Authenticator) func(http.Handler) http.Handler {
return performAuthentication(authenticator, false)
return performAuthentication(authenticator, false, authn.AuthGitCaller)
}
// Required returns an http.HandlerFunc middleware that authenticates
// the http.Request and fails the request if no auth data was available.
func Required(authenticator authn.Authenticator) func(http.Handler) http.Handler {
return performAuthentication(authenticator, true)
return performAuthentication(authenticator, true, authn.AuthAPICaller)
}
// performAuthentication returns an http.HandlerFunc middleware that authenticates
// the http.Request if authentication payload is available.
// Depending on whether it is required or not, the request will be failed.
func performAuthentication(authenticator authn.Authenticator, required bool) func(http.Handler) http.Handler {
func performAuthentication(authenticator authn.Authenticator, required bool, caller authn.APICaller) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
log := hlog.FromRequest(r)
session, err := authenticator.Authenticate(r)
session, err := authenticator.Authenticate(r, caller)
if errors.Is(err, authn.ErrNoAuthData) {
if required {

View File

@ -182,6 +182,34 @@ var queryParameterPath = openapi3.ParameterOrRef{
},
}
var queryParameterSince = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QuerySince,
In: openapi3.ParameterInQuery,
Description: ptr.String("Epoch since when commit information should be retrieved."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
}
var queryParameterUntil = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryUntil,
In: openapi3.ParameterInQuery,
Description: ptr.String("Epoch until when commit information should be retrieved."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{
Type: ptrSchemaType(openapi3.SchemaTypeInteger),
},
},
},
}
var queryParameterIncludeCommit = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: request.QueryParamIncludeCommit,
@ -483,7 +511,7 @@ func repoOperations(reflector *openapi3.Reflector) {
opListCommitsV2.WithTags("repository")
opListCommitsV2.WithMapOfAnything(map[string]interface{}{"operationId": "listCommitsV2"})
opListCommitsV2.WithParameters(queryParameterGitRef, queryParameterAfterCommits, queryParameterPath,
queryParameterPage, queryParameterLimit)
queryParameterSince, queryParameterUntil, queryParameterPage, queryParameterLimit)
_ = reflector.SetRequest(&opListCommitsV2, new(listCommitsRequest), http.MethodGet)
_ = reflector.SetJSONResponse(&opListCommitsV2, []types.ListCommitResponse{}, http.StatusOK)
_ = reflector.SetJSONResponse(&opListCommitsV2, new(usererror.Error), http.StatusInternalServerError)

View File

@ -23,7 +23,7 @@ func Pagination(r *http.Request, w http.ResponseWriter, page, size, total int) {
// Add information that doesn't require total
PaginationNoTotal(r, w, page, size, page >= last)
// add information that requries total
// add information that requires total
uri := getPaginationBaseURL(r, page, size)
params := uri.Query()

View File

@ -18,6 +18,8 @@ const (
QueryLineFrom = "line_from"
QueryLineTo = "line_to"
QueryPath = "path"
QuerySince = "since"
QueryUntil = "until"
)
func GetGitRefFromQueryOrDefault(r *http.Request, deflt string) string {
@ -69,16 +71,35 @@ func ParseTagFilter(r *http.Request) *types.TagFilter {
}
// ParseCommitFilter extracts the commit filter from the url.
func ParseCommitFilter(r *http.Request) *types.CommitFilter {
func ParseCommitFilter(r *http.Request) (*types.CommitFilter, error) {
since, err := QueryParamAsPositiveInt64(r, QuerySince)
if err != nil {
return nil, err
}
until, err := QueryParamAsPositiveInt64(r, QueryUntil)
if err != nil {
return nil, err
}
return &types.CommitFilter{
After: QueryParamOrDefault(r, QueryParamAfter, ""),
PaginationFilter: types.PaginationFilter{
Page: ParsePage(r),
Limit: ParseLimit(r),
},
}
Path: QueryParamOrDefault(r, QueryPath, ""),
Since: since,
Until: until,
}, nil
}
func GetPathFromQueryOrDefault(r *http.Request, deflt string) string {
return QueryParamOrDefault(r, QueryPath, deflt)
}
func GetSinceFromQuery(r *http.Request) (int64, error) {
return QueryParamAsPositiveInt64(r, QuerySince)
}
func GetUntilFromQuery(r *http.Request) (int64, error) {
return QueryParamAsPositiveInt64(r, QueryUntil)
}

View File

@ -11,7 +11,7 @@ import (
var (
// ErrInternal is returned when an internal error occurred.
ErrInternal = New(http.StatusInternalServerError, "Internal error occured")
ErrInternal = New(http.StatusInternalServerError, "Internal error occurred")
// ErrInvalidToken is returned when the api request token is invalid.
ErrInvalidToken = New(http.StatusUnauthorized, "Invalid or missing token")

View File

@ -14,6 +14,16 @@ import (
var (
// ErrNoAuthData that is returned if the authorizer doesn't find any data in the request that can be used for auth.
ErrNoAuthData = errors.New("the request doesn't contain any auth data that can be used by the Authorizer")
// ErrNotAcceptedAuthData that is returned if the request is using an auth data that is not accepted by the authorizer.
// e.g, don't accept jwt (without allowedURI field) for git clone/pull request.
ErrNotAcceptedAuthMethod = errors.New("the request contains auth method that is not accepted by the Authorizer")
)
type APICaller string
const (
AuthAPICaller APICaller = "api"
AuthGitCaller APICaller = "git"
)
// Authenticator is an abstraction of an entity that's responsible for authenticating principals
@ -26,5 +36,5 @@ type Authenticator interface {
* (nil, ErrNoAuthData) - request doesn't contain any auth data
* (nil, err) - request contains auth data but verification failed
*/
Authenticate(r *http.Request) (*auth.Session, error)
Authenticate(r *http.Request, caller APICaller) (*auth.Session, error)
}

View File

@ -38,7 +38,7 @@ func NewTokenAuthenticator(
}
}
func (a *TokenAuthenticator) Authenticate(r *http.Request) (*auth.Session, error) {
func (a *TokenAuthenticator) Authenticate(r *http.Request, caller APICaller) (*auth.Session, error) {
ctx := r.Context()
str := extractToken(r)

View File

@ -26,7 +26,7 @@ type Authorizer interface {
* Returns
* (true, nil) - the action is permitted
* (false, nil) - the action is not permitted
* (false, err) - an error occured while performing the permission check and the action should be denied
* (false, err) - an error occurred while performing the permission check and the action should be denied
*/
Check(ctx context.Context,
session *auth.Session,
@ -40,7 +40,7 @@ type Authorizer interface {
* Returns
* (true, nil) - all requested actions are permitted
* (false, nil) - at least one requested action is not permitted
* (false, err) - an error occured while performing the permission check and all actions should be denied
* (false, err) - an error occurred while performing the permission check and all actions should be denied
*/
CheckAll(ctx context.Context,
session *auth.Session,

View File

@ -38,7 +38,7 @@ var (
ExecutionTimeout = 3 * time.Minute
)
// SanitizeArgsForGit sanitizes the command line arguments (os.Args) if the command indicates they are comming from git.
// SanitizeArgsForGit sanitizes the command line arguments (os.Args) if the command indicates they are coming from git.
// Returns the santized args and true if the call comes from git, otherwise the original args are returned with false.
func SanitizeArgsForGit(command string, args []string) ([]string, bool) {
switch command {

View File

@ -105,7 +105,7 @@ func (c *GitHook) PostReceive(ctx context.Context) error {
func handleServerHookOutput(out *types.ServerHookOutput, err error) error {
if err != nil {
return fmt.Errorf("an error occured when calling the server: %w", err)
return fmt.Errorf("an error occurred when calling the server: %w", err)
}
if out == nil {

View File

@ -314,7 +314,7 @@ func SetupWebhook(r chi.Router, webhookCtrl *webhook.Controller) {
func setupUser(r chi.Router, userCtrl *user.Controller) {
r.Route("/user", func(r chi.Router) {
// enforce principial authenticated and it's a user
// enforce principal authenticated and it's a user
r.Use(middlewareprincipal.RestrictTo(enum.PrincipalTypeUser))
r.Get("/", handleruser.HandleFind(userCtrl))

View File

@ -178,7 +178,7 @@ func (s *Service) executeWebhook(ctx context.Context, webhook *types.Webhook, tr
TriggerType: triggerType,
// for unexpected errors we don't retry - protect the system. User can retrigger manually (if body was set)
Result: enum.WebhookExecutionResultFatalError,
Error: "An unknown error occured",
Error: "An unknown error occurred",
}
defer func(oCtx context.Context, start time.Time) {
// set total execution time
@ -253,7 +253,7 @@ func (s *Service) executeWebhook(ctx context.Context, webhook *types.Webhook, tr
case err != nil:
// for all other errors we don't retry - protect the system. User can retrigger manually (if body was set)
tErr := fmt.Errorf("an error occured while sending the request: %w", err)
tErr := fmt.Errorf("an error occurred while sending the request: %w", err)
execution.Error = tErr.Error()
execution.Result = enum.WebhookExecutionResultFatalError
return &execution, tErr
@ -298,7 +298,7 @@ func (s *Service) prepareHTTPRequest(ctx context.Context, execution *types.Webho
err := json.NewEncoder(bBuff).Encode(body)
if err != nil {
// this is an internal issue, nothing the user can do - don't expose error details
execution.Error = "an error occured preparing the request body"
execution.Error = "an error occurred preparing the request body"
execution.Result = enum.WebhookExecutionResultFatalError
return nil, fmt.Errorf("failed to serialize body to json: %w", err)
}
@ -380,7 +380,7 @@ func handleWebhookResponse(execution *types.WebhookExecution, resp *http.Respons
var bodyRaw []byte
bodyRaw, err = io.ReadAll(io.LimitReader(resp.Body, responseBodyBytesLimit))
if err != nil {
tErr := fmt.Errorf("an error occured while reading the response body: %w", err)
tErr := fmt.Errorf("an error occurred while reading the response body: %w", err)
execution.Error = tErr.Error()
execution.Result = enum.WebhookExecutionResultRetriableError
return tErr

View File

@ -9,7 +9,7 @@ import (
)
// PrincipalUIDTransformation transforms a principalUID to a value that should be duplicate free.
// This allows us to simply switch between principalUIDs being case sensitive, insensitive or anything inbetween.
// This allows us to simply switch between principalUIDs being case sensitive, insensitive or anything in between.
type PrincipalUIDTransformation func(uid string) (string, error)
func ToLowerPrincipalUIDTransformation(uid string) (string, error) {
@ -17,7 +17,7 @@ func ToLowerPrincipalUIDTransformation(uid string) (string, error) {
}
// PathTransformation transforms a path to a value that should be duplicate free.
// This allows us to simply switch between paths being case sensitive, insensitive or anything inbetween.
// This allows us to simply switch between paths being case sensitive, insensitive or anything in between.
type PathTransformation func(string) (string, error)
func ToLowerPathTransformation(original string) (string, error) {

View File

@ -1,70 +0,0 @@
package main
import (
"encoding/gob"
"flag"
"fmt"
"os"
"path"
"reflect"
"github.com/golang/mock/mockgen/model"
pkg_ "github.com/harness/gitness/internal/store"
)
var output = flag.String("output", "", "The output file name, or empty to use stdout.")
func main() {
flag.Parse()
its := []struct{
sym string
typ reflect.Type
}{
{ "PrincipalStore", reflect.TypeOf((*pkg_.PrincipalStore)(nil)).Elem()},
{ "SpaceStore", reflect.TypeOf((*pkg_.SpaceStore)(nil)).Elem()},
{ "RepoStore", reflect.TypeOf((*pkg_.RepoStore)(nil)).Elem()},
}
pkg := &model.Package{
// NOTE: This behaves contrary to documented behaviour if the
// package name is not the final component of the import path.
// The reflect package doesn't expose the package name, though.
Name: path.Base("github.com/harness/gitness/internal/store"),
}
for _, it := range its {
intf, err := model.InterfaceFromInterfaceType(it.typ)
if err != nil {
fmt.Fprintf(os.Stderr, "Reflection: %v\n", err)
os.Exit(1)
}
intf.Name = it.sym
pkg.Interfaces = append(pkg.Interfaces, intf)
}
outfile := os.Stdout
if len(*output) != 0 {
var err error
outfile, err = os.Create(*output)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open output file %q", *output)
}
defer func() {
if err := outfile.Close(); err != nil {
fmt.Fprintf(os.Stderr, "failed to close output file %q", *output)
os.Exit(1)
}
}()
}
if err := gob.NewEncoder(outfile).Encode(pkg); err != nil {
fmt.Fprintf(os.Stderr, "gob encode: %v\n", err)
os.Exit(1)
}
}

View File

@ -8,9 +8,10 @@ import (
context "context"
reflect "reflect"
gomock "github.com/golang/mock/gomock"
user "github.com/harness/gitness/internal/api/controller/user"
types "github.com/harness/gitness/types"
gomock "github.com/golang/mock/gomock"
)
// MockClient is a mock of Client interface.

View File

@ -8,9 +8,10 @@ import (
context "context"
reflect "reflect"
gomock "github.com/golang/mock/gomock"
types "github.com/harness/gitness/types"
enum "github.com/harness/gitness/types/enum"
gomock "github.com/golang/mock/gomock"
)
// MockPrincipalStore is a mock of PrincipalStore interface.

View File

@ -16,7 +16,7 @@ const (
// MaxMaxRetries is the max number of retries of a message for a single consumer group.
MaxMaxRetries = 64
// MinIdleTimeout is the minumum time that can be configured as idle timeout for a stream consumer.
// MinIdleTimeout is the minimum time that can be configured as idle timeout for a stream consumer.
MinIdleTimeout = 5 * time.Second
)

View File

@ -22,6 +22,9 @@ type PaginationFilter struct {
type CommitFilter struct {
PaginationFilter
After string `json:"after"`
Path string `json:"path"`
Since int64 `json:"since"`
Until int64 `json:"until"`
}
// BranchFilter stores branch query parameters.