Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 28f4c03

Browse files
author
Noah Hanjun Lee
authored
Fix to use 'GetEnv' (#230)
1 parent 08a0c3e commit 28f4c03

File tree

2 files changed

+8
-42
lines changed

2 files changed

+8
-42
lines changed

internal/server/api/v1/repos/deployment.go

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (r *Repo) CreateDeployment(c *gin.Context) {
8585
vr, _ := c.Get(KeyRepo)
8686
re := vr.(*ent.Repo)
8787

88-
cf, err := r.i.GetConfig(ctx, u, re)
88+
env, err := r.i.GetEnv(ctx, u, re, p.Env)
8989
if e.HasErrorCode(err, e.ErrorCodeEntityNotFound) {
9090
r.log.Check(gb.GetZapLogLevel(err), "The configuration file is not found.").Write(zap.Error(err))
9191
// To override the HTTP status 422.
@@ -97,24 +97,13 @@ func (r *Repo) CreateDeployment(c *gin.Context) {
9797
return
9898
}
9999

100-
var env *vo.Env
101-
if env = cf.GetEnv(p.Env); env == nil {
102-
r.log.Warn("The environment is not defined in the configuration.")
103-
gb.ResponseWithError(
104-
c,
105-
e.NewErrorWithMessage(e.ErrorCodeConfigParseError, "The environment is not defiend in the configuration.", nil),
106-
)
107-
return
108-
}
109-
110100
d, err := r.i.Deploy(ctx, u, re,
111101
&ent.Deployment{
112102
Type: deployment.Type(p.Type),
113103
Env: p.Env,
114104
Ref: p.Ref,
115105
},
116-
cf.GetEnv(p.Env),
117-
)
106+
env)
118107
if err != nil {
119108
r.log.Check(gb.GetZapLogLevel(err), "Failed to deploy.").Write(zap.Error(err))
120109
gb.ResponseWithError(c, err)
@@ -160,7 +149,7 @@ func (r *Repo) UpdateDeployment(c *gin.Context) {
160149
return
161150
}
162151

163-
cf, err := r.i.GetConfig(ctx, u, re)
152+
env, err := r.i.GetEnv(ctx, u, re, d.Env)
164153
if e.HasErrorCode(err, e.ErrorCodeEntityNotFound) {
165154
r.log.Check(gb.GetZapLogLevel(err), "The configuration file is not found.").Write(zap.Error(err))
166155
// To override the HTTP status 422.
@@ -172,16 +161,6 @@ func (r *Repo) UpdateDeployment(c *gin.Context) {
172161
return
173162
}
174163

175-
var env *vo.Env
176-
if env = cf.GetEnv(d.Env); env == nil {
177-
r.log.Warn("The environment is not defined in the configuration.")
178-
gb.ResponseWithError(
179-
c,
180-
e.NewErrorWithMessage(e.ErrorCodeConfigParseError, "The environment is not defiend in the configuration.", nil),
181-
)
182-
return
183-
}
184-
185164
if d, err = r.i.DeployToRemote(ctx, u, re, d, env); err != nil {
186165
r.log.Check(gb.GetZapLogLevel(err), "It has failed to deploy to the remote.").Write(zap.Error(err))
187166
gb.ResponseWithError(c, err)
@@ -224,7 +203,7 @@ func (r *Repo) RollbackDeployment(c *gin.Context) {
224203
return
225204
}
226205

227-
cf, err := r.i.GetConfig(ctx, u, re)
206+
env, err := r.i.GetEnv(ctx, u, re, d.Env)
228207
if e.HasErrorCode(err, e.ErrorCodeEntityNotFound) {
229208
r.log.Check(gb.GetZapLogLevel(err), "The configuration file is not found.").Write(zap.Error(err))
230209
// To override the HTTP status 422.
@@ -236,25 +215,14 @@ func (r *Repo) RollbackDeployment(c *gin.Context) {
236215
return
237216
}
238217

239-
var env *vo.Env
240-
if env = cf.GetEnv(d.Env); env == nil {
241-
r.log.Warn("The environment is not defined in the configuration.")
242-
gb.ResponseWithError(
243-
c,
244-
e.NewErrorWithMessage(e.ErrorCodeConfigParseError, "The environment is not defiend in the configuration.", nil),
245-
)
246-
return
247-
}
248-
249218
d, err = r.i.Deploy(ctx, u, re,
250219
&ent.Deployment{
251220
Type: d.Type,
252221
Env: d.Env,
253222
Ref: d.Ref,
254223
IsRollback: true,
255224
},
256-
cf.GetEnv(d.Env),
257-
)
225+
env)
258226
if err != nil {
259227
r.log.Check(gb.GetZapLogLevel(err), "Failed to deploy.").Write(zap.Error(err))
260228
gb.ResponseWithError(c, err)

internal/server/api/v1/repos/deployment_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,9 @@ func TestRepo_CreateDeployment(t *testing.T) {
123123
t.Log("Read the config file.")
124124
m.
125125
EXPECT().
126-
GetConfig(gomock.Any(), gomock.AssignableToTypeOf(&ent.User{}), gomock.AssignableToTypeOf(&ent.Repo{})).
127-
Return(&vo.Config{
128-
Envs: []*vo.Env{
129-
{Name: "prod"},
130-
},
126+
GetEnv(gomock.Any(), gomock.AssignableToTypeOf(&ent.User{}), gomock.AssignableToTypeOf(&ent.Repo{}), gomock.Any()).
127+
Return(&vo.Env{
128+
Name: "prod",
131129
}, nil)
132130

133131
t.Log("Deploy with the payload successfully.")

0 commit comments

Comments
 (0)