Skip to content

Instantly share code, notes, and snippets.

@LennyPenny
Last active October 9, 2019 12:39
Show Gist options
  • Save LennyPenny/a0419284b7bea8f35620e238fefb3553 to your computer and use it in GitHub Desktop.
Save LennyPenny/a0419284b7bea8f35620e238fefb3553 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name GitLab - auto check 'delete source branch'
// @namespace https://gist.github.com/LennyPenny
// @version 0.5
// @description Auto checks the "delete source branch" option when creating merge requests
// @author Lennart Bernhardt
// @updateURL https://gist.github.com/LennyPenny/a0419284b7bea8f35620e238fefb3553/raw/gitLabAutoDelete.user.js
// @downloadURL https://gist.github.com/LennyPenny/a0419284b7bea8f35620e238fefb3553/raw/gitLabAutoDelete.user.js
// @match https://*/*/merge_requests/new*
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @grant GM_log
// ==/UserScript==
(function() {
'use strict';
var waitForEl = function(selector, callback) {
if ($(selector).length) {
callback();
} else {
setTimeout(function() {
waitForEl(selector, callback);
}, 100);
}
}
function checkThem(nodes) {
nodes.forEach(function(n) { n.checked = true })
}
waitForEl("#select2-chosen-2", function() {
let sourceBranch = document.querySelector("#select2-chosen-2").textContent;
if (sourceBranch == "master" || sourceBranch == "testing" || sourceBranch == "test" || sourceBranch == "production" || sourceBranch == "prod") {
return;
}
let sel = "#merge_request_force_remove_source_branch";
checkThem([].slice.call(document.querySelectorAll(sel)));
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment