Since projects got added to GitHub, I started using it more and more. For Front Matter, I am using projects to manage its releases. Before projects, I used milestones, but with projects, it is easier to follow up on what things I still need to do before the release.
One thing I was missing was a sort of label in the issue list to easily spot which issues were already added to a project release.
To enhance my experience on GitHub, I went on the journey to find out if it was possible with GitHub Actions.
Getting the event type and project data
To label the issue, what I needed to know were two things:
- The event type. Was the issue added to or deleted from the project;
- The name of the project.
The event type can be retrieved from the
github.event.action environment variable. In the case for my actions, I configured it to trigger on
project_card with the
[created, moved, deleted] types.
The project name is a bit trickier as it is not passed as an environment variable. You will have to do an API call to get the project name. The API is provided by the
github.event.project_card.project_url environment variable. In my case, the variable its value is:
Via a CURL command execution, you can receive this information.
The notation you can see here is to store the CURL response in an environment variable called PROJECT_DATA. You can find more information about setting environment variables in the GitHub documentation.
Once you have the name, all you need is to use the Simple Issue Labeler action to add or remove your project labels.
Here you can see the whole GitHub workflow:
When you add or remove your issues to a project, the labels will now be automatically added or removed.