9
9
10
10
gb "github.com/gitploy-io/gitploy/internal/server/global"
11
11
"github.com/gitploy-io/gitploy/model/ent"
12
+ "github.com/gitploy-io/gitploy/model/ent/deployment"
12
13
"github.com/gitploy-io/gitploy/model/extent"
13
14
"github.com/gitploy-io/gitploy/pkg/e"
14
15
)
@@ -54,15 +55,7 @@ func (s *DeploymentAPI) Rollback(c *gin.Context) {
54
55
return
55
56
}
56
57
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 )
66
59
if err != nil {
67
60
s .log .Check (gb .GetZapLogLevel (err ), "Failed to rollback." ).Write (zap .Error (err ))
68
61
gb .ResponseWithError (c , err )
@@ -77,3 +70,25 @@ func (s *DeploymentAPI) Rollback(c *gin.Context) {
77
70
s .log .Info ("Start to rollback." , zap .String ("repo" , re .GetFullName ()), zap .Int ("number" , d .Number ))
78
71
gb .Response (c , http .StatusCreated , d )
79
72
}
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