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

Commit 3e3234f

Browse files
author
Noah Lee
authored
Fix the bug of the rollback with a branch (#482)
1 parent c74f1f8 commit 3e3234f

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
gb "github.com/gitploy-io/gitploy/internal/server/global"
1111
"github.com/gitploy-io/gitploy/model/ent"
12+
"github.com/gitploy-io/gitploy/model/ent/deployment"
1213
"github.com/gitploy-io/gitploy/model/extent"
1314
"github.com/gitploy-io/gitploy/pkg/e"
1415
)
@@ -54,15 +55,7 @@ func (s *DeploymentAPI) Rollback(c *gin.Context) {
5455
return
5556
}
5657

57-
d, err = s.i.Deploy(ctx, u, re,
58-
&ent.Deployment{
59-
Type: d.Type,
60-
Env: d.Env,
61-
Ref: d.Ref,
62-
DynamicPayload: d.DynamicPayload,
63-
IsRollback: true,
64-
},
65-
env)
58+
d, err = s.i.Deploy(ctx, u, re, s.buildDeploymentForRollback(d), env)
6659
if err != nil {
6760
s.log.Check(gb.GetZapLogLevel(err), "Failed to rollback.").Write(zap.Error(err))
6861
gb.ResponseWithError(c, err)
@@ -77,3 +70,25 @@ func (s *DeploymentAPI) Rollback(c *gin.Context) {
7770
s.log.Info("Start to rollback.", zap.String("repo", re.GetFullName()), zap.Int("number", d.Number))
7871
gb.Response(c, http.StatusCreated, d)
7972
}
73+
74+
func (s *DeploymentAPI) buildDeploymentForRollback(d *ent.Deployment) *ent.Deployment {
75+
// To avoid referencing the head of the branch,
76+
// server has to reference the commit SHA of the deployment.
77+
if d.Type == deployment.TypeBranch && d.Sha != "" {
78+
return &ent.Deployment{
79+
Type: deployment.TypeCommit,
80+
Env: d.Env,
81+
Ref: d.Sha,
82+
DynamicPayload: d.DynamicPayload,
83+
IsRollback: true,
84+
}
85+
}
86+
87+
return &ent.Deployment{
88+
Type: d.Type,
89+
Env: d.Env,
90+
Ref: d.Ref,
91+
DynamicPayload: d.DynamicPayload,
92+
IsRollback: true,
93+
}
94+
}

0 commit comments

Comments
 (0)