Skip to content

Commit 6834628

Browse files
author
gitopia1c2zfrmhra3spfrc2m5ft64hef30guf60lvtcm3
committed
Merge pull request #34 from gitopia/ducnt/dao
2 parents 0eac8c2 + 1908165 commit 6834628

19 files changed

+1156
-365
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ secret.yml
44
build
55
cmd/gitopiad/__debug_bin
66
.DS_Store
7-
.lfsconfig
7+
.lfsconfig
8+
x/rewards/client/cli/test

docs/static/openapi.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76839,6 +76839,8 @@ definitions:
7683976839
type: object
7684076840
gitopia.gitopia.gitopia.MsgUpdateRepositoryDescriptionResponse:
7684176841
type: object
76842+
gitopia.gitopia.gitopia.MsgToggleRepositoryArchivedResponse:
76843+
type: object
7684276844
gitopia.gitopia.gitopia.MsgUpdateRepositoryLabelResponse:
7684376845
type: object
7684476846
gitopia.gitopia.gitopia.MsgUpdateTaskResponse:

proto/gitopia/tx.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ service Msg {
9090
rpc ForkRepositorySuccess(MsgForkRepositorySuccess) returns (MsgForkRepositorySuccessResponse);
9191
rpc RenameRepository(MsgRenameRepository) returns (MsgRenameRepositoryResponse);
9292
rpc UpdateRepositoryDescription(MsgUpdateRepositoryDescription) returns (MsgUpdateRepositoryDescriptionResponse);
93+
rpc ToggleRepositoryArchived(MsgToggleRepositoryArchived) returns (MsgToggleRepositoryArchivedResponse);
9394
rpc ChangeOwner(MsgChangeOwner) returns (MsgChangeOwnerResponse);
9495
rpc UpdateRepositoryCollaborator(MsgUpdateRepositoryCollaborator) returns (MsgUpdateRepositoryCollaboratorResponse);
9596
rpc RemoveRepositoryCollaborator(MsgRemoveRepositoryCollaborator) returns (MsgRemoveRepositoryCollaboratorResponse);
@@ -791,6 +792,12 @@ message MsgUpdateRepositoryDescription {
791792

792793
message MsgUpdateRepositoryDescriptionResponse { }
793794

795+
message MsgToggleRepositoryArchived {
796+
string creator = 1;
797+
RepositoryId repositoryId = 2 [(gogoproto.nullable) = false];
798+
}
799+
800+
message MsgToggleRepositoryArchivedResponse { }
794801

795802
message MsgChangeOwner {
796803
string creator = 1;

x/gitopia/client/cli/tx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func GetTxCmd() *cobra.Command {
107107
cmd.AddCommand(CmdForkRepository())
108108
cmd.AddCommand(CmdRenameRepository())
109109
cmd.AddCommand(CmdUpdateRepositoryDescription())
110+
cmd.AddCommand(CmdToggleRepositoryArchived())
110111
cmd.AddCommand(CmdChangeOwner())
111112
cmd.AddCommand(CmdUpdateRepositoryCollaborator())
112113
cmd.AddCommand(CmdRemoveRepositoryCollaborator())

x/gitopia/client/cli/txRepository.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,35 @@ func CmdUpdateRepositoryDescription() *cobra.Command {
195195
return cmd
196196
}
197197

198+
func CmdToggleRepositoryArchived() *cobra.Command {
199+
cmd := &cobra.Command{
200+
Use: "toggle-repository-archived [owner-id] [repository-name]",
201+
Short: "toggle repository archived",
202+
Args: cobra.ExactArgs(2),
203+
RunE: func(cmd *cobra.Command, args []string) error {
204+
argOwnerid := args[0]
205+
argRepositoryName := args[1]
206+
207+
clientCtx, err := client.GetClientTxContext(cmd)
208+
if err != nil {
209+
return err
210+
}
211+
msg := types.NewMsgToggleRepositoryArchived(
212+
clientCtx.GetFromAddress().String(),
213+
types.RepositoryId{Id: argOwnerid, Name: argRepositoryName},
214+
)
215+
if err := msg.ValidateBasic(); err != nil {
216+
return err
217+
}
218+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
219+
},
220+
}
221+
222+
flags.AddTxFlagsToCmd(cmd)
223+
224+
return cmd
225+
}
226+
198227
func CmdChangeOwner() *cobra.Command {
199228
cmd := &cobra.Command{
200229
Use: "change-owner [id] [repository-name] [owner-id]",

x/gitopia/handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
288288
res, err := msgServer.RenameRepository(sdk.WrapSDKContext(ctx), msg)
289289
return sdk.WrapServiceResult(ctx, res, err)
290290

291+
case *types.MsgToggleRepositoryArchived:
292+
res, err := msgServer.ToggleRepositoryArchived(sdk.WrapSDKContext(ctx), msg)
293+
return sdk.WrapServiceResult(ctx, res, err)
294+
291295
case *types.MsgUpdateRepositoryDescription:
292296
res, err := msgServer.UpdateRepositoryDescription(sdk.WrapSDKContext(ctx), msg)
293297
return sdk.WrapServiceResult(ctx, res, err)

x/gitopia/keeper/msg_server_branch.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ func (k msgServer) SetBranch(goCtx context.Context, msg *types.MsgSetBranch) (*t
2525
}
2626

2727
repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
28+
if repository.Archived {
29+
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
30+
}
31+
2832
if !found {
2933
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
3034
}
@@ -95,6 +99,10 @@ func (k msgServer) MultiSetBranch(goCtx context.Context, msg *types.MsgMultiSetB
9599
}
96100

97101
repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
102+
if repository.Archived {
103+
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
104+
}
105+
98106
if !found {
99107
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
100108
}
@@ -170,6 +178,10 @@ func (k msgServer) SetDefaultBranch(goCtx context.Context, msg *types.MsgSetDefa
170178
}
171179

172180
repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
181+
if repository.Archived {
182+
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
183+
}
184+
173185
if !found {
174186
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
175187
}
@@ -223,6 +235,10 @@ func (k msgServer) DeleteBranch(goCtx context.Context, msg *types.MsgDeleteBranc
223235
}
224236

225237
repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
238+
if repository.Archived {
239+
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
240+
}
241+
226242
if !found {
227243
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
228244
}
@@ -276,6 +292,10 @@ func (k msgServer) MultiDeleteBranch(goCtx context.Context, msg *types.MsgMultiD
276292
}
277293

278294
repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
295+
if repository.Archived {
296+
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
297+
}
298+
279299
if !found {
280300
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
281301
}
@@ -337,6 +357,10 @@ func (k msgServer) ToggleForcePush(goCtx context.Context, msg *types.MsgToggleFo
337357
}
338358

339359
repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
360+
if repository.Archived {
361+
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
362+
}
363+
340364
if !found {
341365
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
342366
}

x/gitopia/keeper/msg_server_issue.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func (k msgServer) CreateIssue(goCtx context.Context, msg *types.MsgCreateIssue)
2727
}
2828

2929
repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
30+
if repository.Archived {
31+
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
32+
}
33+
3034
if !found {
3135
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
3236
}
@@ -284,6 +288,10 @@ func (k msgServer) ToggleIssueState(goCtx context.Context, msg *types.MsgToggleI
284288
}
285289

286290
repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
291+
if repository.Archived {
292+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
293+
}
294+
287295
if !found {
288296
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
289297
}
@@ -425,6 +433,10 @@ func (k msgServer) AddIssueAssignees(goCtx context.Context, msg *types.MsgAddIss
425433
}
426434

427435
repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
436+
if repository.Archived {
437+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
438+
}
439+
428440
if !found {
429441
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
430442
}
@@ -508,6 +520,10 @@ func (k msgServer) RemoveIssueAssignees(goCtx context.Context, msg *types.MsgRem
508520
}
509521

510522
repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
523+
if repository.Archived {
524+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
525+
}
526+
511527
if !found {
512528
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
513529
}
@@ -582,6 +598,10 @@ func (k msgServer) AddIssueLabels(goCtx context.Context, msg *types.MsgAddIssueL
582598
}
583599

584600
repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
601+
if repository.Archived {
602+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
603+
}
604+
585605
if !found {
586606
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
587607
}
@@ -663,6 +683,10 @@ func (k msgServer) RemoveIssueLabels(goCtx context.Context, msg *types.MsgRemove
663683
}
664684

665685
repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
686+
if repository.Archived {
687+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
688+
}
689+
666690
if !found {
667691
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
668692
}
@@ -745,6 +769,10 @@ func (k msgServer) DeleteIssue(goCtx context.Context, msg *types.MsgDeleteIssue)
745769
}
746770

747771
repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
772+
if repository.Archived {
773+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
774+
}
775+
748776
if !found {
749777
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
750778
}

x/gitopia/keeper/msg_server_pullRequest.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func (k msgServer) CreatePullRequest(goCtx context.Context, msg *types.MsgCreate
2727
}
2828

2929
headRepository, found := k.GetAddressRepository(ctx, headRepoOwnerAddress.Address, msg.HeadRepositoryId.Name)
30+
if headRepository.Archived {
31+
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.HeadRepositoryId.Name)
32+
}
33+
3034
if !found {
3135
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("head-repository (%v/%v) doesn't exist", msg.HeadRepositoryId.Id, msg.HeadRepositoryId.Name))
3236
}
@@ -41,6 +45,9 @@ func (k msgServer) CreatePullRequest(goCtx context.Context, msg *types.MsgCreate
4145
}
4246

4347
baseRepository, found := k.GetAddressRepository(ctx, baseRepositoryAddress.Address, msg.BaseRepositoryId.Name)
48+
if baseRepository.Archived {
49+
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.BaseRepositoryId.Name)
50+
}
4451
if !found {
4552
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("base-repository (%v/%v) doesn't exist", msg.BaseRepositoryId.Id, msg.BaseRepositoryId.Name))
4653
}
@@ -327,6 +334,10 @@ func (k msgServer) InvokeMergePullRequest(goCtx context.Context, msg *types.MsgI
327334
}
328335

