Create default labels for any GitHub repository
Tags: cli, labeler, github, node
Published: 2020-03-19 09:14:13

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

So did I. Meet [**Labeler**](https://github.com/Zebiano/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](https://developer.github.com/v3/issues/labels/) 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](#interactive-cli) **`-n`**, or by [manually](#manually-adding-labels) 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](https://github.com/Zebiano/Labeler#labelsjson)!

## 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 zebiano/labeler %}

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

![KthxBaii](https://media.giphy.com/media/QM5lHSyFjz1XW/giphy.gif)