Skip to content

Commit

Permalink
Enforce explicitly setting SHA in API requests
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Peter Aldershaab <lukas.aldershaab@lego.com>
  • Loading branch information
lukaspj committed Dec 7, 2024
1 parent d0294cd commit 940222c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/controllers/api_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type APIRequest struct {
Repository string `validate:"required"`
Ref string `validate:"required"`
Type string `validate:"required"`
Sha string `validate:"required"`
PR int
Projects []string
Paths []struct {
Expand Down Expand Up @@ -239,7 +240,7 @@ func (a *APIController) apiParseAndValidate(r *http.Request) (*APIRequest, *comm
Num: request.PR,
BaseBranch: request.Ref,
HeadBranch: request.Ref,
HeadCommit: request.Ref,
HeadCommit: request.Sha,
BaseRepo: baseRepo,
},
Scope: a.Scope,
Expand Down
2 changes: 2 additions & 0 deletions server/controllers/api_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAPIController_Plan(t *testing.T) {
body, _ := json.Marshal(controllers.APIRequest{
Repository: "Repo",
Ref: "main",
Sha: "abc123",
Type: "Gitlab",
Projects: []string{"default"},
})
Expand All @@ -45,6 +46,7 @@ func TestAPIController_Apply(t *testing.T) {
body, _ := json.Marshal(controllers.APIRequest{
Repository: "Repo",
Ref: "main",
Sha: "abc123",
Type: "Gitlab",
Projects: []string{"default"},
})
Expand Down

0 comments on commit 940222c

Please sign in to comment.