2023-07-26 17:44:11 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
2023-08-10 19:05:14 +00:00
|
|
|
# Recibe webhooks y lanza un PullJob
|
2023-07-26 17:44:11 +00:00
|
|
|
class WebhooksController < BaseController
|
2023-08-10 19:05:14 +00:00
|
|
|
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
|
|
|
|
|
2023-07-27 19:46:32 +00:00
|
|
|
# Trae los cambios a partir de un post de Webhooks:
|
|
|
|
# (Gitlab, Github, Guitea, etc)
|
2023-07-26 17:44:11 +00:00
|
|
|
def pull
|
2023-07-27 19:46:32 +00:00
|
|
|
message = I18n.with_locale(site.default_locale) do
|
|
|
|
I18n.t('webhooks.pull.message')
|
|
|
|
end
|
2023-07-26 17:44:11 +00:00
|
|
|
GitPullJob.perform_later(site, usuarie, message)
|
2023-08-10 19:05:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def platforms_answer
|
2023-07-27 20:23:40 +00:00
|
|
|
head :ok
|
2023-07-26 17:44:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|