summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2016-03-16 14:31:35 +0000
committerPhil Hughes <me@iamphill.com>2016-03-18 10:26:48 +0000
commitfcba25515321f57e36b9a8f2156d6b72eafb4c14 (patch)
tree8b482660cdba07ea007e835fbf9d553647ddfbe5
parentb0e2e2e06ed38d8a23e8f834d389baa18a7a885e (diff)
downloadgitlab-ce-fcba25515321f57e36b9a8f2156d6b72eafb4c14.tar.gz
Commit SHA comes from JSON
Removed page refresh - instead clicking takes to the builds tab
-rw-r--r--app/assets/javascripts/lib/notify.js.coffee18
-rw-r--r--app/assets/javascripts/merge_request_widget.js.coffee56
-rw-r--r--app/controllers/projects/merge_requests_controller.rb3
-rw-r--r--app/views/projects/merge_requests/widget/_show.html.haml15
4 files changed, 49 insertions, 43 deletions
diff --git a/app/assets/javascripts/lib/notify.js.coffee b/app/assets/javascripts/lib/notify.js.coffee
index f28fe8bbc63..bd409faba95 100644
--- a/app/assets/javascripts/lib/notify.js.coffee
+++ b/app/assets/javascripts/lib/notify.js.coffee
@@ -1,7 +1,11 @@
((w) ->
- notifyMe = (message,body, icon) ->
+ notifyPermissions = ->
+ if 'Notification' of window
+ Notification.requestPermission()
+
+ notifyMe = (message, body, icon, onclick) ->
notification = undefined
- opts =
+ opts =
body: body
icon: icon
# Let's check if the browser supports notifications
@@ -10,17 +14,21 @@
else if Notification.permission == 'granted'
# If it's okay let's create a notification
notification = new Notification(message, opts)
+
+ if onclick
+ notification.onclick = onclick
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)
+
+ if onclick
+ notification.onclick = onclick
return
return
w.notify = notifyMe
+ w.notifyPermissions = notifyPermissions
return
) window
-
-if 'Notification' of 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 168de57288b..9afb6a0ce86 100644
--- a/app/assets/javascripts/merge_request_widget.js.coffee
+++ b/app/assets/javascripts/merge_request_widget.js.coffee
@@ -7,9 +7,10 @@ class @MergeRequestWidget
#
constructor: (@opts) ->
- @first = true
+ @firstCICheck = true
modal = $('#modal_merge_info').modal(show: false)
- @getBuildStatus()
+ @getCIStatus()
+ notifyPermissions()
@readyForCICheck = true
# clear the build poller
@@ -39,31 +40,34 @@ class @MergeRequestWidget
else
status
- getBuildStatus: ->
- urlToCiCheck = @opts.url_to_ci_check
- _this = @
- @fetchBuildStatusInterval = setInterval (->
- if not _this.readyForCICheck
- return;
- $.getJSON urlToCiCheck, (data) ->
- _this.readyForCICheck = true
- if _this.first
- _this.first = false
- _this.opts.current_status = data.status
- 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.gitlab_icon)
- setTimeout (->
- Turbolinks.visit(location.href)
- return
- ), 2000
- _this.opts.current_status = data.status
- return
- _this.readyForCICheck = false
- return
+ getCIStatus: ->
+ urlToCICheck = @opts.url_to_ci_check
+ @fetchBuildStatusInterval = setInterval ( =>
+ return if not @readyForCICheck
+ $.getJSON urlToCICheck, (data) =>
+ @readyForCICheck = true
+
+ if @firstCICheck
+ @firstCICheck = false
+ @opts.current_status = data.status
+
+ if data.status isnt @opts.current_status
+ message = @opts.ci_message.replace('{{status}}', @ciLabelForStatus(data.status))
+ message = message.replace('{{sha}}', data.sha)
+
+ notify(
+ "Build #{_this.ciLabelForStatus(data.status)}",
+ message,
+ @opts.gitlab_icon,
+ ->
+ @close()
+ Turbolinks.visit "#{window.location.pathname}/builds"
+ )
+
+ @opts.current_status = data.status
+
+ @readyForCICheck = false
), 5000
getCiStatus: ->
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index e40ec38fbff..2cc94596d2b 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -221,7 +221,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def ci_status
ci_commit = @merge_request.ci_commit
if ci_commit
- status = ci_commit.try(:status)
+ status = ci_commit.status
coverage = ci_commit.try(:coverage)
else
ci_service = @merge_request.source_project.ci_service
@@ -233,6 +233,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
response = {
+ sha: merge_request.last_commit.sha,
status: status,
coverage: coverage
}
diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml
index b5591416a31..8193bb4d180 100644
--- a/app/views/projects/merge_requests/widget/_show.html.haml
+++ b/app/views/projects/merge_requests/widget/_show.html.haml
@@ -14,17 +14,10 @@
check_enable: #{@merge_request.unchecked? ? "true" : "false"},
url_to_ci_check: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
gitlab_icon: "#{asset_path 'gitlab_logo.png'}",
- current_status: ""
+ current_status: "",
+ ci_message: "Build {{status}} for {{sha}}"
};
-
-- if @merge_request.ci_commit
- :javascript
- opts.ci_message = "Build {{status}} for #{@merge_request.ci_commit.sha}";
-- else
- :javascript
- opts.ci_message = "Build {{status}} for #{@merge_request.last_commit.sha}";
-
-:javascript
+
if(typeof merge_request_widget === 'undefined') {
merge_request_widget = new MergeRequestWidget(opts);
- } \ No newline at end of file
+ }