labels-sync

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Labels Sync: GitHub Label Synchronization

Labels Sync:GitHub标签同步

Purpose

用途

Synchronize GitHub repository labels with a predefined set of standard labels, or export the current repository labels as reusable JSON. The skill can compare the repo against a JSON definition, apply the missing changes, or return the repo's current label definitions in copy-ready form.
将GitHub仓库标签与预定义的标准标签集同步,或者将当前仓库的标签导出为可复用的JSON格式。本工具可以将仓库标签与JSON定义进行对比,应用缺失的更改,或者以可复制的形式返回仓库当前的标签定义。

When to Use This Skill

使用场景

Use when the user asks to:
  • "Sync labels", "update labels", "fix labels"
  • "Check labels", "show label differences", "preview label changes"
  • "Manage GitHub labels", "set up labels"
  • "Apply standard labels to this repo"
  • "Export labels", "get current labels", "show labels JSON", "copy labels to another repo"
Trigger phrases: "labels-sync", "labels sync", "sync labels", "label sync", "github labels", "check labels", "export labels", "get labels"
当用户提出以下需求时使用:
  • "同步标签"、"更新标签"、"修复标签"
  • "检查标签"、"查看标签差异"、"预览标签更改"
  • "管理GitHub标签"、"设置标签"
  • "为当前仓库应用标准标签"
  • "导出标签"、"获取当前标签"、"查看标签JSON"、"复制标签到其他仓库"
触发短语:"labels-sync"、"labels sync"、"sync labels"、"label sync"、"github labels"、"check labels"、"export labels"、"get labels"

Operations

操作说明

For sync and check flows, the script compares repository labels against the defined list and reports:
  • CREATE: Labels in the definition but not in the repository
  • UPDATE: Labels that exist but have different name case, description, or color
  • DELETE: Labels in the repository but not in the definition
  • UNCHANGED: Labels that match exactly
For export flows, the script reads the current repository labels and returns a normalized JSON array with:
  • name
  • description
  • color
在同步和检查流程中,脚本会将仓库标签与定义列表进行对比,并报告:
  • CREATE:定义中存在但仓库中没有的标签
  • UPDATE:已存在但名称大小写、描述或颜色不同的标签
  • DELETE:仓库中存在但定义里没有的标签
  • UNCHANGED:完全匹配的标签
在导出流程中,脚本会读取当前仓库的标签,并返回标准化的JSON数组,包含以下字段:
  • name
  • description
  • color

Asking the User

询问用户

Every question in this skill is written as
AskUserQuestion
options. Use that tool where the host offers it, or the host's nearest structured-choice equivalent. Where the host has neither, ask the same question in normal chat as a numbered list of 2–5 options — recommended first, one short line of description each — and wait for the user to reply with a number.
本工具中的所有问题均以
AskUserQuestion
选项形式编写。如果宿主平台提供该工具,请使用它;如果没有,请使用宿主平台最接近的结构化选择功能替代。若两者都没有,则以普通聊天形式提出问题,并列出2-5个带编号的选项——推荐将首选选项放在第一位,每个选项配一行简短描述——然后等待用户回复编号。

Execution Steps

执行步骤

Step 1: Determine Intent

步骤1:确定意图

From the command arguments or conversation context, determine the user's intent:
Apply changes if user explicitly requests (keywords in args or context):
  • apply
    ,
    sync
    ,
    update
    ,
    fix
    ,
    set
    ,
    enforce
  • Example:
    labels-sync apply
    or "sync my labels"
Report only if user wants to check (keywords):
  • check
    ,
    list
    ,
    show
    ,
    preview
    ,
    dry-run
    ,
    diff
  • Example:
    labels-sync check
    or "show label differences"
Export current labels if user wants reusable output (keywords):
  • get
    ,
    export
    ,
    read
    ,
    copy
    ,
    json
  • Example:
    labels-sync get
    or "export current labels so I can copy them to another repo"
If intent is unclear or no arguments are provided, ask per Asking the User:
  1. Check
    (Recommended) — Compare the repo labels against the bundled definition
  2. Get
    — Export the repo's current labels as reusable JSON
  3. Apply
    — Sync the repo labels to match the bundled definition
从命令参数或对话上下文判断用户的意图:
应用更改 如果用户明确要求(参数或上下文中包含以下关键词):
  • apply
    sync
    update
    fix
    set
    enforce
  • 示例:
    labels-sync apply
    或 "同步我的标签"
仅生成报告 如果用户想要检查(包含以下关键词):
  • check
    list
    show
    preview
    dry-run
    diff
  • 示例:
    labels-sync check
    或 "查看标签差异"
导出当前标签 如果用户想要可复用的输出(包含以下关键词):
  • get
    export
    read
    copy
    json
  • 示例:
    labels-sync get
    或 "导出当前标签以便复制到其他仓库"
