Открыть боковую панель
nt_test121
nt_project_9da4a5yt9x4b
Коммиты
becead3f
Не подтверждена
Коммит
becead3f
создал
Авг 13, 2016
по автору
Luke Bennett
Просмотр файлов
Review changes
владелец
03891a62
Изменения
4
Скрыть пробелы
Построчно
Рядом
app/assets/javascripts/merge_request_widget.js
Просмотр файла @
becead3f
...
...
@@ -14,10 +14,7 @@
this
.
opts
=
opts
||
$
(
'
.js-merge-request-widget-options
'
).
data
();
this
.
getInputs
();
this
.
getButtons
(
true
);
if
(
this
.
opts
.
checkStatus
)
{
this
.
getMergeStatus
();
}
if
(
this
.
opts
.
checkStatus
)
this
.
getMergeStatus
();
$
(
'
#modal_merge_info
'
).
modal
({
show
:
false
});
...
...
@@ -51,9 +48,7 @@
this
.
mergeWhenSucceedsButton
=
$
(
'
.merge_when_build_succeeds
'
);
this
.
removeSourceBranchButton
=
$
(
'
.remove_source_branch
'
);
this
.
removeSourceBranchWhenMergedButton
=
$
(
'
.remove_source_branch_when_merged
'
);
if
(
!
skipListeners
)
{
return
this
.
addButtonEventListeners
();
}
if
(
!
skipListeners
)
return
this
.
addButtonEventListeners
();
};
MergeRequestWidget
.
prototype
.
clearEventListeners
=
function
()
{
...
...
@@ -73,85 +68,65 @@
};
MergeRequestWidget
.
prototype
.
addEventListeners
=
function
()
{
var
allowedPages
;
allowedPages
=
[
'
show
'
,
'
commits
'
,
'
builds
'
,
'
pipelines
'
,
'
changes
'
];
return
$
(
document
).
on
(
'
page:change.merge_request
'
,
(
function
(
_this
)
{
return
function
()
{
var
page
;
page
=
$
(
'
body
'
).
data
(
'
page
'
).
split
(
'
:
'
).
last
();
if
(
allowedPages
.
indexOf
(
page
)
<
0
)
{
clearInterval
(
_this
.
fetchBuildStatusInterval
);
_this
.
cancelPolling
();
return
_this
.
clearEventListeners
();
}
};
})(
this
));
var
allowedPages
=
[
'
show
'
,
'
commits
'
,
'
builds
'
,
'
pipelines
'
,
'
changes
'
];
return
$
(
document
).
on
(
'
page:change.merge_request
'
,
(
function
()
{
var
page
=
$
(
'
body
'
).
data
(
'
page
'
).
split
(
'
:
'
).
last
();
if
(
allowedPages
.
indexOf
(
page
)
<
0
)
{
clearInterval
(
this
.
fetchBuildStatusInterval
);
this
.
cancelPolling
();
return
this
.
clearEventListeners
();
}
}).
bind
(
this
));
};
MergeRequestWidget
.
prototype
.
addButtonEventListeners
=
function
()
{
this
.
mergeWhenSucceedsButton
.
on
(
'
click
'
,
(
function
(
_this
)
{
return
function
(
e
)
{
_this
.
mergeWhenSucceedsInput
.
val
(
'
1
'
);
return
_this
.
acceptMergeRequest
(
e
);
};
})(
this
));
this
.
removeSourceBranchWhenMergedButton
.
on
(
'
click
'
,
(
function
(
_this
)
{
return
function
(
e
)
{
_this
.
mergeWhenSucceedsInput
.
val
(
'
1
'
);
return
_this
.
acceptMergeRequest
(
e
,
_this
.
removeSourceBranchWhenMergedButton
.
data
(
'
url
'
));
};
})(
this
));
this
.
acceptMergeRequestButton
.
on
(
'
click
'
,
(
function
(
_this
)
{
return
function
(
e
)
{
return
_this
.
acceptMergeRequest
(
e
);
};
})(
this
));
this
.
cancelMergeOnSuccessButton
.
on
(
'
click
'
,
(
function
(
_this
)
{
return
function
(
e
)
{
return
_this
.
cancelMergeOnSuccess
(
e
);
};
})(
this
));
return
this
.
removeSourceBranchButton
.
on
(
'
click
'
,
(
function
(
_this
)
{
return
function
(
e
)
{
return
_this
.
removeSourceBranch
(
e
);
};
})(
this
));
this
.
mergeWhenSucceedsButton
.
on
(
'
click
'
,
(
function
(
e
)
{
this
.
mergeWhenSucceedsInput
.
val
(
'
1
'
);
return
this
.
acceptMergeRequest
(
e
);
}).
bind
(
this
));
this
.
removeSourceBranchWhenMergedButton
.
on
(
'
click
'
,
(
function
(
e
)
{
this
.
mergeWhenSucceedsInput
.
val
(
'
1
'
);
return
this
.
acceptMergeRequest
(
e
,
this
.
removeSourceBranchWhenMergedButton
.
data
(
'
url
'
));
}).
bind
(
this
));
this
.
acceptMergeRequestButton
.
on
(
'
click
'
,
(
function
(
e
)
{
return
this
.
acceptMergeRequest
(
e
);
}).
bind
(
this
));
this
.
cancelMergeOnSuccessButton
.
on
(
'
click
'
,
(
function
(
e
)
{
return
this
.
cancelMergeOnSuccess
(
e
);
}).
bind
(
this
));
return
this
.
removeSourceBranchButton
.
on
(
'
click
'
,
(
function
(
e
)
{
return
this
.
removeSourceBranch
(
e
);
}).
bind
(
this
));
};
MergeRequestWidget
.
prototype
.
mergeInProgress
=
function
(
deleteSourceBranch
)
{
if
(
deleteSourceBranch
==
null
)
{
deleteSourceBranch
=
false
;
}
if
(
deleteSourceBranch
==
null
)
deleteSourceBranch
=
false
;
return
$
.
ajax
({
type
:
'
GET
'
,
url
:
$
(
'
.merge-request
'
).
data
(
'
url
'
),
dataType
:
'
json
'
,
success
:
(
function
(
_this
)
{
return
function
(
data
)
{
var
urlSuffix
;
if
(
data
.
state
===
"
merged
"
)
{
urlSuffix
=
deleteSourceBranch
?
'
?deleted_source_branch=true
'
:
''
;
return
window
.
location
.
href
=
window
.
location
.
pathname
+
urlSuffix
;
}
else
if
(
data
.
merge_error
)
{
return
_this
.
mergeRequestWidgetBody
.
html
(
"
<h4>
"
+
data
.
merge_error
+
"
</h4>
"
);
}
else
{
return
setTimeout
(
function
()
{
return
_this
.
mergeInProgress
(
deleteSourceBranch
);
},
2000
);
}
};
})(
this
)
success
:
(
function
(
data
)
{
if
(
data
.
state
===
"
merged
"
)
{
var
urlSuffix
=
deleteSourceBranch
?
'
?deleted_source_branch=true
'
:
''
;
return
window
.
location
.
href
=
window
.
location
.
pathname
+
urlSuffix
;
}
else
if
(
data
.
merge_error
)
{
return
this
.
mergeRequestWidgetBody
.
html
(
"
<h4>
"
+
data
.
merge_error
+
"
</h4>
"
);
}
else
{
return
setTimeout
((
function
()
{
return
this
.
mergeInProgress
(
deleteSourceBranch
);
}).
bind
(
this
),
2000
);
}
}).
bind
(
this
)
});
};
MergeRequestWidget
.
prototype
.
getMergeStatus
=
function
()
{
return
$
.
get
(
this
.
opts
.
mergeCheckUrl
,
(
function
(
_this
)
{
return
function
(
data
)
{
_this
.
mergeRequestWidget
.
replaceWith
(
data
);
_this
.
getButtons
();
return
_this
.
getInputs
();
};
})(
this
));
return
$
.
get
(
this
.
opts
.
mergeCheckUrl
,
(
function
(
data
)
{
this
.
mergeRequestWidget
.
replaceWith
(
data
);
this
.
getButtons
();
return
this
.
getInputs
();
}).
bind
(
this
));
};
MergeRequestWidget
.
prototype
.
ciLabelForStatus
=
function
(
status
)
{
...
...
@@ -166,68 +141,50 @@
};
MergeRequestWidget
.
prototype
.
pollCIStatus
=
function
()
{
return
this
.
fetchBuildStatusInterval
=
setInterval
(((
function
(
_this
)
{
return
function
()
{
if
(
!
_this
.
readyForCICheck
)
{
return
;
}
_this
.
getCIStatus
(
true
);
return
_this
.
readyForCICheck
=
false
;
};
})(
this
)),
10000
);
return
this
.
fetchBuildStatusInterval
=
setInterval
((
function
()
{
if
(
!
this
.
readyForCICheck
)
return
;
this
.
getCIStatus
(
true
);
return
this
.
readyForCICheck
=
false
;
}).
bind
(
this
),
10000
);
};
MergeRequestWidget
.
prototype
.
getCIStatus
=
function
(
showNotification
)
{
var
_this
;
_this
=
this
;
$
(
'
.ci-widget-fetching
'
).
show
();
return
$
.
getJSON
(
this
.
opts
.
ciStatusUrl
,
(
function
(
_this
)
{
return
function
(
data
)
{
var
message
,
status
,
title
;
if
(
_this
.
cancel
)
{
return
;
}
_this
.
readyForCICheck
=
true
;
if
(
data
.
status
===
''
)
{
return
;
}
if
(
_this
.
firstCICheck
||
data
.
status
!==
_this
.
opts
.
ciStatus
&&
(
data
.
status
!=
null
))
{
_this
.
opts
.
ciStatus
=
data
.
status
;
_this
.
showCIStatus
(
data
.
status
);
if
(
data
.
coverage
)
{
_this
.
showCICoverage
(
data
.
coverage
);
}
// The first check should only update the UI, a notification
// should only be displayed on status changes
if
(
showNotification
&&
!
_this
.
firstCICheck
)
{
status
=
_this
.
ciLabelForStatus
(
data
.
status
);
if
(
status
===
"
preparing
"
)
{
title
=
_this
.
opts
.
ciTitle
.
preparing
;
status
=
status
.
charAt
(
0
).
toUpperCase
()
+
status
.
slice
(
1
);
message
=
_this
.
opts
.
ciMessage
.
preparing
.
replace
(
'
{{status}}
'
,
status
);
}
else
{
title
=
_this
.
opts
.
ciTitle
.
normal
;
message
=
_this
.
opts
.
ciMessage
.
normal
.
replace
(
'
{{status}}
'
,
status
);
}
title
=
title
.
replace
(
'
{{status}}
'
,
status
);
message
=
message
.
replace
(
'
{{sha}}
'
,
data
.
sha
);
message
=
message
.
replace
(
'
{{title}}
'
,
data
.
title
);
notify
(
title
,
message
,
_this
.
opts
.
gitlabIcon
,
function
()
{
this
.
close
();
return
Turbolinks
.
visit
(
_this
.
opts
.
buildsPath
);
});
return
$
.
getJSON
(
this
.
opts
.
ciStatusUrl
,
(
function
(
data
)
{
var
message
,
status
,
title
;
if
(
this
.
cancel
)
return
;
this
.
readyForCICheck
=
true
;
if
(
data
.
status
===
''
)
return
;
if
(
this
.
firstCICheck
||
data
.
status
!==
this
.
opts
.
ciStatus
&&
(
data
.
status
!=
null
))
{
this
.
opts
.
ciStatus
=
data
.
status
;
this
.
showCIStatus
(
data
.
status
);
if
(
data
.
coverage
)
this
.
showCICoverage
(
data
.
coverage
);
if
(
showNotification
&&
!
this
.
firstCICheck
)
{
status
=
this
.
ciLabelForStatus
(
data
.
status
);
if
(
status
===
"
preparing
"
)
{
title
=
this
.
opts
.
ciTitle
.
preparing
;
status
=
status
.
charAt
(
0
).
toUpperCase
()
+
status
.
slice
(
1
);
message
=
this
.
opts
.
ciMessage
.
preparing
.
replace
(
'
{{status}}
'
,
status
);
}
else
{
title
=
this
.
opts
.
ciTitle
.
normal
;
message
=
this
.
opts
.
ciMessage
.
normal
.
replace
(
'
{{status}}
'
,
status
);
}
return
_this
.
firstCICheck
=
false
;
title
=
title
.
replace
(
'
{{status}}
'
,
status
);
message
=
message
.
replace
(
'
{{sha}}
'
,
data
.
sha
);
message
=
message
.
replace
(
'
{{title}}
'
,
data
.
title
);
notify
(
title
,
message
,
this
.
opts
.
gitlabIcon
,
function
()
{
this
.
close
();
return
Turbolinks
.
visit
(
this
.
opts
.
buildsPath
);
});
}
};
})(
this
));
return
this
.
firstCICheck
=
false
;
}
}).
bind
(
this
));
};
MergeRequestWidget
.
prototype
.
showCIStatus
=
function
(
state
)
{
var
allowed_states
;
if
(
state
==
null
)
{
return
;
}
if
(
state
==
null
)
return
;
$
(
'
.ci_widget
'
).
hide
();
allowed_states
=
[
"
failed
"
,
"
canceled
"
,
"
running
"
,
"
pending
"
,
"
success
"
,
"
success_with_warnings
"
,
"
skipped
"
,
"
not_found
"
];
if
(
indexOf
.
call
(
allowed_states
,
state
)
>=
0
)
{
...
...
@@ -260,9 +217,7 @@
};
MergeRequestWidget
.
prototype
.
acceptMergeRequest
=
function
(
e
,
url
)
{
if
(
e
)
{
e
.
preventDefault
();
}
if
(
e
)
e
.
preventDefault
();
this
.
acceptMergeRequestInput
.
disable
();
this
.
dynamicMergeButton
.
html
(
'
<i class="fa fa-spinner fa-spin"></i> Merge in progress
'
);
return
$
.
ajax
({
...
...
@@ -276,33 +231,27 @@
merge_when_build_succeeds
:
this
.
mergeWhenSucceedsInput
.
val
(),
should_remove_source_branch
:
this
.
removeSourceBranchInput
.
is
(
'
:checked
'
)
?
this
.
removeSourceBranchInput
.
val
()
:
void
0
}
}).
done
((
function
(
_this
)
{
return
function
(
res
)
{
if
(
res
.
merge_in_progress
!=
null
)
{
return
_this
.
mergeInProgress
(
res
.
merge_in_progress
);
}
else
{
_this
.
mergeRequestWidgetBody
.
html
(
res
);
_this
.
getButtons
();
return
_this
.
getInputs
();
}
};
})(
this
));
}).
done
((
function
(
res
)
{
if
(
res
.
merge_in_progress
!=
null
)
{
return
this
.
mergeInProgress
(
res
.
merge_in_progress
);
}
else
{
this
.
mergeRequestWidgetBody
.
html
(
res
);
this
.
getButtons
();
return
this
.
getInputs
();
}
}).
bind
(
this
));
};
MergeRequestWidget
.
prototype
.
cancelMergeOnSuccess
=
function
(
e
)
{
if
(
e
)
{
e
.
preventDefault
();
}
if
(
e
)
e
.
preventDefault
();
return
$
.
ajax
({
method
:
'
POST
'
,
url
:
this
.
opts
.
cancelMergeOnSuccessPath
}).
done
((
function
(
_this
)
{
return
function
(
res
)
{
_this
.
mergeRequestWidgetBody
.
html
(
res
);
_this
.
getButtons
();
return
_this
.
getInputs
();
};
})(
this
));
}).
done
((
function
(
res
)
{
this
.
mergeRequestWidgetBody
.
html
(
res
);
this
.
getButtons
();
return
this
.
getInputs
();
}).
bind
(
this
));
};
MergeRequestWidget
.
prototype
.
removeSourceBranch
=
function
(
e
)
{
...
...
app/controllers/projects/merge_requests_controller.rb
Просмотр файла @
becead3f
...
...
@@ -312,14 +312,12 @@ def merge
# to wait until CI completes to know
unless
@merge_request
.
mergeable?
(
skip_ci_check:
merge_when_build_succeeds_active?
)
@status
=
:failed
render_merge_request_widget_partial
return
return
render_widget
(
@status
)
end
if
params
[
:sha
]
!=
@merge_request
.
diff_head_sha
@status
=
:sha_mismatch
render_merge_request_widget_partial
return
return
render_widget
(
@status
)
end
TodoService
.
new
.
merge_merge_request
(
merge_request
,
current_user
)
...
...
@@ -329,8 +327,7 @@ def merge
if
params
[
:merge_when_build_succeeds
].
present?
unless
@merge_request
.
pipeline
@status
=
:failed
render_merge_request_widget_partial
return
return
render_widget
(
@status
)
end
if
@merge_request
.
pipeline
.
active?
...
...
@@ -350,11 +347,11 @@ def merge
@status
=
:success
end
render_
merge_request_widget_partial
render_
widget
(
@status
)
end
def
render_
merge_request_widget_partial
case
@
status
def
render_
widget
(
status
)
case
status
when
:success
render
json:
{
merge_in_progress:
params
[
:should_remove_source_branch
]
==
'1'
}
when
:merge_when_build_succeeds
...
...
app/helpers/merge_requests_helper.rb
Просмотр файла @
becead3f
...
...
@@ -110,4 +110,29 @@ def merge_request_version_path(project, merge_request, merge_request_diff, start
def
version_index
(
merge_request_diff
)
@merge_request_diffs
.
size
-
@merge_request_diffs
.
index
(
merge_request_diff
)
end
def
widget_options
{
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
),
pipelines_path:
pipelines_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
),
merge_path:
merge_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
),
remove_path:
namespace_project_branch_path
(
@merge_request
.
source_project
.
namespace
,
@merge_request
.
source_project
,
@merge_request
.
source_branch
),
cancel_merge_on_success_path:
cancel_merge_when_build_succeeds_namespace_project_merge_request_path
(
@merge_request
.
target_project
.
namespace
,
@merge_request
.
target_project
,
@merge_request
),
check_status:
(
@merge_request
.
open?
&&
@merge_request
.
unchecked?
?
'true'
:
'false'
)
}
end
end
app/views/projects/merge_requests/widget/_show.html.haml
Просмотр файла @
becead3f
...
...
@@ -7,17 +7,4 @@
-
elsif
@merge_request
.
locked?
=
render
'projects/merge_requests/widget/locked'
.js-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
),
pipelines_path:
pipelines_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
),
merge_path:
merge_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
),
remove_path:
namespace_project_branch_path
(
@merge_request
.
source_project
.
namespace
,
@merge_request
.
source_project
,
@merge_request
.
source_branch
),
cancel_merge_on_success_path:
cancel_merge_when_build_succeeds_namespace_project_merge_request_path
(
@merge_request
.
target_project
.
namespace
,
@merge_request
.
target_project
,
@merge_request
),
check_status:
(
@merge_request
.
open?
&&
@merge_request
.
unchecked?
?
'true'
:
'false'
)
}
}
.js-merge-request-widget-options
{
data:
widget_options
}
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать