jwodder / labelmaker

Create & enforce sets of labels in GitHub repositories
MIT License
2 stars 0 forks source link
available-on-crates-io github github-labels github-repository-management rust

Project Status: Active – The project has reached a stable, usable state and is being actively developed. CI Status codecov.io Minimum Supported Rust Version MIT License

GitHub | crates.io | Issues | Changelog

labelmaker is a Rust program for batch creation of labels in GitHub repositories, including updating and/or renaming existing labels to meet your specifications. Simply describe your desired labels in a configuration file and point labelmaker in the direction of your repositories.

Installation

In order to install labelmaker, you first need to have Rust and Cargo installed. You can then build the latest release of labelmaker and install it in ~/.cargo/bin by running:

cargo install labelmaker

Usage

labelmaker [<global options>] <subcommand> ...

The labelmaker command has the following subcommands, each detailed below:

Each subcommand takes an argument or option for indicating what GitHub repositories to operate on. A repository can be specified in the form OWNER/NAME (or, when OWNER is the authenticated user, just NAME) or as a GitHub repository URL. If no repository is supplied, then the current directory must belong to a Git repository whose origin remote points to a GitHub repository; labelmaker will operate on this remote repository.

Global Options

Authentication

labelmaker requires a GitHub access token with appropriate permissions in order to run. Specify the token via the GH_TOKEN or GITHUB_TOKEN environment variable or store it with the gh command.

Note that, if gh has stored the token in a system keyring, you may be prompted to unlock the keyring.

labelmaker apply

labelmaker [<global options>] apply [<options>] <config-file> [<repository> ...]

labelmaker apply takes a path to a configuration file (See "Configuration File" below) and a list of GitHub repositories as arguments. It then creates and/or updates the labels of each repository based on the specification in the configuration file.

For each repository, all changes are calculated before modifying anything, so if an error occurs based on the state of the configuration file and/or current repository labels, it will be caught before any changes to the repository are made.

Options

labelmaker fetch

labelmaker [<global options>] fetch [<options>] [<repository>]

labelmaker fetch fetches the labels currently defined for the given GitHub repository and dumps them as a labelmaker configuration file, ready for input into labelmaker apply.

The generated configuration file lists only label names, colors, and descriptions, no defaults, aside from the file-wide color setting having its default value included for use as a reference.

Options

labelmaker make

labelmaker [<global options>] make [<options>] <label-name>

labelmaker make creates or updates the label with the given name in a GitHub repository, the same as if labelmaker apply had been run on that repository with a configuration profile containing a single label entry.

Options

Configuration File

labelmaker's configuration file may be written in JSON, JSON5, TOML, or YAML; the file type is determined automatically based on the file extension. The file contains a top-level mapping with the following fields:

Example Configuration File

The following TOML configuration shows the default GitHub labels as of 2023-10-18, along with the default value of the color setting:

[defaults]
color = [
    "0052cc",
    "006b75",
    "0e8a16",
    "1d76db",
    "5319e7",
    "b60205",
    "bfd4f2",
    "bfdadc",
    "c2e0c6",
    "c5def5",
    "d4c5f9",
    "d93f0b",
    "e99695",
    "f9d0c4",
    "fbca04",
    "fef2c0",
]

[[profiles.default.labels]]
name = "bug"
color = "d73a4a"
description = "Something isn't working"

[[profiles.default.labels]]
name = "documentation"
color = "0075ca"
description = "Improvements or additions to documentation"

[[profiles.default.labels]]
name = "duplicate"
color = "cfd3d7"
description = "This issue or pull request already exists"

[[profiles.default.labels]]
name = "enhancement"
color = "a2eeef"
description = "New feature or request"

[[profiles.default.labels]]
name = "good first issue"
color = "7057ff"
description = "Good for newcomers"

[[profiles.default.labels]]
name = "help wanted"
color = "008672"
description = "Extra attention is needed"

[[profiles.default.labels]]
name = "invalid"
color = "e4e669"
description = "This doesn't seem right"

[[profiles.default.labels]]
name = "question"
color = "d876e3"
description = "Further information is requested"

[[profiles.default.labels]]
name = "wontfix"
color = "ffffff"
description = "This will not be worked on"

That same configuration, in YAML:

defaults:
  color:
    - "0052cc"
    - "006b75"
    - "0e8a16"
    - "1d76db"
    - "5319e7"
    - "b60205"
    - "bfd4f2"
    - "bfdadc"
    - "c2e0c6"
    - "c5def5"
    - "d4c5f9"
    - "d93f0b"
    - "e99695"
    - "f9d0c4"
    - "fbca04"
    - "fef2c0"

profiles:
  default:
    labels:
      - name: bug
        color: "d73a4a"
        description: Something isn't working

      - name: documentation
        color: "0075ca"
        description: Improvements or additions to documentation

      - name: duplicate
        color: "cfd3d7"
        description: This issue or pull request already exists

      - name: enhancement
        color: "a2eeef"
        description: New feature or request

      - name: good first issue
        color: "7057ff"
        description: Good for newcomers

      - name: help wanted
        color: "008672"
        description: Extra attention is needed

      - name: invalid
        color: "e4e669"
        description: This doesn't seem right

      - name: question
        color: "d876e3"
        description: Further information is requested

      - name: wontfix
        color: "ffffff"
        description: This will not be worked on