329336
baseRepository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
337+
if baseRepository.Archived {
338+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", pullRequest.Base.RepositoryId)
339+
}
340+
330341
if !found {
331342
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
332343
}
@@ -377,6 +388,9 @@ func (k msgServer) SetPullRequestState(goCtx context.Context, msg *types.MsgSetP
377388
blockTime := ctx.BlockTime().Unix()
378389

379390
baseRepository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
391+
if baseRepository.Archived {
392+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", pullRequest.Base.RepositoryId)
393+
}
380394
if !found {
381395
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
382396
}
@@ -633,6 +647,9 @@ func (k msgServer) AddPullRequestReviewers(goCtx context.Context, msg *types.Msg
633647
}
634648

635649
repository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
650+
if repository.Archived {
651+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
652+
}
636653
if !found {
637654
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
638655
}
@@ -710,6 +727,10 @@ func (k msgServer) RemovePullRequestReviewers(goCtx context.Context, msg *types.
710727
}
711728

712729
repository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
730+
if repository.Archived {
731+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
732+
}
733+
713734
if !found {
714735
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
715736
}
@@ -784,6 +805,10 @@ func (k msgServer) AddPullRequestAssignees(goCtx context.Context, msg *types.Msg
784805
}
785806

786807
repository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
808+
if repository.Archived {
809+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
810+
}
811+
787812
if !found {
788813
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
789814
}
@@ -861,6 +886,10 @@ func (k msgServer) RemovePullRequestAssignees(goCtx context.Context, msg *types.
861886
}
862887

863888
repository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
889+
if repository.Archived {
890+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
891+
}
892+
864893
if !found {
865894
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
866895
}
@@ -935,6 +964,9 @@ func (k msgServer) LinkPullRequestIssueByIid(goCtx context.Context, msg *types.M
935964
}
936965

937966
baseRepository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
967+
if baseRepository.Archived {
968+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
969+
}
938970
if !found {
939971
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
940972
}
@@ -1047,6 +1079,10 @@ func (k msgServer) UnlinkPullRequestIssueByIid(goCtx context.Context, msg *types
10471079
}
10481080

10491081
baseRepository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
1082+
if baseRepository.Archived {
1083+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
1084+
}
1085+
10501086
if !found {
10511087
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
10521088
}
@@ -1153,6 +1189,10 @@ func (k msgServer) AddPullRequestLabels(goCtx context.Context, msg *types.MsgAdd
11531189
}
11541190

11551191
repository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
1192+
if repository.Archived {
1193+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
1194+
}
1195+
11561196
if !found {
11571197
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
11581198
}
@@ -1234,6 +1274,10 @@ func (k msgServer) RemovePullRequestLabels(goCtx context.Context, msg *types.Msg
12341274
}
12351275

12361276
repository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
1277+
if repository.Archived {
1278+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
1279+
}
1280+
12371281
if !found {
12381282
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
12391283
}
@@ -1315,6 +1359,10 @@ func (k msgServer) DeletePullRequest(goCtx context.Context, msg *types.MsgDelete
13151359
}
13161360

13171361
repository, found := k.GetRepositoryById(ctx, msg.RepositoryId)
1362+
if repository.Archived {
1363+
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
1364+
}
1365+
13181366
if !found {
13191367
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", msg.RepositoryId))
13201368
}

0 commit comments

Comments
 (0)