Skip to content

Commit d73f643

Browse files
authored
Merge pull request #4 from gitopia/dev
Merge dev to master
2 parents 69d0fd3 + b9a91d0 commit d73f643

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

cmd/git-remote-gitopia/gitopia.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
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

3736
const (
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

6665
type 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

7272
type 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")

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ go 1.16
44

55
require (
66
github.com/cosmos/cosmos-sdk v0.42.4 // indirect
7-
github.com/gitopia/gitopia v0.7.1-0.20210906165642-daced2dc9465
7+
github.com/gitopia/gitopia v0.7.1-0.20210908101447-c82c98352e19
88
github.com/go-git/go-git/v5 v5.4.2
9-
google.golang.org/grpc v1.38.0
9+
google.golang.org/grpc v1.40.0
1010
)
1111

1212
replace google.golang.org/grpc => google.golang.org/grpc v1.33.2

go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ github.com/gitopia/gitopia v0.7.1-0.20210906130734-6c53e35bf95c h1:ys2WI243eNSqD
190190
github.com/gitopia/gitopia v0.7.1-0.20210906130734-6c53e35bf95c/go.mod h1:zVFAP4WzI1bapXPNn7POT1If5uHJxTDZ4nG2CGiiu+c=
191191
github.com/gitopia/gitopia v0.7.1-0.20210906165642-daced2dc9465 h1:skow6vqHeWQ1Bha6qxRO204pM6T3/zevSxQe2PTRoYQ=
192192
github.com/gitopia/gitopia v0.7.1-0.20210906165642-daced2dc9465/go.mod h1:zVFAP4WzI1bapXPNn7POT1If5uHJxTDZ4nG2CGiiu+c=
193+
github.com/gitopia/gitopia v0.7.1-0.20210907194705-53e5c34b2fb2 h1:XR+YfEjfD6AkKr5zmD9Aw+iOz75VPdAAU7eC/+qgpkA=
194+
github.com/gitopia/gitopia v0.7.1-0.20210907194705-53e5c34b2fb2/go.mod h1:zVFAP4WzI1bapXPNn7POT1If5uHJxTDZ4nG2CGiiu+c=
195+
github.com/gitopia/gitopia v0.7.1-0.20210908101447-c82c98352e19 h1:rpg74I7JG9XHs6SzdtugFKxGJxmpsZK+Yf1LBgrA4rg=
196+
github.com/gitopia/gitopia v0.7.1-0.20210908101447-c82c98352e19/go.mod h1:dNVXmTrslR7J20yRTu6DwfoVhgyG8zW1Oo9C5zTuLcI=
193197
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
194198
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
195199
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
@@ -824,6 +828,7 @@ golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapK
824828
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
825829
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
826830
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
831+
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
827832
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
828833
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
829834
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -860,6 +865,8 @@ google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4/go.mod h1:FWY/as6D
860865
google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
861866
google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced h1:c5geK1iMU3cDKtFrCVQIcjR3W+JOZMuhIyICMCTbtus=
862867
google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24=
868+
google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83 h1:3V2dxSZpz4zozWWUq36vUxXEKnSYitEH2LdsAx+RUmg=
869+
google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
863870
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
864871
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
865872
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
@@ -875,6 +882,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
875882
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
876883
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
877884
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
885+
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
886+
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
878887
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
879888
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
880889
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)