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

Commit ff2b209

Browse files
author
noah
committed
Add DynamicPayload to the ent
1 parent e0b037d commit ff2b209

File tree

16 files changed

+216
-25
lines changed

16 files changed

+216
-25
lines changed

Diff for: go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ require (
8080
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
8181
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
8282
golang.org/x/text v0.3.7 // indirect
83+
golang.org/x/tools v0.1.9-0.20211216111533-8d383106f7e7 // indirect
84+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
8385
google.golang.org/appengine v1.6.7 // indirect
8486
google.golang.org/protobuf v1.26.0 // indirect
8587
gopkg.in/yaml.v2 v2.4.0 // indirect

Diff for: go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
881881
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
882882
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
883883
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
884+
golang.org/x/tools v0.1.9-0.20211216111533-8d383106f7e7 h1:M1gcVrIb2lSn2FIL19DG0+/b8nNVKJ7W7b4WcAGZAYM=
884885
golang.org/x/tools v0.1.9-0.20211216111533-8d383106f7e7/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
885886
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
886887
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

Diff for: internal/interactor/deployment.go

+8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (i *DeploymentInteractor) Deploy(ctx context.Context, u *ent.User, r *ent.R
8383
Type: d.Type,
8484
Env: d.Env,
8585
Ref: d.Ref,
86+
DynamicPayload: d.DynamicPayload,
8687
Status: deployment.DefaultStatus,
8788
ProductionEnvironment: env.IsProductionEnvironment(),
8889
IsRollback: d.IsRollback,
@@ -101,6 +102,13 @@ func (i *DeploymentInteractor) Deploy(ctx context.Context, u *ent.User, r *ent.R
101102
return nil, err
102103
}
103104

105+
if env.IsDynamicPayloadEnabled() {
106+
i.log.Debug("Validate the dynamic_payload.")
107+
if err = env.ValidateDynamicPayload(d.DynamicPayload); err != nil {
108+
return nil, err
109+
}
110+
}
111+
104112
if env.HasReview() {
105113
i.log.Debug("Save the deployment to wait reviews.")
106114
d, err = i.store.CreateDeployment(ctx, d)

Diff for: internal/pkg/github/deployment.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import (
1313
)
1414

1515
func (g *Github) CreateRemoteDeployment(ctx context.Context, u *ent.User, r *ent.Repo, d *ent.Deployment, env *extent.Env) (*extent.RemoteDeployment, error) {
16+
// If there is a dynamic payload, set it as the payload.
17+
payload := env.Payload
18+
if d.DynamicPayload != nil {
19+
payload = d.DynamicPayload
20+
}
21+
1622
gd, res, err := g.Client(ctx, u.Token).
1723
Repositories.
1824
CreateDeployment(ctx, r.Namespace, r.Name, &github.DeploymentRequest{
@@ -22,7 +28,7 @@ func (g *Github) CreateRemoteDeployment(ctx context.Context, u *ent.User, r *ent
2228
Description: env.Description,
2329
AutoMerge: env.AutoMerge,
2430
RequiredContexts: env.RequiredContexts,
25-
Payload: env.Payload,
31+
Payload: payload,
2632
ProductionEnvironment: env.ProductionEnvironment,
2733
})
2834
if res.StatusCode == http.StatusConflict {

Diff for: internal/pkg/store/deployment.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ func (s *Store) CreateDeployment(ctx context.Context, d *ent.Deployment) (*ent.D
265265
SetType(d.Type).
266266
SetRef(d.Ref).
267267
SetEnv(d.Env).
268+
SetDynamicPayload(d.DynamicPayload).
268269
SetUID(d.UID).
269270
SetSha(d.Sha).
270271
SetHTMLURL(d.HTMLURL).
@@ -277,10 +278,7 @@ func (s *Store) CreateDeployment(ctx context.Context, d *ent.Deployment) (*ent.D
277278
if ent.IsConstraintError(err) {
278279
return nil, e.NewError(e.ErrorCodeDeploymentConflict, err)
279280
} else if ent.IsValidationError(err) {
280-
return nil, e.NewErrorWithMessage(
281-
e.ErrorCodeEntityUnprocessable,
282-
fmt.Sprintf("Failed to create a deployment. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
283-
err)
281+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityUnprocessable, fmt.Sprintf("Failed to create a deployment. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name), err)
284282
} else if err != nil {
285283
return nil, e.NewError(e.ErrorCodeInternalError, err)
286284
}

Diff for: internal/server/api/v1/repos/deployment_create.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import (
1616

1717
type (
1818
DeploymentPostPayload struct {
19-
Type string `json:"type"`
20-
Ref string `json:"ref"`
21-
Env string `json:"env"`
19+
Type string `json:"type"`
20+
Ref string `json:"ref"`
21+
Env string `json:"env"`
22+
DynamicPayload map[string]interface{} `json:"dynamic_payload"`
2223
}
2324
)
2425

@@ -56,9 +57,10 @@ func (s *DeploymentAPI) Create(c *gin.Context) {
5657

5758
d, err := s.i.Deploy(ctx, u, re,
5859
&ent.Deployment{
59-
Type: deployment.Type(p.Type),
60-
Env: p.Env,
61-
Ref: p.Ref,
60+
Type: deployment.Type(p.Type),
61+
Env: p.Env,
62+
Ref: p.Ref,
63+
DynamicPayload: p.DynamicPayload,
6264
},
6365
env)
6466
if err != nil {

Diff for: model/ent/deployment.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: model/ent/deployment/deployment.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: model/ent/deployment/where.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: model/ent/deployment_create.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: model/ent/deployment_update.go

+50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: model/ent/migrate/schema.go

+9-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)