Skip to content

Instantly share code, notes, and snippets.

@Ice3man543
Created July 11, 2020 10:25
Show Gist options
  • Save Ice3man543/22570d980200c6190859513593a40ad6 to your computer and use it in GitHub Desktop.
Save Ice3man543/22570d980200c6190859513593a40ad6 to your computer and use it in GitHub Desktop.
Export github labels from https://github.com/<user>/<repo>/issues/labels page
// Forked from https://gist.github.com/MoOx/93c2853fee760f42d97f
// Only change i did was make it return proper color code
var labels = [];
[].slice.call(document.querySelectorAll(".js-label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),
description: element.getAttribute("title"),
// using style.backgroundColor might returns "rgb(...)"
color: element.style.backgroundColor
.substring( 4, element.style.backgroundColor.length - 1 )
.split( ',' )
.reduce( ( hexValue, rgbValue ) => {
return (
hexValue +
Number( rgbValue ).toString( 16 )
.padStart( 2, '0' )
);
}, '' ),
})
})
console.log(JSON.stringify(labels, null, 2))
@Ice3man543
Copy link
Author

Ice3man543 commented Jul 11, 2020

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 );
    }
}

[
  // Labels here
].forEach( label => createOrUpdate( label ) );

@Ice3man543
Copy link
Author

[
  {
    "name": "Priority: Critical",
    "description": "This should be dealt with ASAP. Not fixing this issue would be a serious error.",
    "color": "e11d21"
  },
  {
    "name": "Priority: High",
    "description": "After critical issues are fixed, these should be dealt with before any further issues.",
    "color": "eb6421"
  },
  {
    "name": "Priority: Low",
    "description": "This issue can probably be picked up by anyone looking to contribute to the project, as an entry fix",
    "color": "009800"
  },
  {
    "name": "Priority: Medium",
    "description": "This issue may be useful, and needs some attention.",
    "color": "fbca03"
  },
  {
    "name": "Status: Abandoned",
    "description": "This issue is no longer important to the requestor and no one else has shown an interest in it.",
    "color": "000000"
  },
  {
    "name": "Status: Accepted",
    "description": "It's clear what the subject of the issue is about, and what the resolution should be.",
    "color": "009800"
  },
  {
    "name": "Status: Available",
    "description": "No one has claimed responsibility for resolving this issue",
    "color": "bfe5bf"
  },
  {
    "name": "Status: Blocked",
    "description": "There is some issue that needs to be resolved first.",
    "color": "e11d21"
  },
  {
    "name": "Status: Completed",
    "description": "Nothing further to be done with this issue. Awaiting to be closed.",
    "color": "006a74"
  },
  {
    "name": "Status: In Progress",
    "description": "This issue is being worked on, and has someone assigned.",
    "color": "cccccc"
  },
  {
    "name": "Status: On Hold",
    "description": "Similar to blocked, but is assigned to someone",
    "color": "e11d21"
  },
  {
    "name": "Status: Review Needed",
    "description": "The issue has a PR attached to it which needs to be reviewed",
    "color": "fbca03"
  },
  {
    "name": "Status: Revision Needed",
    "description": "Submitter of PR needs to revise the PR related to the issue.",
    "color": "e11d21"
  },
  {
    "name": "Type: Bug",
    "description": "Inconsistencies or issues which will cause an issue or problem for users or implementors.",
    "color": "e11d21"
  },
  {
    "name": "Type: Discussion",
    "description": "Some ideas need to be planned and disucssed to come to a strategy.",
    "color": "5254bf"
  },
  {
    "name": "Type: Enhancement",
    "description": "Most issues will probably ask for additions or changes.",
    "color": "84b6eb"
  },
  {
    "name": "Type: Maintenance",
    "description": "Updating phrasing or wording to make things clearer or removing ambiguity.",
    "color": "fbca03"
  },
  {
    "name": "Type: Optimization",
    "description": "Increasing the performance/optimization. Not an issue, just something to consider.",
    "color": "e7f49f"
  },
  {
    "name": "Type: Question",
    "description": "A query or seeking clarification on parts of the spec. Probably doesn't need the attention of all.",
    "color": "cc327c"
  }
]

A good default set of labels.

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