Skip to content

Instantly share code, notes, and snippets.

@yu1ec
Last active January 8, 2020 11:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yu1ec/ece7260c776208072afd665b86efc370 to your computer and use it in GitHub Desktop.
Save yu1ec/ece7260c776208072afd665b86efc370 to your computer and use it in GitHub Desktop.
Pipelines Cleaner
// ==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="" />&nbsp;&nbsp;').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}" /> &nbsp;&nbsp;`;
$el.find('.table-section.section-10.commit-link .table-mobile-content').prepend(checkBoxHtml);
});
})
}, 500)
});
})();
@Daemach
Copy link

Daemach commented Sep 10, 2019

This looks great - how would I use this on a private repository?

@theel0ja
Copy link

@Daemach It should work on a private repository.

@yu1ec
Copy link
Author

yu1ec commented Oct 1, 2019 via email

@yu1ec
Copy link
Author

yu1ec commented Jan 8, 2020

I found a bug when looking for the project id, so I used an easier way to get the project id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment