Remarque
- Projects, la toute nouvelle expérience de projet, est maintenant disponible. Pour plus d’informations sur Projects, consultez À propos des Projects.
- Vous pouvez uniquement créer un projet (classique) pour une organisation, un référentiel, ou un utilisateur qui a déjà au moins un projet (classique). Si vous ne parvenez pas à créer un projet (classique), créez à la place un projet.
Remarque
Les exécuteurs hébergés sur GitHub ne sont pas pris en charge sur GitHub Enterprise Server. Vous pouvez voir plus d’informations sur le support futur planifié dans la 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 projet (classique). 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
-
Choisissez un dépôt où vous souhaitez appliquer ce workflow de gestion de projet. Vous pouvez utiliser un dépôt existant auquel vous avez accès en écriture ou en créer un nouveau. Pour plus d’informations sur la création d’un référentiel, consultez Création d’un dépôt.
-
Choose a projet (classique) that belongs to the repository. This workflow cannot be used with projects that belong to users or organizations. You can use an existing projet (classique), or you can create a new projet (classique). For more information about creating a project, see Création d’un project (classic).
-
Dans votre dépôt, créez un fichier nommé
.github/workflows/YOUR_WORKFLOW.yml
, enYOUR_WORKFLOW
remplaçant par un nom de votre choix. Il s’agit d’un fichier de workflow. Pour plus d’informations sur la création de nouveaux fichiers dans GitHub, consultez Création de fichiers. -
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"] })
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"] })
-
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 projet (classique). 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 projets (classique). -
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 Gestion des étiquettes.
-
-
Commitez votre fichier de workflow dans la branche par défaut de votre dépôt. Pour plus d’informations, consultez « Création de fichiers ».
Testing the workflow
Every time a project card on a projet (classique) 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 projet (classique) into the target column.
- Open an issue in your repository. For more information, see Création d’un problème.
- Label the issue with the label that you want the workflow to remove. For more information, see Gestion des étiquettes.
- Add the issue to the projet (classique) column that you specified in your workflow file. For more information, see Ajout de problèmes et de demandes de tirage à un 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.