Skip to content

Commit

Permalink
[maint] gitrpc package removed (harness#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
enver-bisevac authored and Harness committed Nov 15, 2023
1 parent bd54375 commit 67f5608
Show file tree
Hide file tree
Showing 242 changed files with 7,303 additions and 22,794 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ WORKDIR /app
VOLUME /data

ENV XDG_CACHE_HOME /data
ENV GITRPC_SERVER_GIT_ROOT /data
ENV GITNESS_GIT_ROOT /data
ENV GITNESS_DATABASE_DRIVER sqlite3
ENV GITNESS_DATABASE_DATASOURCE /data/database.sqlite
ENV GITNESS_METRIC_ENABLED=true
Expand Down
11 changes: 1 addition & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ lint: tools generate # lint the golang code
# the source file has changed.
###############################################################################

generate: wire proto
generate: wire
@echo "Generated Code"

wire: cmd/gitness/wire_gen.go
Expand All @@ -85,15 +85,6 @@ force-wire: ## Force wire code generation
cmd/gitness/wire_gen.go: cmd/gitness/wire.go
@sh ./scripts/wire/gitness.sh

proto: ## generate proto files for gitrpc integration (and format, as we can't exclude it from being formatted easily)
@protoc --proto_path=./gitrpc/proto \
--go_out=./gitrpc/rpc \
--go_opt=paths=source_relative \
--go-grpc_out=./gitrpc/rpc \
--go-grpc_opt=paths=source_relative \
./gitrpc/proto/*.proto
@goimports -w ./gitrpc/rpc

###############################################################################
# Install Tools and deps
#
Expand Down
8 changes: 4 additions & 4 deletions app/api/controller/check/check_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/app/auth"
"github.com/harness/gitness/gitrpc"
"github.com/harness/gitness/git"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
Expand Down Expand Up @@ -140,12 +140,12 @@ func (c *Controller) Report(
return nil, errValidate
}

if !gitrpc.ValidateCommitSHA(commitSHA) {
if !git.ValidateCommitSHA(commitSHA) {
return nil, usererror.BadRequest("invalid commit SHA provided")
}

_, err = c.gitRPCClient.GetCommit(ctx, &gitrpc.GetCommitParams{
ReadParams: gitrpc.ReadParams{RepoUID: repo.GitUID},
_, err = c.git.GetCommit(ctx, &git.GetCommitParams{
ReadParams: git.ReadParams{RepoUID: repo.GitUID},
SHA: commitSHA,
})
if err != nil {
Expand Down
24 changes: 12 additions & 12 deletions app/api/controller/check/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,33 @@ import (
"github.com/harness/gitness/app/auth"
"github.com/harness/gitness/app/auth/authz"
"github.com/harness/gitness/app/store"
"github.com/harness/gitness/gitrpc"
"github.com/harness/gitness/git"
"github.com/harness/gitness/store/database/dbtx"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)

type Controller struct {
tx dbtx.Transactor
authorizer authz.Authorizer
repoStore store.RepoStore
checkStore store.CheckStore
gitRPCClient gitrpc.Interface
tx dbtx.Transactor
authorizer authz.Authorizer
repoStore store.RepoStore
checkStore store.CheckStore
git git.Interface
}

func NewController(
tx dbtx.Transactor,
authorizer authz.Authorizer,
repoStore store.RepoStore,
checkStore store.CheckStore,
gitRPCClient gitrpc.Interface,
git git.Interface,
) *Controller {
return &Controller{
tx: tx,
authorizer: authorizer,
repoStore: repoStore,
checkStore: checkStore,
gitRPCClient: gitRPCClient,
tx: tx,
authorizer: authorizer,
repoStore: repoStore,
checkStore: checkStore,
git: git,
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/api/controller/check/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package check
import (
"github.com/harness/gitness/app/auth/authz"
"github.com/harness/gitness/app/store"
"github.com/harness/gitness/gitrpc"
"github.com/harness/gitness/git"
"github.com/harness/gitness/store/database/dbtx"

"github.com/google/wire"
Expand All @@ -33,7 +33,7 @@ func ProvideController(
authorizer authz.Authorizer,
repoStore store.RepoStore,
checkStore store.CheckStore,
rpcClient gitrpc.Interface,
rpcClient git.Interface,
) *Controller {
return NewController(
tx,
Expand Down
16 changes: 7 additions & 9 deletions app/api/controller/pullreq/comment_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ package pullreq

import (
"context"
"errors"
"fmt"
"time"

"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/app/auth"
events "github.com/harness/gitness/app/events/pullreq"
"github.com/harness/gitness/gitrpc"
"github.com/harness/gitness/errors"
"github.com/harness/gitness/git"
"github.com/harness/gitness/store"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
Expand Down Expand Up @@ -108,10 +108,8 @@ func (c *Controller) CommentCreate(

switch {
case in.IsCodeComment():
var cut gitrpc.DiffCutOutput

cut, err = c.gitRPCClient.DiffCut(ctx, &gitrpc.DiffCutParams{
ReadParams: gitrpc.ReadParams{RepoUID: repo.GitUID},
cut, err := c.git.DiffCut(ctx, &git.DiffCutParams{
ReadParams: git.ReadParams{RepoUID: repo.GitUID},
SourceCommitSHA: in.SourceCommitSHA,
SourceBranch: pr.SourceBranch,
TargetCommitSHA: in.TargetCommitSHA,
Expand All @@ -122,8 +120,8 @@ func (c *Controller) CommentCreate(
LineEnd: in.LineEnd,
LineEndNew: in.LineEndNew,
})
if gitrpc.ErrorStatus(err) == gitrpc.StatusNotFound || gitrpc.ErrorStatus(err) == gitrpc.StatusPathNotFound {
return nil, usererror.BadRequest(gitrpc.ErrorMessage(err))
if errors.AsStatus(err) == errors.StatusNotFound || errors.AsStatus(err) == errors.StatusPathNotFound {
return nil, usererror.BadRequest(errors.Message(err))
}
if err != nil {
return nil, err
Expand Down Expand Up @@ -306,7 +304,7 @@ func getCommentActivity(session *auth.Session, pr *types.PullReq, in *CommentCre
return act
}

func setAsCodeComment(a *types.PullReqActivity, cut gitrpc.DiffCutOutput, path, sourceCommitSHA string) {
func setAsCodeComment(a *types.PullReqActivity, cut git.DiffCutOutput, path, sourceCommitSHA string) {
var falseBool bool
a.Type = enum.PullReqActivityTypeCodeComment
a.Kind = enum.PullReqActivityKindChangeComment
Expand Down
21 changes: 11 additions & 10 deletions app/api/controller/pullreq/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import (
"github.com/harness/gitness/app/sse"
"github.com/harness/gitness/app/store"
"github.com/harness/gitness/app/url"
"github.com/harness/gitness/gitrpc"
gitrpcenum "github.com/harness/gitness/gitrpc/enum"
"github.com/harness/gitness/errors"
"github.com/harness/gitness/git"
gitenum "github.com/harness/gitness/git/enum"
"github.com/harness/gitness/lock"
"github.com/harness/gitness/store/database/dbtx"
"github.com/harness/gitness/types"
Expand All @@ -52,7 +53,7 @@ type Controller struct {
fileViewStore store.PullReqFileViewStore
membershipStore store.MembershipStore
checkStore store.CheckStore
gitRPCClient gitrpc.Interface
git git.Interface
eventReporter *pullreqevents.Reporter
mtxManager lock.MutexManager
codeCommentMigrator *codecomments.Migrator
Expand All @@ -76,7 +77,7 @@ func NewController(
fileViewStore store.PullReqFileViewStore,
membershipStore store.MembershipStore,
checkStore store.CheckStore,
gitRPCClient gitrpc.Interface,
git git.Interface,
eventReporter *pullreqevents.Reporter,
mtxManager lock.MutexManager,
codeCommentMigrator *codecomments.Migrator,
Expand All @@ -99,7 +100,7 @@ func NewController(
fileViewStore: fileViewStore,
membershipStore: membershipStore,
checkStore: checkStore,
gitRPCClient: gitRPCClient,
git: git,
codeCommentMigrator: codeCommentMigrator,
eventReporter: eventReporter,
mtxManager: mtxManager,
Expand All @@ -117,13 +118,13 @@ func (c *Controller) verifyBranchExistence(ctx context.Context,
return "", usererror.BadRequest("branch name can't be empty")
}

ref, err := c.gitRPCClient.GetRef(ctx,
gitrpc.GetRefParams{
ReadParams: gitrpc.ReadParams{RepoUID: repo.GitUID},
ref, err := c.git.GetRef(ctx,
git.GetRefParams{
ReadParams: git.ReadParams{RepoUID: repo.GitUID},
Name: branch,
Type: gitrpcenum.RefTypeBranch,
Type: gitenum.RefTypeBranch,
})
if gitrpc.ErrorStatus(err) == gitrpc.StatusNotFound {
if errors.AsStatus(err) == errors.StatusNotFound {
return "", usererror.BadRequest(
fmt.Sprintf("branch %s does not exist in the repository %s", branch, repo.UID))
}
Expand Down
26 changes: 13 additions & 13 deletions app/api/controller/pullreq/file_view_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (

"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/app/auth"
"github.com/harness/gitness/gitrpc"
"github.com/harness/gitness/errors"
"github.com/harness/gitness/git"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
Expand All @@ -35,7 +36,7 @@ func (f *FileViewAddInput) Validate() error {
if f.Path == "" {
return usererror.BadRequest("path can't be empty")
}
if !gitrpc.ValidateCommitSHA(f.CommitSHA) {
if !git.ValidateCommitSHA(f.CommitSHA) {
return usererror.BadRequest("commit_sha is invalid")
}

Expand Down Expand Up @@ -72,17 +73,16 @@ func (c *Controller) FileViewAdd(
}

// retrieve file from both provided SHA and mergeBaseSHA to validate user input
// TODO: Add GITRPC call to get multiple tree nodes at once

inNode, err := c.gitRPCClient.GetTreeNode(ctx, &gitrpc.GetTreeNodeParams{
ReadParams: gitrpc.CreateRPCReadParams(repo),
inNode, err := c.git.GetTreeNode(ctx, &git.GetTreeNodeParams{
ReadParams: git.CreateReadParams(repo),
GitREF: in.CommitSHA,
Path: in.Path,
IncludeLatestCommit: false,
})
if err != nil && gitrpc.ErrorStatus(err) != gitrpc.StatusPathNotFound {
if err != nil && errors.AsStatus(err) != errors.StatusPathNotFound {
return nil, fmt.Errorf(
"failed to get tree node '%s' for provided sha '%s' from gitrpc: %w",
"failed to get tree node '%s' for provided sha '%s': %w",
in.Path,
in.CommitSHA,
err,
Expand All @@ -91,20 +91,20 @@ func (c *Controller) FileViewAdd(

// ensure provided path actually points to a blob or commit (submodule)
if inNode != nil &&
inNode.Node.Type != gitrpc.TreeNodeTypeBlob &&
inNode.Node.Type != gitrpc.TreeNodeTypeCommit {
inNode.Node.Type != git.TreeNodeTypeBlob &&
inNode.Node.Type != git.TreeNodeTypeCommit {
return nil, usererror.BadRequestf("Provided path '%s' doesn't point to a file.", in.Path)
}

mergeBaseNode, err := c.gitRPCClient.GetTreeNode(ctx, &gitrpc.GetTreeNodeParams{
ReadParams: gitrpc.CreateRPCReadParams(repo),
mergeBaseNode, err := c.git.GetTreeNode(ctx, &git.GetTreeNodeParams{
ReadParams: git.CreateReadParams(repo),
GitREF: pr.MergeBaseSHA,
Path: in.Path,
IncludeLatestCommit: false,
})
if err != nil && gitrpc.ErrorStatus(err) != gitrpc.StatusPathNotFound {
if err != nil && errors.AsStatus(err) != errors.StatusPathNotFound {
return nil, fmt.Errorf(
"failed to get tree node '%s' for MergeBaseSHA '%s' from gitrpc: %w",
"failed to get tree node '%s' for MergeBaseSHA '%s': %w",
in.Path,
pr.MergeBaseSHA,
err,
Expand Down
6 changes: 3 additions & 3 deletions app/api/controller/pullreq/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
package pullreq

import (
"github.com/harness/gitness/gitrpc"
"github.com/harness/gitness/git"
"github.com/harness/gitness/types"
)

func rpcIdentityFromPrincipal(p types.Principal) *gitrpc.Identity {
return &gitrpc.Identity{
func identityFromPrincipal(p types.Principal) *git.Identity {
return &git.Identity{
Name: p.DisplayName,
Email: p.Email,
}
Expand Down
Loading

0 comments on commit 67f5608

Please sign in to comment.