Skip to main content

This version of GitHub Enterprise was discontinued on 2022-10-12. No patch releases will be made, even for critical security issues. For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise. For help with the upgrade, contact GitHub Enterprise support.

Removing a label when a card is added to a project board 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 project board.

Note: GitHub-hosted runners are not currently supported on GitHub Enterprise Server. You can see more information about planned future support on the GitHub public roadmap.

Introduction

This tutorial demonstrates how to use the andymckay/labeler action along with a conditional to remove a label from issues and pull requests that are added to a specific column on a project board. 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 andymckay/labeler action. Then, you will customize the workflow to suit your needs.

Creating the workflow

  1. Choose a repository where you want to apply this project management workflow. You can use an existing repository that you have write access to, or you can create a new repository. For more information about creating a repository, see "Creating a new repository."

  2. Choose a project that belongs to the repository. This workflow cannot be used with projects that belong to users or organizations. You can use an existing project, or you can create a new project. For more information about creating a project, see "Creating a project board."

  3. In your repository, create a file called .github/workflows/YOUR_WORKFLOW.yml, replacing YOUR_WORKFLOW with a name of your choice. This is a workflow file. For more information about creating new files on GitHub, see "Creating new files."

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

    YAML
    # This workflow uses actions that are not certified by GitHub.
    # They are provided by a third-party and are governed by
    # separate terms of service, privacy policy, and support
    # documentation.
    
    # GitHub recommends pinning actions to a commit SHA.
    # To get a newer version, you will need to update the SHA.
    # You can also reference a tag or branch, but the action may change without warning.
    
    name: Remove labels
    on:
      project_card:
        types:
          - moved
    jobs:
      remove_labels:
        if: github.event.project_card.column_id == '12345678'
        runs-on: ubuntu-latest
        permissions:
          issues: write
          pull-requests: write
        steps:
          - name: remove labels
            uses: andymckay/labeler@5c59dabdfd4dd5bd9c6e6d255b01b9d764af4414
            with:
              remove-labels: "needs review"
              repo-token: ${{ secrets.GITHUB_TOKEN }}
  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 project board. 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 https://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 project boards.

    • Change the value for remove-labels to the list of labels that you want to remove from issues or pull requests that are moved to the specified column(s). Separate multiple labels with commas. For example, "help wanted, good first issue". For more information on labels, see "Managing labels."

  6. Commit your workflow file to the default branch of your repository. For more information, see "Creating new files."

Testing the workflow

Every time a project card on a project 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 labels 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 project into the target column.

  1. Open an issue in your repository. For more information, see "Creating an issue."
  2. Label the issue with the labels that you want the workflow to remove. For more information, see "Managing labels."
  3. Add the issue to the project column that you specified in your workflow file. For more information, see "Adding issues and pull requests to a project board."
  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 labels removed.

Next steps

  • To learn more about additional things you can do with the andymckay/labeler action, like adding labels or skipping this action if the issue is assigned or has a specific label, visit the andymckay/labeler action documentation.
  • Search GitHub for examples of workflows using this action.