如果意图不明确或未提供参数,请按照「询问用户」部分的方式提问:
  1. Check
    (推荐)—— 将仓库标签与内置定义进行对比
  2. Get
    —— 将仓库当前标签导出为可复用的JSON
  3. Apply
    —— 同步仓库标签以匹配内置定义

Step 2: Export Current Labels When Requested

步骤2:按需导出当前标签

For get/export mode, fetch and return the current repository labels directly:
bash
scripts/sync-labels.sh --get
Return the output in a fenced
json
block so the user can copy it into another repository later. Keep the fields in the reusable definition shape:
json
[
  {
    "name": "bug",
    "description": "Something isn't working",
    "color": "B60205"
  }
]
If the user explicitly asks for only
name
and
color
, summarize those fields in the prose response, but keep the script output in the full reusable format unless they ask to omit descriptions.
get/export模式下,直接获取并返回当前仓库的标签:
bash
scripts/sync-labels.sh --get
将输出放在带围栏的
json
代码块中,方便用户稍后复制到其他仓库。保持字段为可复用的定义格式:
json
[
  {
    "name": "bug",
    "description": "Something isn't working",
    "color": "B60205"
  }
]
如果用户明确要求只返回
name
color
,则在文本回复中汇总这些字段,但除非用户要求省略描述,否则脚本输出仍保持完整的可复用格式。

Step 3: Read Label Definitions for Sync/Check

步骤3:读取同步/检查用的标签定义

Read the label definitions from the bundled JSON file:
references/labels.json
Use the Read tool to load the file contents.
Skip this step for get/export mode.
从内置的JSON文件中读取标签定义:
references/labels.json
使用读取工具加载文件内容。
get/export模式下跳过此步骤。

Step 4: Execute Sync Script

步骤4:执行同步脚本

Pipe the label JSON to the sync script:
For dry-run (report only):
bash
cat references/labels.json | scripts/sync-labels.sh
For applying changes, add
--apply
flag:
bash
cat references/labels.json | scripts/sync-labels.sh --apply
将标签JSON传入同步脚本:
对于dry-run(仅报告):
bash
cat references/labels.json | scripts/sync-labels.sh
对于应用更改,添加
--apply
参数:
bash
cat references/labels.json | scripts/sync-labels.sh --apply

Step 5: Present Results

步骤5:展示结果

Parse the JSON output and present as a readable markdown report:
解析JSON输出并以易读的markdown报告形式展示:

Labels to Create

待创建标签

NameDescriptionColor
.........
名称描述颜色
.........

Labels to Update

待更新标签

NameFieldFromTo
............
名称字段当前值目标值
............

Labels to Delete

待删除标签

Name
...
名称
...

Unchanged Labels

未更改标签

  • label1, label2, label3...
If no changes are needed, report that all labels are already in sync.
If changes were applied, confirm success. If any errors occurred, report them.
For get/export mode, prefer returning the exact JSON in a fenced code block first, then optionally add a short summary table of label names and colors if that helps the user scan it.
  • label1、label2、label3...
如果无需更改,报告所有标签已同步。
如果更改已应用,确认操作成功。若发生任何错误,报告错误信息。
对于get/export模式,优先返回带围栏代码块的精确JSON,然后可选择性添加标签名称和颜色的简短汇总表格,方便用户快速浏览。

Customization

自定义

To customize the label set, edit the JSON file at:
references/labels.json
Each label entry requires three fields:
  • name
    — Label name (case-sensitive)
  • description
    — Short description
  • color
    — Hex color without
    #
    prefix (e.g.,
    B60205
    )
要自定义标签集,请编辑以下JSON文件:
references/labels.json
每个标签条目需要三个字段:
  • name
    —— 标签名称(区分大小写)
  • description
    —— 简短描述
  • color
    —— 不带
    #
    前缀的十六进制颜色(例如:
    B60205

Bundled Files

内置文件

  • scripts/sync-labels.sh
    — Generic sync/export script (exports current labels, or reads stdin JSON, diffs via
    jq
    , and applies via
    gh
    )
  • references/labels.json
    — Label definitions (single source of truth)
  • scripts/sync-labels.sh
    —— 通用同步/导出脚本(导出当前标签,或读取标准输入的JSON,通过
    jq
    对比差异,并通过
    gh
    应用更改)
  • references/labels.json
    —— 标签定义(唯一可信来源)

Prerequisites

前置条件

  • gh
    CLI authenticated (
    gh auth login
    )
  • jq
    installed
  • Must be run from within a GitHub repository
  • gh
    CLI已完成认证(执行
    gh auth login
  • 已安装
    jq
  • 必须在GitHub仓库目录内运行