Last active
September 7, 2022 09:01
-
-
Save ruizalexandre/a8c361bb2e8ad77fafbf156664ed877e to your computer and use it in GitHub Desktop.
Automatic Github Labels
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
// ------------------------------ | |
// HOW TO USE | |
// ------------------------------ | |
// 0. Delete all (useless) labels | |
// 1. Open the console | |
// 2. Copy and paste code below | |
// 3. Execute code | |
// ------------------------------ | |
function createLabel( label ) { | |
document.querySelector( '.js-new-label-name-input' ).value = label.name; | |
document.querySelector( '.js-new-label-description-input' ).value = label.description; | |
document.querySelector( '.js-new-label-color-input' ).value = '#' + label.color; | |
document.querySelector( '.js-details-target ~ .btn-primary' ).disabled = false; | |
document.querySelector( '.js-details-target ~ .btn-primary' ).click(); | |
} | |
function updateLabel( label ) { | |
let updatedLabel = false; | |
[].slice.call( document.querySelectorAll( '.js-labels-list-item' ) ).forEach( element => { | |
if ( element.querySelector( '.js-label-link' ).textContent.trim() === label.name ) { | |
updatedLabel = true; | |
element.querySelector( '.js-edit-label' ).click(); | |
element.querySelector( '.js-new-label-name-input' ).value = label.name; | |
element.querySelector( '.js-new-label-description-input' ).value = label.description; | |
element.querySelector( '.js-new-label-color-input' ).value = '#' + label.color; | |
element.querySelector( '.js-edit-label-cancel ~ .btn-primary' ).click(); | |
} | |
}); | |
return updatedLabel; | |
} | |
function createOrUpdate( label ) { | |
if ( !updateLabel( label ) ) { | |
createLabel( label ); | |
} | |
} | |
[{ | |
"name": "feature", | |
"description": "New feature", | |
"color": "0366d6" | |
}, { | |
"name": "documentation", | |
"description": "Documentation", | |
"color": "5D4037" | |
}, { | |
"name": "bug", | |
"description": "Bug fixing", | |
"color": "d93f0b" | |
}, { | |
"name": "chore", | |
"description": "Internal task/operation", | |
"color": "008672" | |
}, { | |
"name": "release", | |
"description": "Release package", | |
"color": "424242" | |
}, { | |
"name": "theming", | |
"description": "Theming and global ui improvements", | |
"color": "4f60ad" | |
}, { | |
"name": "test", | |
"description": "Unit, functional, integration, E2E tests", | |
"color": "0e8a16" | |
}, { | |
"name": "to discuss", | |
"description": "Need to discuss about", | |
"color": "CAD180" | |
}, { | |
"name": "refactor", | |
"description": "Refactor", | |
"color": "480b84" | |
}].forEach( label => createOrUpdate( label ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use