summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke "Jared" Bennett <lbennett@gitlab.com>2016-06-29 18:41:34 +0100
committerLuke "Jared" Bennett <lbennett@gitlab.com>2016-06-30 02:42:26 +0100
commit8e5db1fc3ac9bae9b09d9e8d9bf3db453414ba42 (patch)
treee525f0ab64041f7d515e70e2defe3cef1e3b200a
parent84113d7e725dcf6f9a3945853475f0cede957fec (diff)
downloadgitlab-ce-merge-request-widget-inline-js-demolition.tar.gz
made attribute key changes to tests Attempting to fix mountain of failures
-rw-r--r--app/assets/javascripts/dispatcher.js.coffee1
-rw-r--r--app/assets/javascripts/merge_request_widget.js.coffee35
-rw-r--r--app/views/projects/merge_requests/widget/_show.html.haml36
-rw-r--r--app/views/projects/merge_requests/widget/open/_check.html.haml6
-rw-r--r--spec/javascripts/merge_request_widget_spec.js.coffee37
5 files changed, 50 insertions, 65 deletions
diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee
index 9493a575801..1cb05fbdd6c 100644
--- a/app/assets/javascripts/dispatcher.js.coffee
+++ b/app/assets/javascripts/dispatcher.js.coffee
@@ -51,6 +51,7 @@ class Dispatcher
new ZenMode()
new GLForm($('.release-form'))
when 'projects:merge_requests:show'
+ merge_request_widget = new MergeRequestWidget()
new Diff()
shortcut_handler = new ShortcutsIssuable(true)
new ZenMode()
diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee
index 779f536d9f0..949e59484dd 100644
--- a/app/assets/javascripts/merge_request_widget.js.coffee
+++ b/app/assets/javascripts/merge_request_widget.js.coffee
@@ -1,18 +1,23 @@
class @MergeRequestWidget
# Initialize MergeRequestWidget behavior
#
- # check_enable - Boolean, whether to check automerge status
- # merge_check_url - String, URL to use to check automerge status
+ # checkEnable - Boolean, whether to check automerge status
+ # mergeCheckUrl - String, URL to use to check automerge status
# ci_status_url - String, URL to use to check CI status
#
- constructor: (@opts) ->
+ constructor: (opts) ->
$('#modal_merge_info').modal(show: false)
@firstCICheck = true
@readyForCICheck = false
@cancel = false
clearInterval @fetchBuildStatusInterval
+ @opts = opts || $('.merge-request-widget-options').data()
+ console.log @opts
+
+ @getMergeStatus() if @opts.getMergeStatus
+
@clearEventListeners()
@addEventListeners()
@getCIStatus(false)
@@ -38,7 +43,7 @@ class @MergeRequestWidget
$.ajax
type: 'GET'
url: $('.merge-request').data('url')
- success: (data) =>
+ success: (data) ->
if data.state == "merged"
urlSuffix = if deleteSourceBranch then '?delete_source=true' else ''
@@ -46,12 +51,12 @@ class @MergeRequestWidget
else if data.merge_error
$('.mr-widget-body').html("<h4>" + data.merge_error + "</h4>")
else
- callback = -> merge_request_widget.mergeInProgress(deleteSourceBranch)
+ callback = => @mergeInProgress(deleteSourceBranch)
setTimeout(callback, 2000)
dataType: 'json'
getMergeStatus: ->
- $.get @opts.merge_check_url, (data) ->
+ $.get @opts.mergeCheckUrl, (data) ->
$('.mr-state-widget').replaceWith(data)
ciLabelForStatus: (status) ->
@@ -73,15 +78,15 @@ class @MergeRequestWidget
_this = @
$('.ci-widget-fetching').show()
- $.getJSON @opts.ci_status_url, (data) =>
+ $.getJSON @opts.ciStatusUrl, (data) =>
return if @cancel
@readyForCICheck = true
if data.status is ''
return
- if @firstCICheck || data.status isnt @opts.ci_status and data.status?
- @opts.ci_status = data.status
+ if @firstCICheck || data.status isnt @opts.ciStatus and data.status?
+ @opts.ciStatus = data.status
@showCIStatus data.status
if data.coverage
@showCICoverage data.coverage
@@ -92,12 +97,12 @@ class @MergeRequestWidget
status = @ciLabelForStatus(data.status)
if status is "preparing"
- title = @opts.ci_title.preparing
+ title = @opts.ciTitle.preparing
status = status.charAt(0).toUpperCase() + status.slice(1);
- message = @opts.ci_message.preparing.replace('{{status}}', status)
+ message = @opts.ciMessage.preparing.replace('{{status}}', status)
else
- title = @opts.ci_title.normal
- message = @opts.ci_message.normal.replace('{{status}}', status)
+ title = @opts.ciTitle.normal
+ message = @opts.ciMessage.normal.replace('{{status}}', status)
title = title.replace('{{status}}', status)
message = message.replace('{{sha}}', data.sha)
@@ -106,10 +111,10 @@ class @MergeRequestWidget
notify(
title,
message,
- @opts.gitlab_icon,
+ @opts.gitlabIcon,
->
@close()
- Turbolinks.visit _this.opts.builds_path
+ Turbolinks.visit _this.opts.buildsPath
)
@firstCICheck = false
diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml
index d9efe81701f..7063c716c57 100644
--- a/app/views/projects/merge_requests/widget/_show.html.haml
+++ b/app/views/projects/merge_requests/widget/_show.html.haml
@@ -7,29 +7,13 @@
- elsif @merge_request.locked?
= render 'projects/merge_requests/widget/locked'
-:javascript
- var opts = {
- merge_check_url: "#{merge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
- check_enable: #{@merge_request.unchecked? ? "true" : "false"},
- ci_status_url: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
- gitlab_icon: "#{asset_path 'gitlab_logo.png'}",
- ci_status: "#{@merge_request.pipeline ? @merge_request.pipeline.status : ''}",
- ci_message: {
- normal: "Build {{status}} for \"{{title}}\"",
- preparing: "{{status}} build for \"{{title}}\""
- },
- 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)}"
- };
-
- 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-options{ data: { :merge_check_url => merge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request),
+ :check_enable => (@merge_request.unchecked? ? true : false),
+ :ci_status_url => ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request),
+ :gitlab_icon => asset_path('gitlab_logo.png'),
+ :ci_status => (@merge_request.pipeline ? @merge_request.pipeline.status : ''),
+ :ci_message => { :normal => 'Build {{status}} for "{{title}}"', :preparing => '{{status}} build for "{{title}}"' },
+ :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),
+ :get_merge_status => (@merge_request.open? && @merge_request.unchecked?).to_s } }
diff --git a/app/views/projects/merge_requests/widget/open/_check.html.haml b/app/views/projects/merge_requests/widget/open/_check.html.haml
index e16878ba513..1006bcd8381 100644
--- a/app/views/projects/merge_requests/widget/open/_check.html.haml
+++ b/app/views/projects/merge_requests/widget/open/_check.html.haml
@@ -1,9 +1,3 @@
%strong
= icon("spinner spin")
Checking ability to merge automatically&hellip;
-
-:javascript
- $(function() {
- merge_request_widget.getMergeStatus();
- });
-
diff --git a/spec/javascripts/merge_request_widget_spec.js.coffee b/spec/javascripts/merge_request_widget_spec.js.coffee
index 92b7eeb1116..647c3b378a5 100644
--- a/spec/javascripts/merge_request_widget_spec.js.coffee
+++ b/spec/javascripts/merge_request_widget_spec.js.coffee
@@ -3,24 +3,25 @@
describe 'MergeRequestWidget', ->
beforeEach ->
- window.notifyPermissions = () ->
- window.notify = () ->
- @opts = {
- ci_status_url:"http://sampledomain.local/ci/getstatus",
- ci_status:"",
- ci_message: {
- normal: "Build {{status}} for \"{{title}}\"",
- preparing: "{{status}} build for \"{{title}}\""
- },
- ci_title: {
- preparing: "{{status}} build",
- normal: "Build {{status}}"
- },
- gitlab_icon:"gitlab_logo.png",
- builds_path:"http://sampledomain.local/sampleBuildsPath"
- }
- @class = new MergeRequestWidget(@opts)
- @ciStatusData = {"title":"Sample MR title","sha":"12a34bc5","status":"success","coverage":98}
+ window.notifyPermissions = ->
+ window.notify = ->
+ @opts =
+ ciStatusUrl: 'http://sampledomain.local/ci/getstatus'
+ ciStatus:''
+ ciMessage:
+ normal: 'Build {{status}} for "{{title}}"'
+ preparing: '{{status}} build for "{{title}}"'
+ ciTitle:
+ preparing: '{{status}} build'
+ normal: 'Build {{status}}'
+ gitlabIcon:'gitlab_logo.png'
+ buildsPath:'http://sampledomain.local/sampleBuildsPath'
+ @class = new MergeRequestWidget @opts
+ @ciStatusData =
+ title:'Sample MR title'
+ sha:'12a34bc5'
+ status:'success'
+ coverage:98
describe 'getCIStatus', ->
beforeEach ->