An open API service indexing awesome lists of open source software.

https://github.com/bskinn/repo-label-creator

Tool to automatically create a suite of labels on a GitHub repository
https://github.com/bskinn/repo-label-creator

Last synced: 11 days ago
JSON representation

Tool to automatically create a suite of labels on a GitHub repository

Awesome Lists containing this project

README

        

# repo-label-creator: Automatically create custom issue/PR labels in a GitHub repository

**Want a quick way to create a bunch of standard labels in a GitHub repo?**

**You want `repo-label-creator`!**

Get the labels you need in a few steps:

1. Configure a GitHub personal access token with repo permissions & set it up in
your terminal as the `GITHUB_PAT` environment variable.
2. Clone this repo.
3. Create a virtual environment (Python 3.11+), activate, and
`python -m pip install -r requirements.txt`.
4. Edit `labels.json` to define the labels you want to create.
5. Run `python create_labels.py //`. A GitHub personal access
token with appropriate permissions must be defined in the terminal environment
in the `GITHUB_PAT` variable, and the script should be run using a virtual
environment that's had `python -m pip install -r requirements.txt` run inside
it.

The CLI is implemented with `argparse`, and offers a couple of configuration
flags centered around the deletion of the default labels that GitHub applies to
new repositories:

```
$ python create_labels.py -h
usage: create_labels.py [-h] [--delete-default | --delete-only] repo

Utility to auto-apply a standard set of GitHub issue labels

positional arguments:
repo owner/repo to apply labels to, as '/'

options:
-h, --help show this help message and exit
--delete-default Also delete the GitHub-default labels, if they exist
--delete-only Delete any default GitHub labels without adding new ones
```

As noted above, currently the `labels.json` file location is hardcoded. Comment
on [#2] if you'd like to be able to point to a different location.

### `labels.json` Schema

Expressed (approximately) as dataclasses, the schema for `labels.json` is:

```
@dataclass
class Label:
icon: str
name: str
text: str | None

@dataclass
class Category:
name: str
color: str # Must be RGB hex without the leading '#'
labels: list[Label]

@dataclass
class LabelsJSON:
(root): list[Category]
```

### Internals

GitHub exposes an [API] for listing, retrieving, creating, updating, and
deleting labels from a repository. All interactions with the labels list of the
target repository are achieved using `requests` calls to this API.

[#2]: https://github.com/bskinn/repo-label-creator/issues/2
[#5]: https://github.com/bskinn/repo-label-creator/issues/5
[api]: https://docs.github.com/en/rest/issues/labels?apiVersion=2022-11-28#list-labels-for-a-repository
[diataxis]: https://diataxis.fr
[labs site]: https://labs.quansight.org
[labs site repo]: https://github.com/Quansight/Quansight-website
[labs site labels]: https://github.com/Quansight/Quansight-website/labels
[open a new ticket]: https://github.com/bskinn/repo-label-creator/issues/new
[own labels]: https://github.com/bskinn/repo-label-creator/labels
[Tania Allard]: https://github.com/trallard