fix(G06): remove duplicate trim/validate in webhook receiver

- Move strings.TrimSpace into validateBranchUpdatedPayload to avoid
  duplicate validation in ReceiveGitoWebhook
- Update CODE_REVIEW to reflect the improvement
This commit is contained in:
toki 2026-06-19 11:51:10 +09:00
parent 2b35251b6d
commit 5d2acc1afb
2 changed files with 5 additions and 9 deletions

View file

@ -111,7 +111,8 @@ task=m-gito-http-webhook-consumer-readiness/02+01_http_receiver_idempotency, pla
1. **로컬 validation 함수 도입**: `services/core/internal/http/gito_webhook.go``validateBranchUpdatedPayload` helper 함수를 추가했다. import cycle을 피하기 위해 `gitoevents.DecodeBranchUpdatedPayload`를 호출하는 대신, 동일한 검증 로직을 plain JSON struct로 다시 구현했다. 1. **로컬 validation 함수 도입**: `services/core/internal/http/gito_webhook.go``validateBranchUpdatedPayload` helper 함수를 추가했다. import cycle을 피하기 위해 `gitoevents.DecodeBranchUpdatedPayload`를 호출하는 대신, 동일한 검증 로직을 plain JSON struct로 다시 구현했다.
2. **`gitoWebhookPayload` struct 확장**: `Type``ChangedFiles` 필드를 추가하여 body contract validation을 수행할 수 있도록 했다. `ChangedFiles``interface{}` 타입으로 JSON decoding 시 []interface{}로 유지되도록 했다. 2. **`gitoWebhookPayload` struct 확장**: `Type``ChangedFiles` 필드를 추가하여 body contract validation을 수행할 수 있도록 했다. `ChangedFiles``interface{}` 타입으로 JSON decoding 시 []interface{}로 유지되도록 했다.
3. **validation 호출 시점**: `json.Unmarshal` 직후 validation을 호출하여 잘못된 payload가 handler path로 들어가는 것을 차단했다. 기존 `repo_id`/`branch` 공백 검증과 병렬로 동작한다. 3. **validation 호출 시점**: `json.Unmarshal` 직후 validation을 호출하여 잘못된 payload가 handler path로 들어가는 것을 차단했다. 기존 `repo_id`/`branch` 공백 검증을 validator 내부로 통합하여 중복을 제거했다.
4. **중복 검증 제거**: `ReceiveGitoWebhook`의 별도 `strings.TrimSpace` + 공백 검증을 `validateBranchUpdatedPayload` 내부로 통합했다.
## 사용자 리뷰 요청 ## 사용자 리뷰 요청

View file

@ -81,7 +81,9 @@ func validateBranchUpdatedPayload(p *gitoWebhookPayload) error {
return fmt.Errorf("payload type %q, want %q", p.Type, "branch.updated") return fmt.Errorf("payload type %q, want %q", p.Type, "branch.updated")
} }
// repo_id and branch are required // repo_id and branch are required (trim whitespace before check)
p.RepoID = strings.TrimSpace(p.RepoID)
p.Branch = strings.TrimSpace(p.Branch)
if p.RepoID == "" { if p.RepoID == "" {
return errors.New("payload missing required field repo_id") return errors.New("payload missing required field repo_id")
} }
@ -139,13 +141,6 @@ func (h *Handler) ReceiveGitoWebhook(w stdhttp.ResponseWriter, r *stdhttp.Reques
return return
} }
p.RepoID = strings.TrimSpace(p.RepoID)
p.Branch = strings.TrimSpace(p.Branch)
if p.RepoID == "" || p.Branch == "" {
writeError(w, stdhttp.StatusBadRequest, fmt.Sprintf("invalid branch.updated payload: %s", missingGitoFields(p)))
return
}
ev := GitoBranchUpdatedEvent{ ev := GitoBranchUpdatedEvent{
RepoID: p.RepoID, RepoID: p.RepoID,
Branch: p.Branch, Branch: p.Branch,