Created CLI Tool that Creates/Remove GitHub Labels

0xkoji - Aug 31 '21 - - Dev Community

CLI Tool

Recently I read articles about GitHub labels for issues. I recommend you to check them out. (Sorry one of them is Japanese only)

How we organize GitHub issues: A simple styleguide for tagging

https://robinpowered.com/blog/best-practice-system-for-organizing-and-tagging-github-issues

Sane GitHub Labels

https://medium.com/@dave_lunny/sane-github-labels-c5d2e6004b63

GitHub Labels that are logical, colorful and sensible

https://seantrane.com/posts/logical-colorful-github-labels-18230/

GitHub Issuesのラベルを作り直す+Projectのかんばんを自動化

https://qiita.com/willow-micro/items/51eeb3efe5b4192a4abd

I think when you use the GitHub issues, probably many of you need to add/change labels. Actually, the default labels are well... not ideal. Generally, I add some new labels manually after I push the initial commit. That means I go to the issue board and add a label.
After reading the articles, I thought preparing labels that articles mentioned would be ↓

I checked GitHub API to create labels. Fortunately, there is a Labels API.
https://docs.github.com/en/rest/reference/issues#labels

The usage of the Labels API is very simple. We just need to pass a couple of parameters and create an instance with GitHub personal token since there is a JS library “octokit” that allows us to use the API easily.

GitHub logo octokit / core.js

Extendable client for GitHub's REST & GraphQL APIs

core.js

Extendable client for GitHub's REST & GraphQL APIs

@latest Build Status

If you need a minimalistic library to utilize GitHub's REST API and GraphQL API which you can extend with plugins as needed, then @octokit/core is a great starting point.

If you don't need the Plugin API then using @octokit/request or @octokit/graphql directly is a good alternative.

Usage

Browsers Load @octokit/core directly from esm.sh
<script type="module">
  import { Octokit } from "https://esm.sh/@octokit/core";
</script>
Enter fullscreen mode Exit fullscreen mode
Node

Install with npm install @octokit/core

import { Octokit } from "@octokit/core";
Enter fullscreen mode Exit fullscreen mode

As we use conditional exports, you will need to adapt your tsconfig.json. See the TypeScript docs on package.json "exports".

REST API example

// Create a personal access token at https://github.com/settings/tokens/new?scopes=repo
const octokit = new
Enter fullscreen mode Exit fullscreen mode

I wrote a simple application with Nodejs and Typescript.
I used a typescript-starter to save time for setup. typescript-starter is useful, but it was a little bit too much for this since the ESlint configuration helped me to detect issues but at the same time prevent running the script quickly lol.

GitHub logo bitjson / typescript-starter

Quickly create and configure a new library or Node.js project

typescript-starter dark logotypescript-starter logo

NPM version Codecov CircleCI Travis AppVeyor GitHub stars

demo of the typescript-starter command-line interface

Start Now

Run one simple command to install and use the interactive project generator. You'll need Node v10 or later.

npx typescript-starter
Enter fullscreen mode Exit fullscreen mode

The interactive CLI will help you create and configure your project automatically.

Since this repo includes the CLI and it's tests, you'll only need to fork or clone this project if you want to contribute. If you find this project useful, please consider leaving a star so others can find it. Thanks!

Features





The script’s repo is here.

GitHub logo koji / github-label-manager

Simple CLI tool to create/delete labels with GitHub Labels API

Currently working on making this scripts into a CLI tool

github label manager

Simple CLI tool to create/delete labels with GitHub Labels API.

Screen Shot 2021-08-23 at 1 02 53 AM

label-manager.mov

Labels API

https://docs.github.com/en/rest/reference/issues#labels

label data format

// label format
{
  "id": 3218144327,
  "node_id": "MDU6TGFiZWwzMjE4MTQ0MzI3",
  "url": "https://api.github.com/repos/koji/frontend-tools/labels/wontfix",
  "name": "wontfix",
  "color": "ffffff",
  "default": true,
  "description": "This will not be worked on"
}
Enter fullscreen mode Exit fullscreen mode

What this script can do is the below.

  1. Create a single label on a specific repo
  2. Create multiple labels on a specific repo
  3. Delete a single label from a specific repo
  4. Delete all labels from a specific repo

Requirement: Personal Token about repo

You can generate a token here.

What you will need to input

  1. Operation 0: Cancel (terminate the process) 1: Create a single label on a specific repo 2: Create…

This Nodejs script will ask you 3 things initially. GitHub personal token(wont’ keep it anywhere), GitHub id, and a target repo name.

It will offer 4 simple functionalities to the repo you set.

Create a label

You will need to pass a new label name, label color(hex code without #), and label description as parameters. Then create a new label on your repo.

Create labels

This function will create 29 labels which are set as constant here
If you change the constant, you can update labels easily.

Delete a label

This function will remove a tag from your repo. It requires a label name as a parameter. (In the future, this should get labels list and allow to select a label/labels by multi-select)

Delete all labels

This will delete all labels from your repo. First, get all labels' names from the repo and pass them as a parameter. The process is the same as “Delete a label”

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .