Note
- Projects (beta), the all-new projects experience, is now available. For more information about Projects (beta), see "About Projects (beta)."
- You can only create a new project (classic) for an organization, repository, or user that already has at least one project (classic). If you're unable to create a project (classic), create a project instead.
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 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 project (classic). 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
-
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."
-
Choose a project (classic) that belongs to the repository. This workflow cannot be used with projects that belong to users or organizations. You can use an existing project (classic), or you can create a new project (classic). For more information about creating a project, see "Creating a project (classic)."
-
In your repository, create a file called
.github/workflows/YOUR_WORKFLOW.yml
, replacingYOUR_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." -
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@v6 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"] })
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@v6 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"] })
-
Customize the parameters in your workflow file:
-
In
github.event.project_card.column_id == '12345678'
, replace12345678
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 (classic). 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 forhttps://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 column12345678
or column87654321
. The columns may be on different projects (classic). -
Change the value for
name
in thegithub.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 "Managing labels."
-
-
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 (classic) 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 project (classic) into the target column.
- Open an issue in your repository. For more information, see "Creating an issue."
- Label the issue with the label that you want the workflow to remove. For more information, see "Managing labels."
- Add the issue to the project (classic) column that you specified in your workflow file. For more information, see "Adding issues and pull requests to a project (classic)."
- 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."
- When the workflow completes, the issue that you added to the project column should have the specified label removed.
Next steps
- To learn more about additional things you can do with the
actions/github-script
action, see theactions/github-script
action documentation. - Search GitHub for examples of workflows using this action.