77 "io"
88 "math"
99 "os"
10- "path"
1110 "strings"
1211
1312 "github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
@@ -20,7 +19,7 @@ import (
2019 "github.com/gitopia/git-remote-gitopia/config"
2120 core "github.com/gitopia/git-remote-gitopia/core"
2221 "github.com/gitopia/git-remote-gitopia/core/wallet"
23- gitopiaTypes "github.com/gitopia/gitopia/v2/x/gitopia/types"
22+ gitopiatypes "github.com/gitopia/gitopia/v2/x/gitopia/types"
2423 "github.com/gitopia/gitopia/v2/x/gitopia/utils"
2524 "github.com/go-git/go-git/v5/plumbing"
2625 "github.com/pkg/errors"
@@ -38,12 +37,12 @@ const (
3837
3938type GitopiaHandler struct {
4039 grpcConn * grpc.ClientConn
41- queryClient gitopiaTypes .QueryClient
40+ queryClient gitopiatypes .QueryClient
4241
4342 chainId string
4443 remoteUserId string
4544 remoteRepositoryName string
46- remoteRepository gitopiaTypes .Repository
45+ remoteRepository gitopiatypes .Repository
4746
4847 didPush bool
4948
@@ -66,7 +65,7 @@ func (h *GitopiaHandler) Initialize(remote *core.Remote) error {
6665 }
6766 // defer grpcConn.Close()
6867
69- h .queryClient = gitopiaTypes .NewQueryClient (h .grpcConn )
68+ h .queryClient = gitopiatypes .NewQueryClient (h .grpcConn )
7069 serviceClient := tmservice .NewServiceClient (h .grpcConn )
7170
7271 // Get chain id for signing transaction
@@ -77,7 +76,7 @@ func (h *GitopiaHandler) Initialize(remote *core.Remote) error {
7776 h .chainId = nodeInfoRes .DefaultNodeInfo .Network
7877
7978 // Get RepositoryId
80- res , err := h .queryClient .AnyRepository (context .Background (), & gitopiaTypes .QueryGetAnyRepositoryRequest {
79+ res , err := h .queryClient .AnyRepository (context .Background (), & gitopiatypes .QueryGetAnyRepositoryRequest {
8180 Id : h .remoteUserId ,
8281 RepositoryName : h .remoteRepositoryName ,
8382 })
@@ -93,7 +92,7 @@ func (h *GitopiaHandler) Initialize(remote *core.Remote) error {
9392func (h * GitopiaHandler ) List (remote * core.Remote , forPush bool ) ([]string , error ) {
9493 out := make ([]string , 0 )
9594
96- branchAllRes , err := h .queryClient .RepositoryBranchAll (context .Background (), & gitopiaTypes .QueryAllRepositoryBranchRequest {
95+ branchAllRes , err := h .queryClient .RepositoryBranchAll (context .Background (), & gitopiatypes .QueryAllRepositoryBranchRequest {
9796 Id : h .remoteRepository .Owner .Id ,
9897 RepositoryName : h .remoteRepository .Name ,
9998 Pagination : & query.PageRequest {
@@ -107,7 +106,7 @@ func (h *GitopiaHandler) List(remote *core.Remote, forPush bool) ([]string, erro
107106 out = append (out , fmt .Sprintf ("%s %s%s" , branch .Sha , branchPrefix , branch .Name ))
108107 }
109108
110- tagAllRes , err := h .queryClient .RepositoryTagAll (context .Background (), & gitopiaTypes .QueryAllRepositoryTagRequest {
109+ tagAllRes , err := h .queryClient .RepositoryTagAll (context .Background (), & gitopiatypes .QueryAllRepositoryTagRequest {
111110 Id : h .remoteRepository .Owner .Id ,
112111 RepositoryName : h .remoteRepository .Name ,
113112 Pagination : & query.PageRequest {
@@ -123,25 +122,6 @@ func (h *GitopiaHandler) List(remote *core.Remote, forPush bool) ([]string, erro
123122
124123 out = append (out , fmt .Sprintf ("@refs/heads/%s HEAD" , h .remoteRepository .DefaultBranch ))
125124
126- dir := path .Dir (os .Getenv ("GIT_DIR" ))
127- lfsConfigPath := path .Join (dir , ".lfsconfig" )
128- if _ , err := os .Stat (lfsConfigPath ); os .IsNotExist (err ) {
129- lfsURL := fmt .Sprintf ("%v/%v.git" , config .GitServerHost , h .remoteRepository .Id )
130-
131- args := []string {
132- "config" ,
133- fmt .Sprintf ("--file=%s" , lfsConfigPath ),
134- "lfs.url" ,
135- lfsURL ,
136- }
137-
138- cmd , _ := core .GitCommand ("git" , args ... )
139- if err := cmd .Run (); err != nil {
140- return nil , errors .Wrap (err , "error creating .lfsconfig" )
141- }
142- defer core .CleanUpProcessGroup (cmd )
143- }
144-
145125 return out , nil
146126}
147127
@@ -233,8 +213,8 @@ func (h *GitopiaHandler) Push(remote *core.Remote, refsToPush []core.RefToPush)
233213 remoteURL := fmt .Sprintf ("%v/%v.git" , config .GitServerHost , h .remoteRepository .Id )
234214
235215 var newRemoteRefSha string
236- var setBranches []gitopiaTypes .MsgMultiSetBranch_Branch
237- var setTags []gitopiaTypes .MsgMultiSetTag_Tag
216+ var setBranches []gitopiatypes .MsgMultiSetBranch_Branch
217+ var setTags []gitopiatypes .MsgMultiSetTag_Tag
238218 var deleteBranches , deleteTags []string
239219 var res []string
240220
@@ -305,7 +285,7 @@ func (h *GitopiaHandler) Push(remote *core.Remote, refsToPush []core.RefToPush)
305285
306286 newRemoteRefSha = localCommitHash .String ()
307287 remoteBranchName := strings .TrimPrefix (ref .Remote , branchPrefix )
308- branch := gitopiaTypes .MsgMultiSetBranch_Branch {
288+ branch := gitopiatypes .MsgMultiSetBranch_Branch {
309289 Name : remoteBranchName ,
310290 Sha : newRemoteRefSha ,
311291 }
@@ -321,7 +301,7 @@ func (h *GitopiaHandler) Push(remote *core.Remote, refsToPush []core.RefToPush)
321301
322302 newRemoteRefSha = tagRef .Hash ().String ()
323303 remoteTagName := strings .TrimPrefix (ref .Remote , tagPrefix )
324- tag := gitopiaTypes .MsgMultiSetTag_Tag {
304+ tag := gitopiatypes .MsgMultiSetTag_Tag {
325305 Name : remoteTagName ,
326306 Sha : newRemoteRefSha ,
327307 }
@@ -336,25 +316,25 @@ func (h *GitopiaHandler) Push(remote *core.Remote, refsToPush []core.RefToPush)
336316 var msg []sdk.Msg
337317
338318 if len (setBranches ) > 0 {
339- msg = append (msg , gitopiaTypes .NewMsgMultiSetBranch (h .wallet .Address (), gitopiaTypes .RepositoryId {
319+ msg = append (msg , gitopiatypes .NewMsgMultiSetBranch (h .wallet .Address (), gitopiatypes .RepositoryId {
340320 Id : h .remoteRepository .Owner .Id ,
341321 Name : h .remoteRepository .Name ,
342322 }, setBranches ))
343323 }
344324 if len (setTags ) > 0 {
345- msg = append (msg , gitopiaTypes .NewMsgMultiSetTag (h .wallet .Address (), gitopiaTypes .RepositoryId {
325+ msg = append (msg , gitopiatypes .NewMsgMultiSetTag (h .wallet .Address (), gitopiatypes .RepositoryId {
346326 Id : h .remoteRepository .Owner .Id ,
347327 Name : h .remoteRepository .Name ,
348328 }, setTags ))
349329 }
350330 if len (deleteBranches ) > 0 {
351- msg = append (msg , gitopiaTypes .NewMsgMultiDeleteBranch (h .wallet .Address (), gitopiaTypes .RepositoryId {
331+ msg = append (msg , gitopiatypes .NewMsgMultiDeleteBranch (h .wallet .Address (), gitopiatypes .RepositoryId {
352332 Id : h .remoteRepository .Owner .Id ,
353333 Name : h .remoteRepository .Name ,
354334 }, deleteBranches ))
355335 }
356336 if len (deleteTags ) > 0 {
357- msg = append (msg , gitopiaTypes .NewMsgMultiDeleteTag (h .wallet .Address (), gitopiaTypes .RepositoryId {
337+ msg = append (msg , gitopiatypes .NewMsgMultiDeleteTag (h .wallet .Address (), gitopiatypes .RepositoryId {
358338 Id : h .remoteRepository .Owner .Id ,
359339 Name : h .remoteRepository .Name ,
360340 }, deleteTags ))
@@ -368,26 +348,26 @@ func (h *GitopiaHandler) Push(remote *core.Remote, refsToPush []core.RefToPush)
368348}
369349
370350func (h * GitopiaHandler ) havePushPermission (walletAddress string ) (havePermission bool , err error ) {
371- if h .remoteRepository .Owner .Type == gitopiaTypes .OwnerType_USER {
351+ if h .remoteRepository .Owner .Type == gitopiatypes .OwnerType_USER {
372352 if h .wallet .Address () == h .remoteRepository .Owner .Id {
373353 havePermission = true
374354 }
375- } else if h .remoteRepository .Owner .Type == gitopiaTypes .OwnerType_DAO {
376- member , err := h .queryClient .DaoMember (context .Background (), & gitopiaTypes .QueryGetDaoMemberRequest {
355+ } else if h .remoteRepository .Owner .Type == gitopiatypes .OwnerType_DAO {
356+ member , err := h .queryClient .DaoMember (context .Background (), & gitopiatypes .QueryGetDaoMemberRequest {
377357 DaoId : h .remoteRepository .Owner .Id ,
378358 UserId : h .wallet .Address (),
379359 })
380360 if err != nil {
381361 return havePermission , err
382362 }
383- if member .Member .Role == gitopiaTypes .MemberRole_OWNER {
363+ if member .Member .Role == gitopiatypes .MemberRole_OWNER {
384364 havePermission = true
385365 }
386366 }
387367
388368 if ! havePermission {
389369 if i , exists := utils .RepositoryCollaboratorExists (h .remoteRepository .Collaborators , h .wallet .Address ()); exists {
390- if h .remoteRepository .Collaborators [i ].Permission >= gitopiaTypes .PushBranchPermission {
370+ if h .remoteRepository .Collaborators [i ].Permission >= gitopiatypes .PushBranchPermission {
391371 havePermission = true
392372 }
393373 }
0 commit comments