Skip to content

Commit 940222c

Browse files
committed
Enforce explicitly setting SHA in API requests
Signed-off-by: Lukas Peter Aldershaab <[email protected]>
1 parent d0294cd commit 940222c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Diff for: server/controllers/api_controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type APIRequest struct {
3939
Repository string `validate:"required"`
4040
Ref string `validate:"required"`
4141
Type string `validate:"required"`
42+
Sha string `validate:"required"`
4243
PR int
4344
Projects []string
4445
Paths []struct {
@@ -239,7 +240,7 @@ func (a *APIController) apiParseAndValidate(r *http.Request) (*APIRequest, *comm
239240
Num: request.PR,
240241
BaseBranch: request.Ref,
241242
HeadBranch: request.Ref,
242-
HeadCommit: request.Ref,
243+
HeadCommit: request.Sha,
243244
BaseRepo: baseRepo,
244245
},
245246
Scope: a.Scope,

Diff for: server/controllers/api_controller_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestAPIController_Plan(t *testing.T) {
2828
body, _ := json.Marshal(controllers.APIRequest{
2929
Repository: "Repo",
3030
Ref: "main",
31+
Sha: "abc123",
3132
Type: "Gitlab",
3233
Projects: []string{"default"},
3334
})
@@ -45,6 +46,7 @@ func TestAPIController_Apply(t *testing.T) {
4546
body, _ := json.Marshal(controllers.APIRequest{
4647
Repository: "Repo",
4748
Ref: "main",
49+
Sha: "abc123",
4850
Type: "Gitlab",
4951
Projects: []string{"default"},
5052
})

0 commit comments

Comments
 (0)