Skip to content

Instantly share code, notes, and snippets.

@andersy005
Forked from cdlhub/import-github-labels.md
Created July 31, 2019 20:45
Show Gist options
  • Save andersy005/9cd264068c03581ca24d7d73961ba87a to your computer and use it in GitHub Desktop.
Save andersy005/9cd264068c03581ca24d7d73961ba87a to your computer and use it in GitHub Desktop.
Script to import labels to Github issue page

Import GitHub labels

Based on: https://gist.github.com/Isaddo/7efebcb673a0957b9c6f07cd14826ea4

  1. Go on your labels page https://github.com/user/repo/labels
  2. Paste this script in your console.
  3. Press Enter.
[
  {
    "name": "0 - blocker",
    "color": "b60205",
    "description": "High priority, needs immediate response"
  },
  {
    "name": "1 - urgent",
    "color": "d93f0b",
    "description": "Urgent priority"
  },
  {
    "name": "2 - normal",
    "color": "e99695",
    "description": "Normal priority"
  },
  {
    "name": "3 - low",
    "color": "f9d0c4",
    "description": "Low priority"
  },
  {
    "name": "bug",
    "color": "e27461",
    "description": "Something isn't working"
  },
  {
    "name": "enhancement",
    "color": "fbca04",
    "description": "New feature or request"
  },
  {
    "name": "on hold",
    "color": "e9e9e9",
    "description": "This will be worked on when situation changes"
  },
  {
    "name": "in progress",
    "color": "5cc429",
    "description": "Someone is working on this"
  }
].forEach(function(label) {
  addLabel(label)
})

function updateLabel (label) {
  var flag = false;
  [].slice.call(document.querySelectorAll(".labels-list-item"))
  .forEach(function(element) {
    if (element.querySelector('.label-link').textContent.trim() === label.name) {
      flag = 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 flag
}

function addNewLabel (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 addLabel (label) {
  if (!updateLabel(label)) addNewLabel(label)
}

You'll get the following labels:

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