webhook: use provided userID

This commit is contained in:
Simone Gotti 2019-04-03 15:11:50 +02:00
parent 2548598bb8
commit a2cd92c70b

View File

@ -120,6 +120,11 @@ func (h *webhooksHandler) handleWebhook(r *http.Request) (int, string, error) {
ctx := r.Context()
projectID := r.URL.Query().Get("projectid")
userID := r.URL.Query().Get("userid")
if projectID == "" && userID == "" {
return http.StatusBadRequest, "", errors.Errorf("bad webhook url %q. Missing projectid or userid", r.URL)
}
isUserBuild := false
if projectID == "" {
isUserBuild = true
@ -132,7 +137,6 @@ func (h *webhooksHandler) handleWebhook(r *http.Request) (int, string, error) {
var cloneURL string
var skipSSHHostKeyCheck bool
var runType types.RunType
var userID string
variables := map[string]string{}
var gitSource gitsource.GitSource
@ -220,9 +224,9 @@ func (h *webhooksHandler) handleWebhook(r *http.Request) (int, string, error) {
return http.StatusBadRequest, "", errors.Wrapf(err, "failed to parse webhook")
}
user, _, err := h.configstoreClient.GetUserByName(ctx, webhookData.Repo.Owner)
user, _, err := h.configstoreClient.GetUser(ctx, userID)
if err != nil {
return http.StatusBadRequest, "", errors.Wrapf(err, "failed to get project %s", projectID)
return http.StatusBadRequest, "", errors.Wrapf(err, "failed to get user with id %q", userID)
}
h.log.Debugf("user: %s", util.Dump(user))
userID = user.ID