Introduction
This tutorial demonstrates how to use the GitHub CLI in a workflow to label newly opened or reopened issues. For example, you can add the triage
label every time an issue is opened or reopened. Then, you can see all issues that need to be triaged by filtering for issues with the triage
label.
The GitHub CLI allows you to easily use the GitHub API in a workflow.
In the tutorial, you will first make a workflow file that uses the GitHub CLI. Then, you will customize the workflow to suit your needs.
Creating the workflow
-
Wähle ein Repository aus, in dem du diesen Projektverwaltungsworkflow anwenden möchtest. Du kannst ein vorhandenes Repository verwenden, auf das du Schreibzugriff hast, oder du kannst ein neues Repository erstellen. Weitere Informationen zum Erstellen eines Repositorys findest du unter Ein neues Repository erstellen.
-
Erstelle in deinem Repository eine Datei namens
.github/workflows/YOUR_WORKFLOW.yml
, und ersetzeYOUR_WORKFLOW
durch einen Namen deiner Wahl. Dies ist eine Workflowdatei. Weitere Informationen zum Erstellen neuer Dateien auf GitHub findest du unter Neue Dateien erstellen. -
Copy the following YAML contents into your workflow file.
YAML name: Label issues on: issues: types: - reopened - opened jobs: label_issues: runs-on: ubuntu-latest permissions: issues: write steps: - run: gh issue edit "$NUMBER" --add-label "$LABELS" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} NUMBER: ${{ github.event.issue.number }} LABELS: triage
name: Label issues on: issues: types: - reopened - opened jobs: label_issues: runs-on: ubuntu-latest permissions: issues: write steps: - run: gh issue edit "$NUMBER" --add-label "$LABELS" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} NUMBER: ${{ github.event.issue.number }} LABELS: triage
-
Customize the
env
values in your workflow file:- The
GH_TOKEN
,GH_REPO
, andNUMBER
values are automatically set using thegithub
andsecrets
contexts. You do not need to change these. - Change the value for
LABELS
to the list of labels that you want to add to the issue. The label(s) must exist for your repository. Separate multiple labels with commas. For example,help wanted,good first issue
. For more information about labels, see Verwalten von Bezeichnungen.
- The
-
Committe deine Workflowdatei in den Standardbranch deines Repositorys. Weitere Informationen finden Sie unter Neue Dateien erstellen.
Testing the workflow
Every time an issue in your repository is opened or reopened, this workflow will add the labels that you specified to the issue.
Test out your workflow by creating an issue in your repository.
- Create an issue in your repository. For more information, see Einen Issue erstellen.
- To see the workflow run that was triggered by creating the issue, view the history of your workflow runs. For more information, see Viewing workflow run history.
- When the workflow completes, the issue that you created should have the specified labels added.
Next steps
- To learn more about additional things you can do with the GitHub CLI, see the GitHub CLI manual.
- To learn more about different events that can trigger your workflow, see Ereignisse zum Auslösen von Workflows.
- Search GitHub for examples of workflows using
gh issue edit
.