Skip to content

kubecub/github-label-syncer

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

⭐️ sync labels between repos and org. ⭐️

🧩 Awesome features

This document discusses the development of a Go language actions that synchronizes labels on GitHub repositories. This actions is not limited to synchronizing labels on your own repository, but can also retrieve all of the API objects of a target repository, which can then be saved to a YAML file or synchronized to your own GitHub project.

Labels are an important way of organizing and categorizing issues and pull requests on GitHub. They allow you to quickly and easily identify the status, priority, and type of each issue or pull request.

To retrieve the API objects of a GitHub project's labels, you can use the following URLs:

  • To retrieve the first page of objects: https://api.github.com/repos/<owner>/<repo>/labels?page=1&sort=name-asc
  • To retrieve all objects: https://api.github.com/repos/<owner>/<repo>/labels?per_page=100&page=1&sort=name-asc

Simply replace <owner> and <repo> with the owner and repository name, respectively. These URLs can be used to retrieve all of the labels associated with a project, which can then be synchronized or saved as needed.

github-label-syncer is a tool to sync labels between repos and org. The main features are:

  • Feel free to pick a remote repository and fetch all its labels to a local yaml, table AND json
  • Feel free to pick a remote repository and sync all of its labels to your desired project repository
  • Sync labels across repositories according to configuration
  • Create, update and delete labels
  • Dry run to preview which labels would be created, updated or deleted
  • Handle label collisions by renaming or skipping existing labels
  • Support labeling pull requests and issues

Labels denger: The labels are designed semantic and standard. We provide labels for priority, type, status etc. You can refer to the label doc to get more info.

**github actions

🛫 Quick start

Note: You can get started quickly with github-label-syncer.

📦 Installation

git clone https://github.com/kubecub/github-label-syncer/release syncer && export syncer=$(pwd)/syncer && cd $syncer && make

Install from github release

Install from GitHub Releases

Work with Makefile

❯ make help    # show help
❯ make build   # build binary exporter and syncerecho 'export PATH=$PATH:/path/to/_output/platforms/linux/amd64/' | tee -a ~/.zshrc;source ~/.zshrc

Use Github-Label-Syncer

You can set your own GITHUB_TOKEN via env or via the export GITHUB_TOKEN environment variable, or use one of the default tokens we provide, which is TOEKN for our free automated 🤖 robot

❯ ./_output/bin/platforms/linux/amd64/exporter --help
usage: exporter [<flags>] <owner> <repo>


Flags:
      --[no-]help    Show context-sensitive help (also try --help-long and --help-man).
  -y, --[no-]yaml    Use the YAML format.
  -j, --[no-]json    Use the JSON format.
  -t, --[no-]table   Use the table format.
  -x, --[no-]xml     Use the XML format.
      --[no-]toml    Use the TOML format.
      --[no-]ini     Use the INI format.
      --[no-]csv     Use the CSV format.
  -f, --file=FILE    Export labels to file.
      --token=TOKEN  GitHub token. ($GITHUB_TOKEN)

Args:
  <owner>  Owner of the repository.
  <repo>   Repository whose wanted labels.

❯ export GITHUB_TOKEN="ghp_****************************************0z"
❯ exporter kubecub log --json | jq
[
  {
    "name": "major version",
    "description": "Automatically create a new major version tag after PR is merged",
    "color": "1E8DE7"
  },
  {
    "name": "merge when passing",
    "description": "Merge the PR automatically once all status checks have passed",
    "color": "FF851B"
  },
  {
    "name": "minor version",
    "description": "Automatically create a new minor version tag after PR is merged",
    "color": "6EBAF7"
  },
  {
    "name": "patch version",
    "description": "Automatically create a new patch version tag after PR is merged",
    "color": "99cef9"
  }
]

❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes kubernetes --yaml -f ./_output/tmp/kubernetes_labels.yaml
❯ tree _output/
root@kubecub# tree _output/
_output/
├── bin
│   └── platforms
│       └── linux
│           └── amd64
│               ├── exporter
│               ├── merged-binary
│               └── syncer
├── tmp
│   └── kubernetes_labels.yaml
└── tools
    ├── addlicense
    ├── git-chglog
    ├── github-release
    ├── go-gitlint
    └── gsemver

❯ ./syncer --help

labels template

### kubernetes
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes kubernetes --yaml -f ./labels-templates/kubernetes-yaml.yaml
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes kubernetes --table -f ./labels-templates/kubernetes-table.txt
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes kubernetes --json -f ./labels-templates/kubernetes-json.json
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes kubernetes --xml -f ./labels-templates/kubernetes-xml.xml

### openim OpenIMSDK/Open-IM-Server
❯ ./_output/bin/platforms/linux/amd64/exporter OpenIMSDK Open-IM-Server --yaml -f ./labels-templates/openim-yaml.yaml
❯ ./_output/bin/platforms/linux/amd64/exporter OpenIMSDK Open-IM-Server --table -f ./labels-templates/openim-table.txt
❯ ./_output/bin/platforms/linux/amd64/exporter OpenIMSDK Open-IM-Server --json -f ./labels-templates/openim-json.json
❯ ./_output/bin/platforms/linux/amd64/exporter OpenIMSDK Open-IM-Server --xml -f ./labels-templates/openim-xml.xml

### sealos labring/sealos
❯ ./_output/bin/platforms/linux/amd64/exporter labring sealos --yaml -f ./labels-templates/sealos-yaml.yaml
❯ ./_output/bin/platforms/linux/amd64/exporter labring sealos --table -f ./labels-templates/sealos-table.txt
❯ ./_output/bin/platforms/linux/amd64/exporter labring sealos --json -f ./labels-templates/sealos-json.json
❯ ./_output/bin/platforms/linux/amd64/exporter labring sealos --xml -f ./labels-templates/sealos-xml.xml

### vscode microsoft/vscode
❯ ./_output/bin/platforms/linux/amd64/exporter microsoft vscode --yaml -f ./labels-templates/vscode-yaml.yaml
❯ ./_output/bin/platforms/linux/amd64/exporter microsoft vscode --table -f ./labels-templates/vscode-table.txt
❯ ./_output/bin/platforms/linux/amd64/exporter microsoft vscode --json -f ./labels-templates/vscode-json.json
❯ ./_output/bin/platforms/linux/amd64/exporter microsoft vscode --xml -f ./labels-templates/vscode-xml.xml

### kubernetes-sigs kustomize
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes-sigs kustomize --yaml -f ./labels-templates/kustomize-yaml.yaml
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes-sigs kustomize --table -f ./labels-templates/kustomize-table.txt
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes-sigs kustomize --json -f ./labels-templates/kustomize-json.json
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes-sigs kustomize --xml -f ./labels-templates/kustomize-xml.xml

### prometheus prometheus
❯ ./_output/bin/platforms/linux/amd64/exporter prometheus prometheus --yaml -f ./labels-templates/prometheus-yaml.yaml
❯ ./_output/bin/platforms/linux/amd64/exporter prometheus prometheus --table -f ./labels-templates/prometheus-table.txt
❯ ./_output/bin/platforms/linux/amd64/exporter prometheus prometheus --json -f ./labels-templates/prometheus-json.json
❯ ./_output/bin/platforms/linux/amd64/exporter prometheus prometheus --xml -f ./labels-templates/prometheus-xml.xml

## prow kubernetes/test-infra
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes test-infra --yaml -f ./labels-templates/test-infra-yaml.yaml
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes test-infra --table -f ./labels-templates/test-infra-table.txt
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes test-infra --json -f ./labels-templates/test-infra-json.json
❯ ./_output/bin/platforms/linux/amd64/exporter kubernetes test-infra --xml -f ./labels-templates/test-infra-xml.xml

