Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Silence allow list errors works again #2535

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions server/controllers/events/events_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ func (e *VCSEventsController) Post(w http.ResponseWriter, r *http.Request) {
}

type HTTPError struct {
err error
code int
err error
code int
isSilenced bool
}

type HTTPResponse struct {
Expand Down Expand Up @@ -180,7 +181,9 @@ func (e *VCSEventsController) handleGithubPost(w http.ResponseWriter, r *http.Re
}

if resp.err.code != 0 {
logger.Err("error handling gh post code: %d err: %s", resp.err.code, resp.err.err.Error())
if !resp.err.isSilenced {
logger.Err("error handling gh post code: %d err: %s", resp.err.code, resp.err.err.Error())
}
scope.Counter(fmt.Sprintf("error_%d", resp.err.code)).Inc(1)
w.WriteHeader(resp.err.code)
fmt.Fprintln(w, resp.err.err.Error())
Expand Down Expand Up @@ -294,8 +297,9 @@ func (e *VCSEventsController) HandleGithubCommentEvent(event *github.IssueCommen
return HTTPResponse{
body: wrapped.Error(),
err: HTTPError{
code: http.StatusBadRequest,
err: wrapped,
code: http.StatusBadRequest,
err: wrapped,
isSilenced: false,
},
}
}
Expand Down Expand Up @@ -401,8 +405,9 @@ func (e *VCSEventsController) HandleGithubPullRequestEvent(logger logging.Simple
return HTTPResponse{
body: wrapped.Error(),
err: HTTPError{
code: http.StatusBadRequest,
err: wrapped,
code: http.StatusBadRequest,
err: wrapped,
isSilenced: false,
},
}
}
Expand All @@ -425,8 +430,9 @@ func (e *VCSEventsController) handlePullRequestEvent(logger logging.SimpleLoggin
return HTTPResponse{
body: err.Error(),
err: HTTPError{
code: http.StatusForbidden,
err: err,
code: http.StatusForbidden,
err: err,
isSilenced: e.SilenceAllowlistErrors,
},
}
}
Expand All @@ -453,8 +459,9 @@ func (e *VCSEventsController) handlePullRequestEvent(logger logging.SimpleLoggin
return HTTPResponse{
body: err.Error(),
err: HTTPError{
code: http.StatusForbidden,
err: err,
code: http.StatusForbidden,
err: err,
isSilenced: false,
},
}
}
Expand Down Expand Up @@ -538,11 +545,13 @@ func (e *VCSEventsController) handleCommentEvent(logger logging.SimpleLogging, b
e.commentNotAllowlisted(baseRepo, pullNum)

err := errors.New("Repo not allowlisted")

return HTTPResponse{
body: err.Error(),
err: HTTPError{
err: err,
code: http.StatusForbidden,
err: err,
code: http.StatusForbidden,
isSilenced: e.SilenceAllowlistErrors,
},
}
}
Expand Down