Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion ent/callback/callback.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ent/migrate/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ent/schema/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func (Callback) Fields() []ent.Field {
Values(
"deploy",
"rollback",
"lock",
"unlock",
),
field.Time("created_at").
Default(time.Now),
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ require (
go.uber.org/zap v1.13.0
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c
gopkg.in/h2non/gock.v1 v1.1.2
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
)
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down Expand Up @@ -334,8 +332,6 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/nleeper/goment v1.4.2 h1:r4c8KkCrsBJUnVi/IJ5HEqev5QY8aCWOXQtu+eYXtnI=
github.com/nleeper/goment v1.4.2/go.mod h1:zDl5bAyDhqxwQKAvkSXMRLOdCowrdZz53ofRJc4VhTo=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand Down Expand Up @@ -739,8 +735,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
Expand Down
1 change: 1 addition & 0 deletions internal/interactor/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type (
DeleteApproval(ctx context.Context, a *ent.Approval) error

ListLocksOfRepo(ctx context.Context, r *ent.Repo) ([]*ent.Lock, error)
FindLockOfRepoByEnv(ctx context.Context, r *ent.Repo, env string) (*ent.Lock, error)
HasLockOfRepoForEnv(ctx context.Context, r *ent.Repo, env string) (bool, error)
FindLockByID(ctx context.Context, id int) (*ent.Lock, error)
CreateLock(ctx context.Context, l *ent.Lock) (*ent.Lock, error)
Expand Down
15 changes: 15 additions & 0 deletions internal/interactor/mock/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions internal/pkg/store/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ func (s *Store) ListLocksOfRepo(ctx context.Context, r *ent.Repo) ([]*ent.Lock,
All(ctx)
}

func (s *Store) FindLockOfRepoByEnv(ctx context.Context, r *ent.Repo, env string) (*ent.Lock, error) {
return s.c.Lock.
Query().
Where(
lock.And(
lock.RepoID(r.ID),
lock.EnvEQ(env),
),
).
WithUser().
WithRepo().
Only(ctx)
}

func (s *Store) HasLockOfRepoForEnv(ctx context.Context, r *ent.Repo, env string) (bool, error) {
cnt, err := s.c.Lock.
Query().
Expand Down
2 changes: 1 addition & 1 deletion internal/server/api/v1/repos/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestRepo_CreateLock(t *testing.T) {
t.Log("Get the lock with edges")
m.
EXPECT().
FindLockByID(gomock.Any(), gomock.AssignableToTypeOf(&ent.Lock{})).
FindLockByID(gomock.Any(), 1).
Return(&ent.Lock{ID: 1}, nil)

r := NewRepo(RepoConfig{}, m)
Expand Down
15 changes: 15 additions & 0 deletions internal/server/api/v1/repos/mock/interactor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 2 additions & 11 deletions internal/server/slack/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *Slack) handleDeployCmd(c *gin.Context) {
bv, _ := c.Get(KeyChatUser)
cu := bv.(*ent.ChatUser)

s.log.Debug("Process deploy command.", zap.String("command", cmd.Text))
s.log.Debug("Processing deploy command.", zap.String("command", cmd.Text))
ns, n := parseCmd(cmd.Text)

r, err := s.i.FindRepoOfUserByNamespaceName(ctx, cu.Edges.User, ns, n)
Expand Down Expand Up @@ -121,15 +121,6 @@ func parseCmd(cmd string) (string, string) {
return nn[0], nn[1]
}

func parseFullName(fullname string) (string, string, error) {
namespaceName := strings.Split(fullname, "/")
if len(namespaceName) != 2 {
return "", "", fmt.Errorf("It is a invalid formatted command.")
}

return namespaceName[0], namespaceName[1], nil
}

func buildDeployView(callbackID string, c *vo.Config, perms []*ent.Perm) slack.ModalViewRequest {
envs := []*slack.OptionBlockObject{}
for _, env := range c.Envs {
Expand Down Expand Up @@ -279,7 +270,7 @@ func (s *Slack) interactDeploy(c *gin.Context) {
}

if locked, err := s.i.HasLockOfRepoForEnv(ctx, cb.Edges.Repo, sm.Env); locked {
postBotMessage(cu, "The env is locked. You should unlock the env before deploying.")
postBotMessage(cu, fmt.Sprintf("The `%s` environment is locked. You should unlock the environment before deploying.", sm.Env))
c.Status(http.StatusOK)
return
} else if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions internal/server/slack/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import (
"github.com/gitploy-io/gitploy/vo"
)

const (
pathPostMessage string = "chat.postMessage"
)

func TestSlack_interactDeploy(t *testing.T) {
t.Run("Create a new deployment with payload.", func(t *testing.T) {
m := mock.NewMockInteractor(gomock.NewController(t))
Expand Down
5 changes: 5 additions & 0 deletions internal/server/slack/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ type (

CreateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error)

ListLocksOfRepo(ctx context.Context, r *ent.Repo) ([]*ent.Lock, error)
FindLockOfRepoByEnv(ctx context.Context, r *ent.Repo, env string) (*ent.Lock, error)
HasLockOfRepoForEnv(ctx context.Context, r *ent.Repo, env string) (bool, error)
FindLockByID(ctx context.Context, id int) (*ent.Lock, error)
CreateLock(ctx context.Context, l *ent.Lock) (*ent.Lock, error)
DeleteLock(ctx context.Context, l *ent.Lock) error

SubscribeEvent(fn func(e *ent.Event)) error
UnsubscribeEvent(fn func(e *ent.Event)) error
Expand Down
Loading