github/issue-labeler
GitHub: github/issue-labeler
基于正则表达式自动为 GitHub Issue 和 Pull Request 添加及同步标签的 GitHub Action 工具。
Stars: 234 | Forks: 51
# Issue 标签器
Issue 标签器将根据 issue 的正文内容为其添加标签。
## 用法
### 创建 `.github/labeler.yml`
创建一个 `.github/labeler.yml` 文件,其中包含标签列表以及用于匹配并应用标签的正则表达式。
键(key)是您要在仓库中添加的标签名称(例如:"merge conflict"、"needs-updating"),值(value)是决定何时应用该标签的正则表达式。如果正则表达式不匹配,该标签将被移除。
#### 基础示例
```
# 如果 issue 包含 'urgent' 或 'critical',则添加/移除 'critical' 标签
critical:
- '(critical|urgent)'
```
#### 为所有 Issue 打标签
```
# 为任何被打开的 issue 添加 'critical' 标签
critical:
- '/.*/'
```
### 创建工作流
创建一个工作流(例如:`.github/workflows/labeler.yml`,参见[创建工作流文件](https://docs.github.com/en/actions/use-cases-and-examples/creating-an-example-workflow))以使用此标签器 action,内容如下:
```
name: "Issue Labeler"
on:
issues:
types: [opened, edited]
permissions:
issues: write
contents: read
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: github/issue-labeler@v3.3 #May not be the latest version
with:
configuration-path: .github/labeler.yml
not-before: 2020-01-15T02:54:32Z
enable-versioned-regex: 0
repo-token: ${{ github.token }}
```
`not-before` 是可选的,设置后将忽略此时间戳之前的所有 issue。
### 使用带有版本的 Issue 模板的示例
随着您不断迭代正则表达式,由于您的 issue 模板可能会更新,这可能会对现有的 issue 产生影响。以下内容允许您对正则表达式定义进行版本控制,并将它们与 issue 模板配对。
以下是一个示例 issue 的正文,其中嵌入了版本标识符 `issue_labeler_regex_version`。
```
I have an urgent issue that requires someone's attention.
```
以下是工作流文件
```
name: "Issue Labeler"
on:
issues:
types: [opened, edited]
permissions:
issues: write
contents: read
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: github/issue-labeler@v3.3 #May not be the latest version
with:
configuration-path: .github/labeler.yml
not-before: 2020-01-15T02:54:32Z
enable-versioned-regex: 1
versioned-regex: 'issue_labeler_regex_version=(\d+)'
body-missing-regex-label: 'broken-template'
repo-token: ${{ github.token }}
```
当评估该 issue 时,它将根据 issue 中设置的 `configuration-path` 和版本号来查找 `.github/labeler-v1.yml`。
当您想要更新标签和正则表达式,并且这可能导致与历史 issue 发生冲突时,只需更新您的 issue 模板以包含 `issue_labeler_regex_version=2`,并创建文件 `.github/labeler-v2.yml`。Issue 将自动匹配到正确的一组正则表达式。
将 `versioned-regex` 设置为任何有效的正则表达式,用于从 issue 中捕获版本号。如果找到多个匹配项,将使用第一个匹配项。
将 `body-missing-regex-label` 设置为当找不到指定的 `version-regex` 时,应添加到 issue 的标签名称。这对于用户意外删除该值的情况非常有用。如果您不想使用此功能,请将其留空。
### Pull request 支持
此标签器 action 也可用于 Pull request。请确保工作流由 Pull request 触发。
```
on:
pull_request:
types: [opened, edited]
```
### 在正则表达式匹配目标中包含 Issue 标题的示例
将 `include-title` 设置为 `1`,以便在正则表达式匹配目标中包含 issue 标题(除了正文之外)。
```
name: "Issue Labeler"
on:
issues:
types: [opened, edited]
permissions:
issues: write
contents: read
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: github/issue-labeler@v3.3 #May not be the latest version
with:
configuration-path: .github/labeler.yml
enable-versioned-regex: 0
include-title: 1
repo-token: ${{ github.token }}
```
### 在正则表达式匹配目标中*仅*包含 Issue 标题而不包含正文的示例
设置 `include-title: 1` 和 `include-body: 0`。
```
name: "Issue Labeler"
on:
issues:
types: [opened, edited]
permissions:
issues: write
contents: read
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: github/issue-labeler@v3.3 #May not be the latest version
with:
configuration-path: .github/labeler.yml
include-title: 1
include-body: 0
```
### 同步标签
默认情况下,不再匹配的标签不会从 issue 中移除。要启用此功能,请明确将 `sync-labels` 设置为 `1`。
```
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: github/issue-labeler@v3.3
with:
configuration-path: .github/labeler.yml
enable-versioned-regex: 0
sync-labels: 1
repo-token: ${{ github.token }}
```
标签:CICD, GitHub Action, GitHub机器人, Issue分类, Issue自动化, 事件驱动, 参数发现, 开源框架, 开源项目维护, 持续集成, 数据可视化, 文本匹配, 标签管理, 自动化攻击, 自动回复, 项目自动化管理