# frozen_string_literal: true module Api module V1 # Recibe webhooks y lanza un PullJob class WebhooksController < BaseController rescue_from ActiveRecord::RecordNotFound, with: :platforms_answer def site @site ||= Site.find_by_name!(params[:site_id]) end # valida la plataforma del webhook def usuarie # Gitlab token = request.headers["X-Gitlab-Token"] @usuarie = site.roles.find_by!(temporal: false, rol: 'usuarie', token: token).usuarie end # Trae los cambios a partir de un post de Webhooks: # (Gitlab, Github, Guitea, etc) def pull message = I18n.with_locale(site.default_locale) do I18n.t('webhooks.pull.message') end GitPullJob.perform_later(site, usuarie, message) end def platforms_answer head :ok end end end end