mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 22:26:22 +00:00
Merge branch 'issue-10031' into informative-deploys
This commit is contained in:
commit
4604560d51
2 changed files with 32 additions and 4 deletions
|
@ -40,7 +40,7 @@ class DeployJob < ApplicationJob
|
|||
# No es opcional
|
||||
unless @deployed[:deploy_local][:status]
|
||||
# Hacer fallar la tarea
|
||||
raise DeployException, deploy_local.build_stats.last.log
|
||||
raise DeployException, 'Falló la compilación'
|
||||
end
|
||||
|
||||
deploy_others
|
||||
|
@ -59,7 +59,13 @@ class DeployJob < ApplicationJob
|
|||
# @param :exception [StandardError]
|
||||
# @param :deploy [Deploy]
|
||||
def notify_exception(exception, deploy = nil)
|
||||
ExceptionNotifier.notify_exception(exception, data: { site: @site.id, deploy: deploy&.type })
|
||||
data = {
|
||||
site: @site.id,
|
||||
deploy: deploy&.type,
|
||||
log: deploy&.build_stats&.last&.log
|
||||
}
|
||||
|
||||
ExceptionNotifier.notify_exception(exception, data: data)
|
||||
end
|
||||
|
||||
def deploy_local
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
# Notifica excepciones a una instancia de Gitlab, como incidencias
|
||||
# nuevas o como comentarios a las incidencias pre-existentes.
|
||||
class GitlabNotifierJob < ApplicationJob
|
||||
class GitlabNotifierError < StandardError; end
|
||||
|
||||
include ExceptionNotifier::BacktraceCleaner
|
||||
|
||||
# Variables que vamos a acceder luego
|
||||
|
@ -18,22 +20,28 @@ class GitlabNotifierJob < ApplicationJob
|
|||
@issue_data = { count: 1 }
|
||||
# Necesitamos saber si el issue ya existía
|
||||
@cached = false
|
||||
@issue = {}
|
||||
|
||||
# Traemos los datos desde la caché si existen, sino generamos un
|
||||
# issue nuevo e inicializamos la caché
|
||||
@issue_data = Rails.cache.fetch(cache_key) do
|
||||
issue = client.new_issue confidential: true, title: title, description: description, issue_type: 'incident'
|
||||
@issue = client.new_issue confidential: true, title: title, description: description, issue_type: 'incident'
|
||||
@cached = true
|
||||
|
||||
{
|
||||
count: 1,
|
||||
issue: issue['iid'],
|
||||
issue: @issue['iid'],
|
||||
user_agents: [user_agent].compact,
|
||||
params: [request&.filtered_parameters].compact,
|
||||
urls: [url].compact
|
||||
}
|
||||
end
|
||||
|
||||
unless @issue['iid']
|
||||
Rails.cache.delete(cache_key)
|
||||
raise GitlabNotifierError, @issue.dig('message', 'title')&.join(', ')
|
||||
end
|
||||
|
||||
# No seguimos actualizando si acabamos de generar el issue
|
||||
return if cached
|
||||
|
||||
|
@ -104,6 +112,7 @@ class GitlabNotifierJob < ApplicationJob
|
|||
# @return [String]
|
||||
def description
|
||||
@description ||= ''.dup.tap do |d|
|
||||
d << log_section
|
||||
d << request_section
|
||||
d << javascript_section
|
||||
d << javascript_footer
|
||||
|
@ -151,6 +160,19 @@ class GitlabNotifierJob < ApplicationJob
|
|||
@client ||= GitlabApiClient.new
|
||||
end
|
||||
|
||||
# @return [String]
|
||||
def log_section
|
||||
return '' unless options[:log]
|
||||
|
||||
<<~LOG
|
||||
# Log
|
||||
|
||||
```
|
||||
#{options[:log]}
|
||||
```
|
||||
LOG
|
||||
end
|
||||
|
||||
# Muestra información de la petición
|
||||
#
|
||||
# @return [String]
|
||||
|
|
Loading…
Reference in a new issue