### redis redis
❯ ./_output/bin/platforms/linux/amd64/exporter redis redis --yaml -f ./labels-templates/redis-yaml.yaml
❯ ./_output/bin/platforms/linux/amd64/exporter redis redis --table -f ./labels-templates/redis-table.txt
❯ ./_output/bin/platforms/linux/amd64/exporter redis redis --json -f ./labels-templates/redis-json.json

Actions Auto Sync labels

For a more convenient way, we can use actions to sync labels directly, which is faster and easier

An example workflow is here:

name: Sync labels
on:
  push:
    branches:
      - master
    paths:
      - path/to/manifest/labels.yml
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Github lables pull and synchronize
        uses: kubecub/github-label-syncer@v2.0.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          manifest: path/to/manifest/labels.yml

You can sync labels to multiple repositories at the same time, which is more convenient, but you'll need to provide a token.

For example, the following yaml file takes a local.github/sync_labeler.yml file and syncs it to kubecub/github-label-syncer, kubecub/log, etc. BOT_GITHUB_TOKEN is used as the token

name: Kubecub Sync labels

on:
  push:
    branches:
      - main
    # paths:
    #   - .github/sync_labels.yml

jobs:
    build:
      runs-on: ubuntu-latest
      steps:
        - name: Checkout
          uses: actions/checkout@1.0.0
        - name: Github lables pull and synchronize
          uses: kubecub/github-label-syncer@v2.0.0
          with:
            manifest: .github/sync_labeler.yml
            token: ${{ secrets.BOT_GITHUB_TOKEN }}
            repository: |
              kubecub/github-label-syncer
              kubecub/log
          env:
            GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}

Note: The new labels and colors will replace the old ones

You can add jobs.<job_id>.steps.with.prune: false in order to preserver all existing labels which is not mentioned in manifest, in this case when a label will be renamed old label will be not deleted.

Work with Docker

❯ make deploy

🕋 architecture diagram

graph LR
A[Config file] -->B(github-label-syncer)
B --> C{Sync labels}
C -->|Yes| D[Create/Update labels] 
C -->|No | E[Delete labels]
D --> F[Dry run]
F --> |Yes| G[Preview]
F --> |No| H[Apply changes]
E --> I[Dry run]
I --> |Yes| J[Preview]
I --> |No| K[Apply changes]

MVC Architecture Design:

flowchart TB

A[Config file]
A --> B[github-label-syncer]
B --> C{Sync labels}
C -->|Yes|D[<font color='green'>Create/Update </font> <br>labels]
C -->|No|E[<font color='red'>Delete </font><br> labels]  
D -.-> F[<font color='blue'>Dry run</font><br>Preview]
F --> G[Apply <br>changes]
E -.-> H[<font color='blue'>Dry run</font><br>Preview]
H --> I[Apply<br> changes]
B --> J[Label <br>PRs & <br>Issues]

🗓️ community meeting

We welcome everyone to join us and contribute to github-label-syncer, whether you are new to open source or professional. We are committed to promoting an open source culture, so we offer community members neighborhood prizes and reward money in recognition of their contributions. We believe that by working together, we can build a strong community and make valuable open source tools and resources available to more people. So if you are interested in github-label-syncer, please join our community and start contributing your ideas and skills!

We take notes of each biweekly meeting in GitHub discussions, and our minutes are written in Google Docs.

github-label-syncer maintains a public roadmap. It gives a a high-level view of the main priorities for the project, the maturity of different features and projects, and how to influence the project direction.

🤼‍ Contributing & Development

kubecub Our goal is to build a top-level open source community. We have a set of standards, in the Community repository.

If you'd like to contribute to this github-label-syncer repository, please read our contributor documentation.

Before you start, please make sure your changes are in demand. The best for that is to create a new discussion OR Slack Communication, or if you find an issue, report it first.

🚨 License

Kubecub is licensed under the MIT License, Version 2.0. See LICENSE for the full license text.

FOSSA Status

🔮 Thanks to our contributors!