Skip to main content

Removing a label when a card is added to a プロジェクト (クラシック) column

You can use GitHub Actions to automatically remove a label when an issue or pull request is added to a specific column on a プロジェクト (クラシック).

メモ

  • 新しいプロジェクト エクスペリエンスである Projects が利用できるようになりました。 Projects の詳細については、「Projects について」を参照してください。
  • 新しいプロジェクト (クラシック)は、既に 1 つ以上のプロジェクト (クラシック)を持つ organization、リポジトリ、またはユーザーに対してのみ作成できます。 プロジェクト (クラシック)を作成できない場合は、代わりにプロジェクトを作成します。

メモ

GitHub ホステッド ランナーは、現在 GitHub Enterprise Server ではサポートされていません。 GitHub public roadmap で、今後の計画的なサポートの詳細を確認できます。

Introduction

This tutorial demonstrates how to use the actions/github-script action along with a conditional to remove a label from issues and pull requests that are added to a specific column on a プロジェクト (クラシック). For example, you can remove the needs review label when project cards are moved into the Done column.

In the tutorial, you will first make a workflow file that uses the actions/github-script action. Then, you will customize the workflow to suit your needs.

Creating the workflow

  1. このプロジェクト管理ワークフローを適用したいリポジトリを選択してください。 書き込みアクセス権を持つ既存のリポジトリを利用することも、新しいリポジトリを作成することもできます。 リポジトリの作成について詳しくは、「新しいリポジトリの作成」をご覧ください。

  2. Choose a プロジェクト (クラシック) that belongs to the repository. This workflow cannot be used with projects that belong to users or organizations. You can use an existing プロジェクト (クラシック), or you can create a new プロジェクト (クラシック). For more information about creating a project, see project (classic) の作成.

  3. リポジトリに .github/workflows/YOUR_WORKFLOW.yml というファイルを作成します (YOUR_WORKFLOW は任意の名前に置き換えます)。 これがワークフローファイルです。 GitHub での新しいファイルの作成について詳しくは、「新しいファイルの作成」をご覧ください。

  4. Copy the following YAML contents into your workflow file.

    YAML
    name: Remove a label
    on:
      project_card:
        types:
          - moved
    jobs:
      remove_label:
        if: github.event.project_card.column_id == '12345678'
        runs-on: ubuntu-latest
        permissions:
          issues: write
          pull-requests: write
        steps:
          - uses: actions/github-script@v7
            with:
              script: |
                // this gets the number at the end of the content URL, which should be the issue/PR number
                const issue_num = context.payload.project_card.content_url.split('/').pop()
                github.rest.issues.removeLabel({
                  issue_number: issue_num,
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  name: ["needs review"]
                })
    
  5. Customize the parameters in your workflow file:

    • In github.event.project_card.column_id == '12345678', replace 12345678 with the ID of the column where you want to un-label issues and pull requests that are moved there.

      To find the column ID, navigate to your プロジェクト (クラシック). Next to the title of the column, click then click Copy column link. The column ID is the number at the end of the copied link. For example, 24687531 is the column ID for http://github.com/octocat/octo-repo/projects/1#column-24687531.

      If you want to act on more than one column, separate the conditions with ||. For example, if github.event.project_card.column_id == '12345678' || github.event.project_card.column_id == '87654321' will act whenever a project card is added to column 12345678 or column 87654321. The columns may be on different プロジェクト (クラシック).

    • Change the value for name in the github.rest.issues.removeLabel() function to the name of the label that you want to remove from issues or pull requests that are moved to the specified column(s). For more information on labels, see ラベルを管理する.

  6. ワークフローファイルを、リポジトリのデフォルトブランチにコミットしてください。 詳しくは、「新しいファイルの作成」をご覧ください。

Testing the workflow

Every time a project card on a プロジェクト (クラシック) in your repository moves, this workflow will run. If the card is an issue or a pull request and is moved into the column that you specified, then the workflow will remove the specified label from the issue or a pull request. Cards that are notes will not be affected.

Test your workflow out by moving an issue on your プロジェクト (クラシック) into the target column.

  1. Open an issue in your repository. For more information, see Issue の作成.
  2. Label the issue with the label that you want the workflow to remove. For more information, see ラベルを管理する.
  3. Add the issue to the プロジェクト (クラシック) column that you specified in your workflow file. For more information, see project (classic) に issue と pull request を追加する.
  4. To see the workflow run that was triggered by adding the issue to the project, view the history of your workflow runs. For more information, see Viewing workflow run history.
  5. When the workflow completes, the issue that you added to the project column should have the specified label removed.

Next steps