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

Commit 277d562

Browse files
author
noah
committed
Fix to add RepoID when creating a status
1 parent d7a424f commit 277d562

File tree

12 files changed

+110
-29
lines changed

12 files changed

+110
-29
lines changed

internal/interactor/deployment.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func (i *DeploymentInteractor) Deploy(ctx context.Context, u *ent.User, r *ent.R
125125
Status: string(deployment.StatusWaiting),
126126
Description: "Gitploy waits the reviews.",
127127
DeploymentID: d.ID,
128+
RepoID: r.ID,
128129
}); err != nil {
129130
i.log.Error("Failed to create a deployment status.", zap.Error(err))
130131
}
@@ -153,6 +154,7 @@ func (i *DeploymentInteractor) Deploy(ctx context.Context, u *ent.User, r *ent.R
153154
Status: string(deployment.StatusCreated),
154155
Description: "Gitploy starts to deploy.",
155156
DeploymentID: d.ID,
157+
RepoID: r.ID,
156158
}); err != nil {
157159
i.log.Error("Failed to create a deployment status.", zap.Error(err))
158160
}
@@ -235,6 +237,7 @@ func (i *DeploymentInteractor) DeployToRemote(ctx context.Context, u *ent.User,
235237
Status: string(deployment.StatusCreated),
236238
Description: "Gitploy start to deploy.",
237239
DeploymentID: d.ID,
240+
RepoID: r.ID,
238241
})
239242

240243
return d, nil
@@ -301,6 +304,7 @@ L:
301304
Status: "canceled",
302305
Description: "Gitploy cancels the inactive deployment.",
303306
DeploymentID: d.ID,
307+
RepoID: d.RepoID,
304308
}
305309
if err := i.scm.CancelDeployment(ctx, d.Edges.User, d.Edges.Repo, d, s); err != nil {
306310
i.log.Error("It has failed to cancel the remote deployment.", zap.Error(err))

internal/pkg/store/deploymentstatus.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,27 @@ func (s *Store) ListDeploymentStatuses(ctx context.Context, d *ent.Deployment) (
2121
return dss, nil
2222
}
2323

24+
func (s *Store) FindDeploymentStatusByID(ctx context.Context, id int) (*ent.DeploymentStatus, error) {
25+
ds, err := s.c.DeploymentStatus.Query().
26+
Where(deploymentstatus.IDEQ(id)).
27+
WithDeployment().
28+
WithRepo().
29+
Only(ctx)
30+
if ent.IsNotFound(err) {
31+
return nil, e.NewError(e.ErrorCodeEntityNotFound, err)
32+
}
33+
34+
return ds, nil
35+
}
36+
2437
func (s *Store) CreateEntDeploymentStatus(ctx context.Context, ds *ent.DeploymentStatus) (*ent.DeploymentStatus, error) {
2538
// Build the query creating a deployment status.
2639
qry := s.c.DeploymentStatus.Create().
2740
SetStatus(ds.Status).
2841
SetDescription(ds.Description).
2942
SetLogURL(ds.LogURL).
30-
SetDeploymentID(ds.DeploymentID)
43+
SetDeploymentID(ds.DeploymentID).
44+
SetRepoID(ds.RepoID)
3145

3246
if !ds.CreatedAt.IsZero() {
3347
qry.SetCreatedAt(ds.CreatedAt.UTC())
@@ -49,12 +63,3 @@ func (s *Store) CreateEntDeploymentStatus(ctx context.Context, ds *ent.Deploymen
4963

5064
return ret, nil
5165
}
52-
53-
func (s *Store) FindDeploymentStatusByID(ctx context.Context, id int) (*ent.DeploymentStatus, error) {
54-
ds, err := s.c.DeploymentStatus.Get(ctx, id)
55-
if ent.IsNotFound(err) {
56-
return nil, e.NewError(e.ErrorCodeEntityNotFound, err)
57-
}
58-
59-
return ds, nil
60-
}

internal/pkg/store/event.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ func (s *Store) ListEventsGreaterThanTime(ctx context.Context, t time.Time) ([]*
3030
}).
3131
WithDeploymentStatus(func(dsq *ent.DeploymentStatusQuery) {
3232
dsq.
33-
WithDeployment()
33+
WithDeployment().
34+
WithRepo()
3435
}).
3536
WithReview(func(rq *ent.ReviewQuery) {
3637
rq.

internal/server/hooks/hook.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func (h *Hooks) handleGithubDeploymentEvent(c *gin.Context) {
117117
}
118118

119119
ds.DeploymentID = d.ID
120+
ds.RepoID = d.RepoID
120121
if ds, err = h.i.CreateDeploymentStatus(ctx, ds); err != nil {
121122
h.log.Check(gb.GetZapLogLevel(err), "Failed to create a new the deployment status.").Write(zap.Error(err))
122123
gb.ResponseWithError(c, err)

model/ent/deploymentstatus.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

model/ent/deploymentstatus/where.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

model/ent/deploymentstatus_create.go

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

model/ent/deploymentstatus_update.go

Lines changed: 28 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

model/ent/migrate/schema.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

model/ent/mutation.go

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)