diff options
author | Jacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home> | 2016-01-25 16:20:24 -0500 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2016-03-18 10:26:48 +0000 |
commit | f7e2109905ba21c4ca61e0ab74da208d18b6adeb (patch) | |
tree | b2e8d492e7d4d68f3cd3dadfcf2bdf64d8d3a04e /app | |
parent | 51ceb3802f07d82fe9fa606382cf2f1074e1cfb5 (diff) | |
download | gitlab-ce-f7e2109905ba21c4ca61e0ab74da208d18b6adeb.tar.gz |
Adds notifications API to MR page.
When a build status changes a notification will popup.
Fixes #10851
Diffstat (limited to 'app')
5 files changed, 93 insertions, 26 deletions
diff --git a/app/assets/javascripts/lib/notify.js.coffee b/app/assets/javascripts/lib/notify.js.coffee new file mode 100644 index 00000000000..26924d87d68 --- /dev/null +++ b/app/assets/javascripts/lib/notify.js.coffee @@ -0,0 +1,27 @@ +# Written by Jacob Schatz @jakecodes + +((w) -> + notifyMe = (message,body) -> + notification = undefined + opts = + body: body + icon: "#{document.location.origin}/assets/gitlab_logo.png" + # Let's check if the browser supports notifications + if !('Notification' of window) + # do nothing + else if Notification.permission == 'granted' + # If it's okay let's create a notification + notification = new Notification(message, opts) + else if Notification.permission != 'denied' + Notification.requestPermission (permission) -> + # If the user accepts, let's create a notification + if permission == 'granted' + notification = new Notification(message, opts) + return + return + + w.notify = notifyMe + return +) window + +Notification.requestPermission()
\ No newline at end of file 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 diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 259e25c91ab..987b3e1c5b6 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -218,28 +218,26 @@ class Projects::MergeRequestsController < Projects::ApplicationController end end - def st - @ci_commit = @merge_request.ci_commit - @statuses = @ci_commit.statuses if @ci_commit - render json: { - statuses: @statuses - } - end - def ci_status - ci_service = @merge_request.source_project.ci_service - status = ci_service.commit_status(merge_request.last_commit.sha, merge_request.source_branch) + ci_commit = @merge_request.ci_commit + if ci_commit + status = ci_commit.try(:status) + coverage = ci_commit.try(:coverage) + else + ci_service = @merge_request.source_project.ci_service + status = ci_service.commit_status(merge_request.last_commit.sha, merge_request.source_branch) if ci_service - if ci_service.respond_to?(:commit_coverage) - coverage = ci_service.commit_coverage(merge_request.last_commit.sha, merge_request.source_branch) + if ci_service.respond_to?(:commit_coverage) + coverage = ci_service.commit_coverage(merge_request.last_commit.sha, merge_request.source_branch) + end end response = { - status: status, - coverage: coverage + status: status || :not_found, + coverage: coverage || :not_found } - render json: response + render json: response, status: 200 end protected diff --git a/app/views/projects/merge_requests/widget/_heading.html.haml b/app/views/projects/merge_requests/widget/_heading.html.haml index b05ab869215..ccb2f9fa77e 100644 --- a/app/views/projects/merge_requests/widget/_heading.html.haml +++ b/app/views/projects/merge_requests/widget/_heading.html.haml @@ -4,7 +4,8 @@ = ci_status_icon(@ci_commit) %span Build - = ci_status_label(@ci_commit) + %span.ci-status-label + = ci_status_label(@ci_commit) for = succeed "." do = link_to @ci_commit.short_sha, namespace_project_commit_path(@merge_request.source_project.namespace, @merge_request.source_project, @ci_commit.sha), class: "monospace" diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml index 268171fde08..73ec56d170a 100644 --- a/app/views/projects/merge_requests/widget/_show.html.haml +++ b/app/views/projects/merge_requests/widget/_show.html.haml @@ -9,13 +9,21 @@ :javascript var merge_request_widget; - - merge_request_widget = new MergeRequestWidget({ + var opts = { url_to_automerge_check: "#{merge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", check_enable: #{@merge_request.unchecked? ? "true" : "false"}, - url_to_ci_check: "#{st_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", - ci_enable: #{@project.ci_service ? "true" : "false"}, - current_status: "#{@merge_request.gitlab_merge_status}" - }); - var cici = "#{@project}" + url_to_ci_check: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", + ci_enable: #{@project.ci_service ? "true" : "false"} + }; + +- if @merge_request.ci_commit + :javascript + opts.current_status = "#{@merge_request.ci_commit.try(:status)}"; + opts.ci_message = "Build {{status}} for #{@merge_request.ci_commit.sha}"; +- else + :javascript + opts.current_status = "#{@merge_request.source_project.ci_service.commit_status(@merge_request.last_commit.sha, merge_request.source_branch) if @merge_request.source_project.ci_service}"; + opts.ci_message = "Build {{status}} for #{@merge_request.last_commit.sha}"; +:javascript + merge_request_widget = new MergeRequestWidget(opts);
\ No newline at end of file |