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) | |
}); | |
})(); |
@Daemach It should work on a private repository.
Do you have set personal access token ?
[image: image.png]
Giovanni Lovato <[email protected]> 于2019年9月19日周四 下午2:02写道:
… I can't see the checkboxes to select pipelines! GitLab CE 12.2.4
[image: Screenshot 2019-09-19 at 08 00 45]
<https://user-images.githubusercontent.com/851745/65217265-0d596e80-daa3-11e9-973d-351ba600b0e8.png>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/ece7260c776208072afd665b86efc370?email_source=notifications&email_token=AAWLBY7SOZCEUUYBTDH4N3LQKMIYDA5CNFSM4IVMBVT2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFZB6M#gistcomment-3032038>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAWLBY6JB77AIVTAV6D2XATQKMIYDANCNFSM4IVMBVTQ>
.
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
This looks great - how would I use this on a private repository?