Last active
January 8, 2020 11:35
-
-
Save yu1ec/ece7260c776208072afd665b86efc370 to your computer and use it in GitHub Desktop.
Pipelines Cleaner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Pipelines Cleaner | |
// @namespace https://your-domain/ | |
// @version 0.1 | |
// @description Gitlab CI/CD Pipelines Cleaner | |
// @author ecareyu | |
// @match *://your-domain/*/*/pipelines | |
// @require https://code.jquery.com/jquery-2.2.4.min.js | |
// @run-at document-end | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// @see:https://docs.gitlab.com/ee/api/pipelines.html | |
$(function () { | |
let PRIVATE_TOKEN = 'your personal access token' | |
$.ajaxSetup({ | |
'dataType': 'json', | |
'headers': { | |
'PRIVATE-TOKEN': PRIVATE_TOKEN | |
} | |
}); | |
function destroyPipelines() { | |
let $this = $(this); | |
if (!confirm('Are your sure?')) { | |
return false; | |
} | |
$('input[name="pipelines[]"]:checked').each(function (index, elem) { | |
let $elem = $(elem) | |
let projectId = $elem.data('projectId'); | |
let pipelineId = $elem.val(); | |
$.ajax({ | |
'url': `/api/v4/projects/${projectId}/pipelines/${pipelineId}`, | |
'type': 'DELETE', | |
'success': function () { | |
$(`#pipeline-${pipelineId}`).remove(); | |
} | |
}); | |
}); | |
} | |
function toggleCheckbox() { | |
let $obj = $(this); | |
$('input[name="pipelines[]"]').prop('checked', $obj.prop('checked')); | |
} | |
setTimeout(function () { | |
let projectId = $('body').data('projectId') | |
let $btnEl = $('<a href="javascript:;" class="btn btn-danger" variant="success">Delete</a>').on('click', destroyPipelines) | |
$('.nav-controls').append($btnEl); | |
let $columnEl = $('<input type="checkbox" value="" /> ').on('click', toggleCheckbox); | |
$('.ci-table .table-section.section-10.js-pipeline-status').prepend($columnEl); | |
let API_PIPELINES = `/api/v4/projects/${projectId}/pipelines`; | |
$.get(API_PIPELINES, function (pipelines) { | |
pipelines.forEach(function (pipeline, index) { | |
let $el = $('.commit.gl-responsive-table-row').eq(index) | |
$el.attr('id', `pipeline-${pipeline.id}`) | |
let checkBoxHtml = `<input name="pipelines[]" type="checkbox" data-project-id="${projectId}" value="${pipeline.id}" /> `; | |
$el.find('.table-section.section-10.commit-link .table-mobile-content').prepend(checkBoxHtml); | |
}); | |
}) | |
}, 500) | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found a bug when looking for the project id, so I used an easier way to get the project id.