Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
Signed-off-by: Zach Aller <[email protected]>
  • Loading branch information
zachaller committed Nov 21, 2024
1 parent f5f9863 commit ff9da7c
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions internal/webhookreceiver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ func (wr *webhookReceiver) Start(ctx context.Context, addr string) error {
return fmt.Errorf("failed to set field index for .status.proposed.hydrated.sha: %w", err)
}

if err := wr.mgr.GetFieldIndexer().IndexField(ctx, &promoterv1alpha1.ChangeTransferPolicy{}, ".spec.proposedBranch", func(rawObj client.Object) []string {
//nolint:forcetypeassert
ctp := rawObj.(*promoterv1alpha1.ChangeTransferPolicy)
return []string{ctp.Spec.ProposedBranch}
}); err != nil {
return fmt.Errorf("failed to set field index for .status.proposed.hydrated.sha: %w", err)
}

mux := http.NewServeMux()
mux.HandleFunc("/", wr.postRoot)

Expand Down Expand Up @@ -113,12 +105,14 @@ func (wr *webhookReceiver) postRoot(w http.ResponseWriter, r *http.Request) {

func (wr *webhookReceiver) findChangeTransferPolicy(ctx context.Context, jsonBytes []byte) (*promoterv1alpha1.ChangeTransferPolicy, error) {
var beforeSha string
var ref string
ctpLists := promoterv1alpha1.ChangeTransferPolicyList{}

// TODO: probably move to own function once we start adding providers because rules might be more complex
if gjson.GetBytes(jsonBytes, "before").Exists() && gjson.GetBytes(jsonBytes, "pusher").Exists() {
// Github
beforeSha = gjson.GetBytes(jsonBytes, "before").String()
ref = gjson.GetBytes(jsonBytes, "ref").String()
}

if beforeSha == "" {
Expand All @@ -136,10 +130,10 @@ func (wr *webhookReceiver) findChangeTransferPolicy(ctx context.Context, jsonByt
}

if len(ctpLists.Items) == 0 {
return nil, fmt.Errorf("no changetransferpolicies found from webhook receiver sha: %s", beforeSha)
return nil, fmt.Errorf("no changetransferpolicies found from webhook receiver sha: %s, ref: %s", beforeSha, ref)
}
if len(ctpLists.Items) > 1 {
return nil, fmt.Errorf("to many changetranferpolicies found for sha: %s", beforeSha)
return nil, fmt.Errorf("to many changetranferpolicies found for sha: %s, ref: %s", beforeSha, ref)
}

return &ctpLists.Items[0], nil
Expand Down

0 comments on commit ff9da7c

Please sign in to comment.