Commit 9b09a94c authored by Jacob Schatz's avatar Jacob Schatz Committed by Yorick Peterse

Merge branch 'fix-multiple-ci-status-poll' into 'master'

Fixed potential issue with 2 ci status polling events happening

Possible cause for double notifications was if the request was slow & then you changed page whilst this request was happening it would finish on another page & then launch another interval - this stops that issue.

Also passed in the CI status as an option value rather than waiting for the first ajax request to finish

See merge request !3869
parent 8487770e
...@@ -10,6 +10,7 @@ class @MergeRequestWidget ...@@ -10,6 +10,7 @@ class @MergeRequestWidget
$('#modal_merge_info').modal(show: false) $('#modal_merge_info').modal(show: false)
@firstCICheck = true @firstCICheck = true
@readyForCICheck = false @readyForCICheck = false
@cancel = false
clearInterval @fetchBuildStatusInterval clearInterval @fetchBuildStatusInterval
@clearEventListeners() @clearEventListeners()
...@@ -21,10 +22,16 @@ class @MergeRequestWidget ...@@ -21,10 +22,16 @@ class @MergeRequestWidget
clearEventListeners: -> clearEventListeners: ->
$(document).off 'page:change.merge_request' $(document).off 'page:change.merge_request'
cancelPolling: ->
@cancel = true
addEventListeners: -> addEventListeners: ->
allowedPages = ['show', 'commits', 'builds', 'changes']
$(document).on 'page:change.merge_request', => $(document).on 'page:change.merge_request', =>
if $('body').data('page') isnt 'projects:merge_requests:show' page = $('body').data('page').split(':').last()
if allowedPages.indexOf(page) < 0
clearInterval @fetchBuildStatusInterval clearInterval @fetchBuildStatusInterval
@cancelPolling()
@clearEventListeners() @clearEventListeners()
mergeInProgress: (deleteSourceBranch = false)-> mergeInProgress: (deleteSourceBranch = false)->
...@@ -67,6 +74,7 @@ class @MergeRequestWidget ...@@ -67,6 +74,7 @@ class @MergeRequestWidget
$('.ci-widget-fetching').show() $('.ci-widget-fetching').show()
$.getJSON @opts.ci_status_url, (data) => $.getJSON @opts.ci_status_url, (data) =>
return if @cancel
@readyForCICheck = true @readyForCICheck = true
if data.status is '' if data.status is ''
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
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: "#{@merge_request.ci_commit ? @merge_request.ci_commit.status : ''}",
ci_message: { ci_message: {
normal: "Build {{status}} for \"{{title}}\"", normal: "Build {{status}} for \"{{title}}\"",
preparing: "{{status}} build for \"{{title}}\"" preparing: "{{status}} build for \"{{title}}\""
...@@ -26,4 +26,10 @@ ...@@ -26,4 +26,10 @@
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') {
clearInterval(merge_request_widget.fetchBuildStatusInterval);
merge_request_widget.cancelPolling();
merge_request_widget.clearEventListeners();
}
merge_request_widget = new MergeRequestWidget(opts); merge_request_widget = new MergeRequestWidget(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