@@ -84,7 +84,7 @@ func (r *Repo) CreateLock(c *gin.Context) {
8484 vu , _ := c .Get (global .KeyUser )
8585 u := vu .(* ent.User )
8686
87- cfg , err := r .i .GetConfig (ctx , u , re )
87+ env , err := r .i .GetEnv (ctx , u , re , p . Env )
8888 if e .HasErrorCode (err , e .ErrorCodeEntityNotFound ) {
8989 r .log .Check (gb .GetZapLogLevel (err ), "The configuration file is not found." ).Write (zap .Error (err ))
9090 // To override the HTTP status 422.
@@ -96,32 +96,8 @@ func (r *Repo) CreateLock(c *gin.Context) {
9696 return
9797 }
9898
99- if ! cfg .HasEnv (p .Env ) {
100- r .log .Warn ("The environment is not defined in the configuration." )
101- gb .ResponseWithError (
102- c ,
103- e .NewErrorWithMessage (e .ErrorCodeConfigParseError , "The environment is not defiend in the configuration." , nil ),
104- )
105- return
106- }
107-
108- // TODO: migrate the business logic into the interactor.
109- if ok , err := r .i .HasLockOfRepoForEnv (ctx , re , p .Env ); ok {
110- r .log .Warn ("The lock already exist." , zap .String ("env" , p .Env ))
111- gb .ResponseWithError (
112- c ,
113- e .NewErrorWithMessage (e .ErrorCodeEntityUnprocessable , "The lock already exist." , err ),
114- )
115- return
116- } else if err != nil {
117- r .log .Check (gb .GetZapLogLevel (err ), "Failed to check the lock." ).Write (zap .Error (err ))
118- gb .ResponseWithError (c , err )
119- return
120- }
121-
122- // Lock the environment.
12399 l , err := r .i .CreateLock (ctx , & ent.Lock {
124- Env : p . Env ,
100+ Env : env . Name ,
125101 ExpiredAt : expiredAt ,
126102 UserID : u .ID ,
127103 RepoID : re .ID ,
@@ -136,7 +112,7 @@ func (r *Repo) CreateLock(c *gin.Context) {
136112 l = nl
137113 }
138114
139- r .log .Debug ("Lock the env ." , zap .String ("env" , p .Env ))
115+ r .log .Info ("Lock the environment ." , zap .String ("repo" , re . GetFullName ()), zap . String ( " env" , p .Env ), zap . String ( "login" , u . Login ))
140116 gb .Response (c , http .StatusCreated , l )
141117}
142118
@@ -201,6 +177,7 @@ func (r *Repo) UpdateLock(c *gin.Context) {
201177 l = nl
202178 }
203179
180+ r .log .Info ("Patch the environment lock." , zap .Int ("lock_id" , l .ID ))
204181 gb .Response (c , http .StatusOK , l )
205182}
206183
0 commit comments