Commit 63265243 authored by Jacob Schatz's avatar Jacob Schatz

Merge branch 'build-notification-fixes' into 'master'

Build notification null check

Cancels build notification interval on page change

See merge request !3540
parents d75ec6cd 1b4a56bd
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
notificationGranted = (message, opts, onclick) -> notificationGranted = (message, opts, onclick) ->
notification = new Notification(message, opts) notification = new Notification(message, opts)
# Hide the notification after X amount of seconds
setTimeout ->
notification.close()
, 8000
if onclick if onclick
notification.onclick = onclick notification.onclick = onclick
......
...@@ -12,10 +12,19 @@ class @MergeRequestWidget ...@@ -12,10 +12,19 @@ class @MergeRequestWidget
@readyForCICheck = true @readyForCICheck = true
clearInterval @fetchBuildStatusInterval clearInterval @fetchBuildStatusInterval
@clearEventListeners()
@addEventListeners()
@pollCIStatus() @pollCIStatus()
notifyPermissions() notifyPermissions()
setOpts: (@opts) -> clearEventListeners: ->
$(document).off 'page:change.merge_request'
addEventListeners: ->
$(document).on 'page:change.merge_request', =>
if $('body').data('page') isnt 'projects:merge_requests:show'
clearInterval @fetchBuildStatusInterval
@clearEventListeners()
mergeInProgress: (deleteSourceBranch = false)-> mergeInProgress: (deleteSourceBranch = false)->
$.ajax $.ajax
...@@ -38,7 +47,7 @@ class @MergeRequestWidget ...@@ -38,7 +47,7 @@ class @MergeRequestWidget
$('.mr-state-widget').replaceWith(data) $('.mr-state-widget').replaceWith(data)
ciLabelForStatus: (status) -> ciLabelForStatus: (status) ->
if status == 'success' if status is 'success'
'passed' 'passed'
else else
status status
...@@ -67,18 +76,28 @@ class @MergeRequestWidget ...@@ -67,18 +76,28 @@ class @MergeRequestWidget
@opts.ci_status = data.status @opts.ci_status = data.status
return return
if data.status isnt @opts.ci_status if data.status isnt @opts.ci_status and data.status?
@showCIStatus data.status @showCIStatus data.status
if data.coverage if data.coverage
@showCICoverage data.coverage @showCICoverage data.coverage
if showNotification if showNotification
message = @opts.ci_message.replace('{{status}}', @ciLabelForStatus(data.status)) status = @ciLabelForStatus(data.status)
if status is "preparing"
title = @opts.ci_title.preparing
status = status.charAt(0).toUpperCase() + status.slice(1);
message = @opts.ci_message.preparing.replace('{{status}}', status)
else
title = @opts.ci_title.normal
message = @opts.ci_message.normal.replace('{{status}}', status)
title = title.replace('{{status}}', status)
message = message.replace('{{sha}}', data.sha) message = message.replace('{{sha}}', data.sha)
message = message.replace('{{title}}', data.title) message = message.replace('{{title}}', data.title)
notify( notify(
"Build #{@ciLabelForStatus(data.status)}", title,
message, message,
@opts.gitlab_icon, @opts.gitlab_icon,
-> ->
...@@ -98,6 +117,8 @@ class @MergeRequestWidget ...@@ -98,6 +117,8 @@ class @MergeRequestWidget
@setMergeButtonClass('btn-danger') @setMergeButtonClass('btn-danger')
when "running", "pending" when "running", "pending"
@setMergeButtonClass('btn-warning') @setMergeButtonClass('btn-warning')
when "success"
@setMergeButtonClass('btn-create')
else else
$('.ci_widget.ci-error').show() $('.ci_widget.ci-error').show()
@setMergeButtonClass('btn-danger') @setMergeButtonClass('btn-danger')
...@@ -107,4 +128,6 @@ class @MergeRequestWidget ...@@ -107,4 +128,6 @@ class @MergeRequestWidget
$('.ci_widget:visible .ci-coverage').text(text) $('.ci_widget:visible .ci-coverage').text(text)
setMergeButtonClass: (css_class) -> setMergeButtonClass: (css_class) ->
$('.accept_merge_request').removeClass("btn-create").addClass(css_class) $('.accept_merge_request')
.removeClass('btn-danger btn-warning btn-create')
.addClass(css_class)
...@@ -237,6 +237,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -237,6 +237,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
end end
status = "preparing" if status.nil?
response = { response = {
title: merge_request.title, title: merge_request.title,
sha: merge_request.last_commit_short_sha, sha: merge_request.last_commit_short_sha,
......
...@@ -8,20 +8,22 @@ ...@@ -8,20 +8,22 @@
= render 'projects/merge_requests/widget/locked' = render 'projects/merge_requests/widget/locked'
:javascript :javascript
var merge_request_widget;
var opts = { var opts = {
merge_check_url: "#{merge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", merge_check_url: "#{merge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
check_enable: #{@merge_request.unchecked? ? "true" : "false"}, check_enable: #{@merge_request.unchecked? ? "true" : "false"},
ci_status_url: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", ci_status_url: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
gitlab_icon: "#{asset_path 'gitlab_logo.png'}", gitlab_icon: "#{asset_path 'gitlab_logo.png'}",
ci_status: "", ci_status: "",
ci_message: "Build {{status}} for \"{{title}}\"", ci_message: {
normal: "Build {{status}} for \"{{title}}\"",
preparing: "{{status}} build for \"{{title}}\""
},
ci_enable: #{@project.ci_service ? "true" : "false"}, ci_enable: #{@project.ci_service ? "true" : "false"},
ci_title: {
preparing: "{{status}} build",
normal: "Build {{status}}"
},
builds_path: "#{builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}" builds_path: "#{builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}"
}; };
if(typeof merge_request_widget === 'undefined') {
merge_request_widget = new MergeRequestWidget(opts); merge_request_widget = new MergeRequestWidget(opts);
} else {
merge_request_widget.setOpts(opts);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment