DEV Community

Sebas Barros
Sebas Barros

Posted on

Create default labels for any GitHub repository

Ever wanted to have your own set of default labels when creating a new GitHub repository?

So did I. Meet Labeler, your new label manager!

What does it do?

Glad you asked. It stores your custom labels in a .json file, and uploads them to any repository, so long permissions are granted.

How though?

Simple: labeler makes use of the GitHub API in order to successfully take actions in repositories. First, a GET request is made for all labels stored in the repository. Next, a DELETE request for them all, and lastly a POST request to save your custom labels. Easy right?

Stop waffling, show me some commands!

Yes Sir!

labeler -t [TOKEN] -o [OWNER] -r [REPOSITORY] -du

Specify the token -t, owner -o and repository -r. Delete -d every label in the repo, and upload -u your custom ones.

Euw, that's ugly.

I know, I know... There's no need to hurt my feelings like that.

You see, labeler also has a flag meant to store things for you. I introduce: -c

The glorious Config

Since the token and owner usually don't change, I've implemented a way to store and set them as default when not specified through flags.

Running labeler -c will open an interactive CLI, asking which of the following you want to save:

  • Token
  • Owner
  • Repository

I recommend saving token and owner as they rarely change.

This way, the long Euw that's ugly command from before gets reduced to a simpler labeler -dur [REPOSITORY].

Cool! How do I add new labels though?

Good question. You have two options: either by using the interactive CLI -n, or by manually editing the .json file.

Interactive CLI

By running labeler -n, you'll be greeted with 3 input fields:

  • Name
  • Description
  • Color

Pretty self explanatory. Name of label, an optional description and a color in Hex format. Add as many labels as you want, and exit with Ctrl+C.

Manually adding labels

Don't fancy using the CLI? No prob. Run labeler -p to get the full path to the .json file and edit it to your liking!

Any more tips?

Tip #1: Use the -f flag to ignore user confirmation. Deleting every label from the wrong repository is most likely something you don't fancy doing, which is why you get asked to confirm the operation. But if you're a brave one, use labeler -fdur [REPOSITORY]. -f works with any type of confirmation.

Tip #2: If you want to create new labels, but start from a fresh file (instead of appending to the default labels), use labeler -en to clean out every label before creating new ones!

Tip #3: If for some reason you think the labels file is screwed up, don't worry. -R to the rescue! Resets your labels to the default ones.

K thx baii

That's about it! I hope this tool will be of use to some of you at least. There's a more in-depth (and a bit more serious) info over at the GitHub repo if needed.

GitHub logo Zebiano / Labeler

Easily manage default labels in GitHub repositories.

   __       _          _
  / /  __ _| |__   ___| | ___ _ __
 / /  / _` | '_ \ / _ \ |/ _ \ '__|
/ /__| (_| | |_) |  __/ |  __/ |   
\____/\__,_|_.__/ \___|_|\___|_|   
    

Easily manage default labels in GitHub repositories

Why?

Because I was sick of always deleting the default labels and uploading my own ones.

How?

By storing custom labels in a labels.json file, deleting the default ones from the repository and uploading those from said file.

Installation

npm install --global labeler

Usage

NAME
labeler - Label manager for GitHub repositories.

SYNOPSIS
labeler [OPTIONS]

DESCRIPTION
Create custom labels on GitHub repositories automatically.
This CLI helps you organize your GitHub labels by storing them in a labels.json file. You can add new labels through the CLI with the -n flag.
Whenever you create a new repository, instead of manually uploading your labels, use this

…




Thank you for taking your time to read my first article of my life. Have a nice and safe day!

KthxBaii

Top comments (0)