Skip to content
Open

t #1

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ff5695e
add msg UpdateArchiveState and proto scripts
anhductn2001 Jun 25, 2023
1c9e455
refactor proto folder and make proto-gen
anhductn2001 Jun 25, 2023
d787d66
set repository archived
anhductn2001 Jun 25, 2023
402399e
all relevant messages should check if archived flag is set or not
anhductn2001 Jun 25, 2023
22ffd42
add msg to RegisterInterface
anhductn2001 Jun 26, 2023
410f7e3
use cosmos/gogoproto
anhductn2001 Jun 26, 2023
83bfa3a
revert proto
anhductn2001 Jun 26, 2023
159f923
fix unit test
anhductn2001 Jun 26, 2023
583da0d
Merge remote-tracking branch 'gitopia2/master' into ducnt/dao
anhductn2001 Jun 27, 2023
4922002
ignore .lfsconfig
anhductn2001 Jun 27, 2023
daacc25
proto gen
anhductn2001 Jun 27, 2023
0a55f00
source
anhductn2001 Jun 27, 2023
d4edd33
source
anhductn2001 Jun 27, 2023
d259328
add command
anhductn2001 Jun 27, 2023
872bb2a
rename
anhductn2001 Jun 27, 2023
b71cfc5
add unit test
anhductn2001 Jun 27, 2023
2bbbfa2
fix unit test
anhductn2001 Jun 27, 2023
3cbb287
Merge remote-tracking branch 'gitopia2/master' into ducnt/dao
anhductn2001 Jun 27, 2023
c77b7c2
proto gen by ignite
anhductn2001 Jun 27, 2023
6980a5e
proto gen by ignite
anhductn2001 Jun 27, 2023
625b792
lint
anhductn2001 Jun 27, 2023
0d2862a
go mod tidy
anhductn2001 Jun 27, 2023
60199c5
lint
anhductn2001 Jun 27, 2023
c7b769d
ToggleRepositoryArchived
anhductn2001 Jun 29, 2023
3510332
proto
anhductn2001 Jun 29, 2023
c29a62b
cli
anhductn2001 Jun 29, 2023
1908165
arg is 2
anhductn2001 Jun 30, 2023
6834628
Merge pull request #34 from gitopia/ducnt/dao
Jun 30, 2023
8bbb7f0
t
ProgramCpp Jul 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ secret.yml
build
cmd/gitopiad/__debug_bin
.DS_Store
.lfsconfig
.lfsconfig
x/rewards/client/cli/test
2 changes: 2 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76839,6 +76839,8 @@ definitions:
type: object
gitopia.gitopia.gitopia.MsgUpdateRepositoryDescriptionResponse:
type: object
gitopia.gitopia.gitopia.MsgToggleRepositoryArchivedResponse:
type: object
gitopia.gitopia.gitopia.MsgUpdateRepositoryLabelResponse:
type: object
gitopia.gitopia.gitopia.MsgUpdateTaskResponse:
Expand Down
7 changes: 7 additions & 0 deletions proto/gitopia/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ service Msg {
rpc ForkRepositorySuccess(MsgForkRepositorySuccess) returns (MsgForkRepositorySuccessResponse);
rpc RenameRepository(MsgRenameRepository) returns (MsgRenameRepositoryResponse);
rpc UpdateRepositoryDescription(MsgUpdateRepositoryDescription) returns (MsgUpdateRepositoryDescriptionResponse);
rpc ToggleRepositoryArchived(MsgToggleRepositoryArchived) returns (MsgToggleRepositoryArchivedResponse);
rpc ChangeOwner(MsgChangeOwner) returns (MsgChangeOwnerResponse);
rpc UpdateRepositoryCollaborator(MsgUpdateRepositoryCollaborator) returns (MsgUpdateRepositoryCollaboratorResponse);
rpc RemoveRepositoryCollaborator(MsgRemoveRepositoryCollaborator) returns (MsgRemoveRepositoryCollaboratorResponse);
Expand Down Expand Up @@ -791,6 +792,12 @@ message MsgUpdateRepositoryDescription {

message MsgUpdateRepositoryDescriptionResponse { }

message MsgToggleRepositoryArchived {
string creator = 1;
RepositoryId repositoryId = 2 [(gogoproto.nullable) = false];
}

message MsgToggleRepositoryArchivedResponse { }

message MsgChangeOwner {
string creator = 1;
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Gitopia
test
![Gitopia](https://github.com/gitopia/gitopia-web/blob/master/public/og-gitopia.jpg)

[Gitopia](https://gitopia.com/) is a platform for developers and web3 communities to collaborate on open-source projects in a decentralized and censorship-free environment by using permanent storage through Filecoin, Arweave, and IPFS. Additionally, it offers web3-specific features such as Bounties and Proposals, which Gitopia supports through its native LORE token, as well as familiar collaboration tools like Issues and Pull-Requests.
Expand Down
1 change: 1 addition & 0 deletions x/gitopia/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdForkRepository())
cmd.AddCommand(CmdRenameRepository())
cmd.AddCommand(CmdUpdateRepositoryDescription())
cmd.AddCommand(CmdToggleRepositoryArchived())
cmd.AddCommand(CmdChangeOwner())
cmd.AddCommand(CmdUpdateRepositoryCollaborator())
cmd.AddCommand(CmdRemoveRepositoryCollaborator())
Expand Down
29 changes: 29 additions & 0 deletions x/gitopia/client/cli/txRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,35 @@ func CmdUpdateRepositoryDescription() *cobra.Command {
return cmd
}

func CmdToggleRepositoryArchived() *cobra.Command {
cmd := &cobra.Command{
Use: "toggle-repository-archived [owner-id] [repository-name]",
Short: "toggle repository archived",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
argOwnerid := args[0]
argRepositoryName := args[1]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgToggleRepositoryArchived(
clientCtx.GetFromAddress().String(),
types.RepositoryId{Id: argOwnerid, Name: argRepositoryName},
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

func CmdChangeOwner() *cobra.Command {
cmd := &cobra.Command{
Use: "change-owner [id] [repository-name] [owner-id]",
Expand Down
4 changes: 4 additions & 0 deletions x/gitopia/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
res, err := msgServer.RenameRepository(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

case *types.MsgToggleRepositoryArchived:
res, err := msgServer.ToggleRepositoryArchived(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

case *types.MsgUpdateRepositoryDescription:
res, err := msgServer.UpdateRepositoryDescription(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
Expand Down
24 changes: 24 additions & 0 deletions x/gitopia/keeper/msg_server_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func (k msgServer) SetBranch(goCtx context.Context, msg *types.MsgSetBranch) (*t
}

repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
}
Expand Down Expand Up @@ -95,6 +99,10 @@ func (k msgServer) MultiSetBranch(goCtx context.Context, msg *types.MsgMultiSetB
}

repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
}
Expand Down Expand Up @@ -170,6 +178,10 @@ func (k msgServer) SetDefaultBranch(goCtx context.Context, msg *types.MsgSetDefa
}

repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
}
Expand Down Expand Up @@ -223,6 +235,10 @@ func (k msgServer) DeleteBranch(goCtx context.Context, msg *types.MsgDeleteBranc
}

repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
}
Expand Down Expand Up @@ -276,6 +292,10 @@ func (k msgServer) MultiDeleteBranch(goCtx context.Context, msg *types.MsgMultiD
}

repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
}
Expand Down Expand Up @@ -337,6 +357,10 @@ func (k msgServer) ToggleForcePush(goCtx context.Context, msg *types.MsgToggleFo
}

repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
}
Expand Down
28 changes: 28 additions & 0 deletions x/gitopia/keeper/msg_server_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func (k msgServer) CreateIssue(goCtx context.Context, msg *types.MsgCreateIssue)
}

repository, found := k.GetAddressRepository(ctx, address.Address, msg.RepositoryId.Name)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.RepositoryId.Name)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository (%v/%v) doesn't exist", msg.RepositoryId.Id, msg.RepositoryId.Name))
}
Expand Down Expand Up @@ -284,6 +288,10 @@ func (k msgServer) ToggleIssueState(goCtx context.Context, msg *types.MsgToggleI
}

repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
}
Expand Down Expand Up @@ -425,6 +433,10 @@ func (k msgServer) AddIssueAssignees(goCtx context.Context, msg *types.MsgAddIss
}

repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
}
Expand Down Expand Up @@ -508,6 +520,10 @@ func (k msgServer) RemoveIssueAssignees(goCtx context.Context, msg *types.MsgRem
}

repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
}
Expand Down Expand Up @@ -582,6 +598,10 @@ func (k msgServer) AddIssueLabels(goCtx context.Context, msg *types.MsgAddIssueL
}

repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
}
Expand Down Expand Up @@ -663,6 +683,10 @@ func (k msgServer) RemoveIssueLabels(goCtx context.Context, msg *types.MsgRemove
}

repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
}
Expand Down Expand Up @@ -745,6 +769,10 @@ func (k msgServer) DeleteIssue(goCtx context.Context, msg *types.MsgDeleteIssue)
}

repository, found := k.GetRepositoryById(ctx, issue.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", issue.RepositoryId))
}
Expand Down
48 changes: 48 additions & 0 deletions x/gitopia/keeper/msg_server_pullRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func (k msgServer) CreatePullRequest(goCtx context.Context, msg *types.MsgCreate
}

headRepository, found := k.GetAddressRepository(ctx, headRepoOwnerAddress.Address, msg.HeadRepositoryId.Name)
if headRepository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %s when archived is set to true", msg.HeadRepositoryId.Name)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("head-repository (%v/%v) doesn't exist", msg.HeadRepositoryId.Id, msg.HeadRepositoryId.Name))
}
Expand All @@ -41,6 +45,9 @@ func (k msgServer) CreatePullRequest(goCtx context.Context, msg *types.MsgCreate
}

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

baseRepository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
if baseRepository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", pullRequest.Base.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
}
Expand Down Expand Up @@ -377,6 +388,9 @@ func (k msgServer) SetPullRequestState(goCtx context.Context, msg *types.MsgSetP
blockTime := ctx.BlockTime().Unix()

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

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

repository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
}
Expand Down Expand Up @@ -784,6 +805,10 @@ func (k msgServer) AddPullRequestAssignees(goCtx context.Context, msg *types.Msg
}

