2015-06-11 12:27:03 -04:00
|
|
|
class @MergeRequestWidget
|
|
|
|
# Initialize MergeRequestWidget behavior
|
|
|
|
#
|
|
|
|
# check_enable - Boolean, whether to check automerge status
|
2016-03-18 07:08:03 -04:00
|
|
|
# merge_check_url - String, URL to use to check automerge status
|
|
|
|
# ci_status_url - String, URL to use to check CI status
|
2015-06-11 12:27:03 -04:00
|
|
|
#
|
2016-03-04 18:22:39 -05:00
|
|
|
|
2015-06-11 12:27:03 -04:00
|
|
|
constructor: (@opts) ->
|
2016-03-21 05:54:13 -04:00
|
|
|
$('#modal_merge_info').modal(show: false)
|
2016-03-16 10:31:35 -04:00
|
|
|
@firstCICheck = true
|
2016-05-07 15:12:15 -04:00
|
|
|
@readyForCICheck = false
|
2016-04-22 05:50:04 -04:00
|
|
|
@cancel = false
|
2016-03-21 05:52:38 -04:00
|
|
|
clearInterval @fetchBuildStatusInterval
|
|
|
|
|
2016-04-05 11:18:25 -04:00
|
|
|
@clearEventListeners()
|
|
|
|
@addEventListeners()
|
2016-05-07 15:12:15 -04:00
|
|
|
@getCIStatus(false)
|
2016-03-21 05:52:38 -04:00
|
|
|
@pollCIStatus()
|
|
|
|
notifyPermissions()
|
2015-06-11 12:27:03 -04:00
|
|
|
|
2016-04-05 11:18:25 -04:00
|
|
|
clearEventListeners: ->
|
|
|
|
$(document).off 'page:change.merge_request'
|
|
|
|
|
2016-04-22 05:50:04 -04:00
|
|
|
cancelPolling: ->
|
|
|
|
@cancel = true
|
|
|
|
|
2016-04-05 11:18:25 -04:00
|
|
|
addEventListeners: ->
|
2016-04-22 05:50:04 -04:00
|
|
|
allowedPages = ['show', 'commits', 'builds', 'changes']
|
2016-04-05 11:18:25 -04:00
|
|
|
$(document).on 'page:change.merge_request', =>
|
2016-04-22 05:50:04 -04:00
|
|
|
page = $('body').data('page').split(':').last()
|
|
|
|
if allowedPages.indexOf(page) < 0
|
2016-04-05 11:18:25 -04:00
|
|
|
clearInterval @fetchBuildStatusInterval
|
2016-04-22 05:50:04 -04:00
|
|
|
@cancelPolling()
|
2016-04-05 11:18:25 -04:00
|
|
|
@clearEventListeners()
|
2016-04-06 21:46:12 -04:00
|
|
|
|
2015-11-24 22:41:36 -05:00
|
|
|
mergeInProgress: (deleteSourceBranch = false)->
|
2015-06-11 12:27:03 -04:00
|
|
|
$.ajax
|
|
|
|
type: 'GET'
|
|
|
|
url: $('.merge-request').data('url')
|
|
|
|
success: (data) =>
|
2015-10-01 02:31:48 -04:00
|
|
|
if data.state == "merged"
|
2015-11-24 22:41:36 -05:00
|
|
|
urlSuffix = if deleteSourceBranch then '?delete_source=true' else ''
|
|
|
|
|
2015-12-21 22:59:15 -05:00
|
|
|
window.location.href = window.location.pathname + urlSuffix
|
2015-10-01 02:31:48 -04:00
|
|
|
else if data.merge_error
|
|
|
|
$('.mr-widget-body').html("<h4>" + data.merge_error + "</h4>")
|
|
|
|
else
|
2015-11-24 22:41:36 -05:00
|
|
|
callback = -> merge_request_widget.mergeInProgress(deleteSourceBranch)
|
|
|
|
setTimeout(callback, 2000)
|
2015-06-11 12:27:03 -04:00
|
|
|
dataType: 'json'
|
|
|
|
|
|
|
|
getMergeStatus: ->
|
2016-03-18 07:08:03 -04:00
|
|
|
$.get @opts.merge_check_url, (data) ->
|
2015-06-11 12:27:03 -04:00
|
|
|
$('.mr-state-widget').replaceWith(data)
|
|
|
|
|
2016-01-25 16:20:24 -05:00
|
|
|
ciLabelForStatus: (status) ->
|
2016-07-15 16:08:27 -04:00
|
|
|
switch status
|
|
|
|
when 'success'
|
|
|
|
'passed'
|
|
|
|
when 'success_with_warnings'
|
|
|
|
'passed with warnings'
|
|
|
|
else
|
|
|
|
status
|
2016-01-25 16:20:24 -05:00
|
|
|
|
2016-03-21 05:52:38 -04:00
|
|
|
pollCIStatus: ->
|
2016-03-16 10:31:35 -04:00
|
|
|
@fetchBuildStatusInterval = setInterval ( =>
|
|
|
|
return if not @readyForCICheck
|
2016-03-04 18:22:39 -05:00
|
|
|
|
2016-03-21 05:52:38 -04:00
|
|
|
@getCIStatus(true)
|
|
|
|
|
|
|
|
@readyForCICheck = false
|
2016-04-06 21:46:12 -04:00
|
|
|
), 10000
|
2016-03-21 05:52:38 -04:00
|
|
|
|
|
|
|
getCIStatus: (showNotification) ->
|
|
|
|
_this = @
|
|
|
|
$('.ci-widget-fetching').show()
|
|
|
|
|
|
|
|
$.getJSON @opts.ci_status_url, (data) =>
|
2016-04-22 05:50:04 -04:00
|
|
|
return if @cancel
|
2016-03-21 05:52:38 -04:00
|
|
|
@readyForCICheck = true
|
2016-03-16 10:31:35 -04:00
|
|
|
|
2016-05-04 14:45:12 -04:00
|
|
|
if data.status is ''
|
|
|
|
return
|
2016-04-06 21:46:12 -04:00
|
|
|
|
2016-05-07 15:12:15 -04:00
|
|
|
if @firstCICheck || data.status isnt @opts.ci_status and data.status?
|
2016-05-04 14:45:12 -04:00
|
|
|
@opts.ci_status = data.status
|
2016-03-21 05:52:38 -04:00
|
|
|
@showCIStatus data.status
|
|
|
|
if data.coverage
|
|
|
|
@showCICoverage data.coverage
|
2016-03-16 10:31:35 -04:00
|
|
|
|
2016-05-04 14:45:12 -04:00
|
|
|
# The first check should only update the UI, a notification
|
|
|
|
# should only be displayed on status changes
|
2016-05-07 15:12:15 -04:00
|
|
|
if showNotification and not @firstCICheck
|
2016-04-06 12:04:22 -04:00
|
|
|
status = @ciLabelForStatus(data.status)
|
|
|
|
|
|
|
|
if status is "preparing"
|
|
|
|
title = @opts.ci_title.preparing
|
|
|
|
status = status.charAt(0).toUpperCase() + status.slice(1);
|
|
|
|
message = @opts.ci_message.preparing.replace('{{status}}', status)
|
|
|
|
else
|
|
|
|
title = @opts.ci_title.normal
|
|
|
|
message = @opts.ci_message.normal.replace('{{status}}', status)
|
|
|
|
|
|
|
|
title = title.replace('{{status}}', status)
|
2016-03-16 10:31:35 -04:00
|
|
|
message = message.replace('{{sha}}', data.sha)
|
2016-03-16 10:52:56 -04:00
|
|
|
message = message.replace('{{title}}', data.title)
|
2016-03-16 10:31:35 -04:00
|
|
|
|
|
|
|
notify(
|
2016-04-06 12:04:22 -04:00
|
|
|
title,
|
2016-03-16 10:31:35 -04:00
|
|
|
message,
|
|
|
|
@opts.gitlab_icon,
|
|
|
|
->
|
|
|
|
@close()
|
2016-03-16 10:52:56 -04:00
|
|
|
Turbolinks.visit _this.opts.builds_path
|
2016-03-16 10:31:35 -04:00
|
|
|
)
|
2016-05-07 15:12:15 -04:00
|
|
|
@firstCICheck = false
|
2015-06-11 12:27:03 -04:00
|
|
|
|
2016-03-21 05:52:38 -04:00
|
|
|
showCIStatus: (state) ->
|
2016-05-25 04:59:11 -04:00
|
|
|
return if not state?
|
2015-06-11 12:27:03 -04:00
|
|
|
$('.ci_widget').hide()
|
2016-06-29 13:06:41 -04:00
|
|
|
allowed_states = ["failed", "canceled", "running", "pending", "success", "success_with_warnings", "skipped", "not_found"]
|
2015-06-11 12:27:03 -04:00
|
|
|
if state in allowed_states
|
|
|
|
$('.ci_widget.ci-' + state).show()
|
|
|
|
switch state
|
2015-06-23 06:23:17 -04:00
|
|
|
when "failed", "canceled", "not_found"
|
2015-06-11 12:27:03 -04:00
|
|
|
@setMergeButtonClass('btn-danger')
|
2016-05-19 07:51:15 -04:00
|
|
|
when "running"
|
2015-06-11 12:27:03 -04:00
|
|
|
@setMergeButtonClass('btn-warning')
|
2016-06-29 13:06:41 -04:00
|
|
|
when "success", "success_with_warnings"
|
2016-04-06 09:58:50 -04:00
|
|
|
@setMergeButtonClass('btn-create')
|
2015-06-11 12:27:03 -04:00
|
|
|
else
|
|
|
|
$('.ci_widget.ci-error').show()
|
|
|
|
@setMergeButtonClass('btn-danger')
|
|
|
|
|
2016-03-18 07:08:03 -04:00
|
|
|
showCICoverage: (coverage) ->
|
2015-08-11 08:33:31 -04:00
|
|
|
text = 'Coverage ' + coverage + '%'
|
|
|
|
$('.ci_widget:visible .ci-coverage').text(text)
|
2015-06-11 12:27:03 -04:00
|
|
|
|
|
|
|
setMergeButtonClass: (css_class) ->
|
2016-05-25 04:59:11 -04:00
|
|
|
$('.js-merge-button,.accept-action .dropdown-toggle')
|
2016-04-06 09:58:50 -04:00
|
|
|
.removeClass('btn-danger btn-warning btn-create')
|
|
|
|
.addClass(css_class)
|