diff options
author | Jacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home> | 2016-01-26 00:20:24 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2016-03-18 13:26:48 +0300 |
commit | f7e2109905ba21c4ca61e0ab74da208d18b6adeb (patch) | |
tree | b2e8d492e7d4d68f3cd3dadfcf2bdf64d8d3a04e /app/assets/javascripts/merge_request_widget.js.coffee | |
parent | 51ceb3802f07d82fe9fa606382cf2f1074e1cfb5 (diff) |
Adds notifications API to MR page.
When a build status changes a notification will popup.
Fixes #10851
Diffstat (limited to 'app/assets/javascripts/merge_request_widget.js.coffee')
-rw-r--r-- | app/assets/javascripts/merge_request_widget.js.coffee | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee index b1daa1f34eb..4e422763543 100644 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ b/app/assets/javascripts/merge_request_widget.js.coffee @@ -10,6 +10,8 @@ class @MergeRequestWidget constructor: (@opts) -> modal = $('#modal_merge_info').modal(show: false) @getBuildStatus() + # clear the build poller + $(document).on 'page:fetch', (e) => clearInterval(@fetchBuildStatusInterval) mergeInProgress: (deleteSourceBranch = false)-> $.ajax @@ -31,12 +33,43 @@ class @MergeRequestWidget $.get @opts.url_to_automerge_check, (data) -> $('.mr-state-widget').replaceWith(data) + ciIconForStatus: (status) -> + icon = undefined + switch status + when 'success' + icon = 'check' + when 'failed' + icon = 'close' + when 'running' or 'pending' + icon = 'clock-o' + else + icon = 'circle' + 'fa fa-' + icon + ' fa-fw' + + ciLabelForStatus: (status) -> + if status == 'success' + 'passed' + else + status + getBuildStatus: -> urlToCiCheck = @opts.url_to_ci_check - console.log('checking') - setInterval (-> + _this = @ + @fetchBuildStatusInterval = setInterval (-> $.getJSON urlToCiCheck, (data) -> - console.log("data",data); + if data.status isnt _this.opts.current_status + notify("Build #{_this.ciLabelForStatus(data.status)}", + _this.opts.ci_message.replace('{{status}}', + _this.ciLabelForStatus(data.status))); + _this.opts.current_status = data.status + $('.mr-widget-heading i') + .removeClass() + .addClass(_this.ciIconForStatus(data.status)); + $('.mr-widget-heading .ci_widget') + .removeClass() + .addClass("ci_widget ci-#{data.status}"); + $('.mr-widget-heading span.ci-status-label') + .text(_this.ciLabelForStatus(data.status)) return return ), 5000 |