repository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
}
Expand Down Expand Up @@ -861,6 +886,10 @@ func (k msgServer) RemovePullRequestAssignees(goCtx context.Context, msg *types.
}

repository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
}
Expand Down Expand Up @@ -935,6 +964,9 @@ func (k msgServer) LinkPullRequestIssueByIid(goCtx context.Context, msg *types.M
}

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

baseRepository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
if baseRepository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
}
Expand Down Expand Up @@ -1153,6 +1189,10 @@ func (k msgServer) AddPullRequestLabels(goCtx context.Context, msg *types.MsgAdd
}

repository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
}
Expand Down Expand Up @@ -1234,6 +1274,10 @@ func (k msgServer) RemovePullRequestLabels(goCtx context.Context, msg *types.Msg
}

repository, found := k.GetRepositoryById(ctx, pullRequest.Base.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", pullRequest.Base.RepositoryId))
}
Expand Down Expand Up @@ -1315,6 +1359,10 @@ func (k msgServer) DeletePullRequest(goCtx context.Context, msg *types.MsgDelete
}

repository, found := k.GetRepositoryById(ctx, msg.RepositoryId)
if repository.Archived {
return nil, fmt.Errorf("don't allow any modifications to repository %d when archived is set to true", msg.RepositoryId)
}

if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("repository id (%d) doesn't exist", msg.RepositoryId))
}
Expand Down
Loading