Created
October 3, 2020 07:47
-
-
Save codekandis/5b48fe19445d4ee4d2b14985abcaa3ae to your computer and use it in GitHub Desktop.
Replace all issue labels with own templates
This file contains hidden or 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
/** | |
* Open the labels view in your repository. | |
* Open your developer console. | |
* Paste the code below. | |
* Edit your preferred labels. | |
* Execute the code. | |
*/ | |
function request( action, formData ) | |
{ | |
const request = new XMLHttpRequest(); | |
request.open( | |
'POST', | |
action | |
); | |
request.send( formData ); | |
} | |
function deleteAllLabels() | |
{ | |
document | |
.querySelectorAll( 'form.d-inline.js-delete-label' ) | |
.forEach( | |
function ( form ) | |
{ | |
const formData = new FormData(); | |
form | |
.querySelectorAll( 'input' ) | |
.forEach( | |
function ( input ) | |
{ | |
formData.append( | |
input.getAttribute( 'name' ), | |
input.getAttribute( 'value' ) | |
); | |
} | |
); | |
request( | |
form.getAttribute( 'action' ), | |
formData | |
); | |
} | |
); | |
} | |
function createNewLabels( labels ) | |
{ | |
const form = document.querySelector( '#new_label' ); | |
labels.forEach( | |
function ( label ) | |
{ | |
const formData = new FormData; | |
form | |
.querySelectorAll( 'input' ) | |
.forEach( | |
function ( input ) | |
{ | |
formData.append( | |
input.getAttribute( 'name' ), | |
input.getAttribute( 'value' ) | |
); | |
} | |
); | |
formData.append( 'label[name]', label.name ); | |
formData.append( 'label[description]', label.description ); | |
formData.append( 'label[color]', label.color ); | |
request( | |
form.getAttribute( 'action' ), | |
formData | |
); | |
} | |
); | |
} | |
deleteAllLabels(); | |
createNewLabels( | |
[ | |
{ | |
name: 'Label One', | |
description: 'Description One', | |
color: '#000000' | |
}, | |
{ | |
name: 'Label Two', | |
description: 'Description Two', | |
color: '#a0a0a0' | |
} | |
] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment