77 "fmt"
88 "net/http"
99 "os"
10- "strconv"
1110 "strings"
1211
1312 clientTx "github.com/cosmos/cosmos-sdk/client/tx"
@@ -35,9 +34,9 @@ import (
3534)
3635
3736const (
38- chainID = "internal-2 "
37+ chainID = "internal-4 "
3938 AccountAddressPrefix = "gitopia"
40- apiURL = "34.87.152.178 :9090"
39+ apiURL = "34.87.90.147 :9090"
4140 objectsURL = "http://34.126.69.254:5000"
4241 saveToArweaveURL = "http://34.126.69.254:5000/save"
4342 branchPrefix = "refs/heads/"
@@ -65,8 +64,9 @@ type GitopiaWallet struct {
6564
6665type SaveToArweavePostBody struct {
6766 RepositoryID uint64 `json:"repository_id"`
68- LocalObjectHash string `json:"local_object_hash"`
69- RemoteObjectHash string `json:"remote_object_hash"`
67+ RemoteRefName string `json:"remote_ref_name"`
68+ NewRemoteRefSha string `json:"new_remote_ref_sha"`
69+ PrevRemoteRefSha string `json:"prev_remote_ref_sha"`
7070}
7171
7272type GitopiaHandler struct {
@@ -95,8 +95,8 @@ func (h *GitopiaHandler) Initialize(remote *core.Remote) error {
9595 h .txClient = tx .NewServiceClient (grpcConn )
9696
9797 // Get RepositoryId
98- res , err := h .queryClient .UserRepository (context .Background (), & gitopiaTypes.QueryGetUserRepositoryRequest {
99- UserId : h .remoteUserId ,
98+ res , err := h .queryClient .AddressRepository (context .Background (), & gitopiaTypes.QueryGetAddressRepositoryRequest {
99+ Id : h .remoteUserId ,
100100 RepositoryName : h .remoteRepositoryName ,
101101 })
102102 if err != nil {
@@ -240,45 +240,44 @@ func (h *GitopiaHandler) Push(remote *core.Remote, local string, remoteRef strin
240240
241241 txBuilder := txCfg .NewTxBuilder ()
242242
243- var localObjectHash string
244- remoteObjectHash := "0000000000000000000000000000000000000000"
243+ var newRemoteRefSha , prevRemoteRefSha string
245244 var msg sdk.Msg
246245
247246 if strings .HasPrefix (local , branchPrefix ) {
248247 localCommitHash , err := remote .Repo .ResolveRevision (plumbing .Revision (local ))
249248 if err != nil {
250249 return "" , fmt .Errorf ("fatal: local branch %s doesn't exist" , local )
251250 }
252- localObjectHash = localCommitHash .String ()
251+ newRemoteRefSha = localCommitHash .String ()
253252
254253 remoteBranchName := strings .TrimPrefix (remoteRef , branchPrefix )
255254 branchShaResponse , err := h .queryClient .BranchSha (context .Background (), & gitopiaTypes.QueryGetBranchShaRequest {
256255 RepositoryId : h .remoteRepository .Id ,
257256 BranchName : remoteBranchName ,
258257 })
259258 if err == nil {
260- remoteObjectHash = branchShaResponse .Sha
259+ prevRemoteRefSha = branchShaResponse .Sha
261260 }
262261
263- msg = gitopiaTypes .NewMsgCreateBranch (walletAddress .String (), h .remoteRepository .Id , remoteBranchName , localObjectHash )
262+ msg = gitopiaTypes .NewMsgCreateBranch (walletAddress .String (), h .remoteRepository .Id , remoteBranchName , newRemoteRefSha )
264263 } else if strings .HasPrefix (local , tagPrefix ) {
265264 localTagName := strings .TrimPrefix (local , tagPrefix )
266265 ref , err := remote .Repo .Tag (localTagName )
267266 if err != nil {
268267 return "" , fmt .Errorf ("fatal: invalid tag name, %v" , localTagName )
269268 }
270- localObjectHash = ref .Hash ().String ()
269+ newRemoteRefSha = ref .Hash ().String ()
271270
272271 remoteTagName := strings .TrimPrefix (remoteRef , tagPrefix )
273272 tagShaResponse , err := h .queryClient .TagSha (context .Background (), & gitopiaTypes.QueryGetTagShaRequest {
274273 RepositoryId : h .remoteRepository .Id ,
275274 TagName : remoteTagName ,
276275 })
277276 if err == nil {
278- remoteObjectHash = tagShaResponse .Sha
277+ prevRemoteRefSha = tagShaResponse .Sha
279278 }
280279
281- msg = gitopiaTypes .NewMsgCreateTag (walletAddress .String (), h .remoteRepository .Id , remoteTagName , ref . Hash (). String () )
280+ msg = gitopiaTypes .NewMsgCreateTag (walletAddress .String (), h .remoteRepository .Id , remoteTagName , newRemoteRefSha )
282281 } else {
283282 return "" , fmt .Errorf ("fatal: not a valid branch/tag, %v" , local )
284283 }
@@ -356,8 +355,9 @@ func (h *GitopiaHandler) Push(remote *core.Remote, local string, remoteRef strin
356355 // Queue task to upload objects to arweave
357356 saveToArweavePostBody := SaveToArweavePostBody {
358357 RepositoryID : h .remoteRepository .Id ,
359- LocalObjectHash : localObjectHash ,
360- RemoteObjectHash : remoteObjectHash ,
358+ RemoteRefName : remoteRef ,
359+ NewRemoteRefSha : newRemoteRefSha ,
360+ PrevRemoteRefSha : prevRemoteRefSha ,
361361 }
362362
363363 postBody , err := json .Marshal (saveToArweavePostBody )
@@ -382,13 +382,8 @@ func (h *GitopiaHandler) havePushPermission(walletAddress string) (bool, error)
382382 var o gitopiaTypes.Organization
383383
384384 if h .remoteRepository .Owner .Type == gitopiaTypes .RepositoryOwner_ORGANIZATION {
385- orgId , err := strconv .ParseUint (h .remoteRepository .Owner .Id , 10 , 64 )
386- if err != nil {
387- return false , fmt .Errorf ("fatal: invalid organization id" )
388- }
389-
390385 res , err := h .queryClient .Organization (context .Background (), & gitopiaTypes.QueryGetOrganizationRequest {
391- Id : orgId ,
386+ Id : h . remoteRepository . Owner . Id ,
392387 })
393388 if err != nil {
394389 return false , fmt .Errorf ("fatal: organization doesn't exist" )
0 commit comments