Note Use the official action Add To GitHub projects.
Warning We deprecated the ProjectNext GraphQL API on 2022-06-20, and we will remove the ProjectNext GraphQL API on 2022-10-01. For more information on migrating to the new ProjectV2 GraphQL API, please see "The new GitHub Issues – June 23rd update" in the GitHub Blog. See Using the API to manage Projects .
This GitHub action adds issues or pull requests to a Project (beta).
Create a workflow (eg: .github/workflows/on-issue-pr-open.yml). See Creating a Workflow file.
You will need a project number for input project-number. For example https://github.com/users/austenstone/projects/5 the project number is 5.
You will need to create a PAT(Personal Access Token) that has admin:org access so we can read/write to the project.
For user owned projects the PAT will also need to have repo and project scopes.
Add this PAT as a secret so we can use it as input github-token, see Creating encrypted secrets for a repository.
If your project is part of an organization that has SAML enabled you must authorize the PAT, see Authorizing a personal access token for use with SAML single sign-on.
name: "Add to Project"
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
add_to_project:
runs-on: ubuntu-latest
steps:
- uses: austenstone/project-add@main
with:
github-token: "${{ secrets.MY_TOKEN }}"
project-number: 1234For user owned projects you must provide the user input in the workflow.
with:
user: ${{ github.repository_owner }}
github-token: "${{ secrets.MY_TOKEN }}"
project-number: 1234Modify the on event to be issues or pull_request or both. All activity types work.
on:
issues:
types: [opened]on:
issues:
types: [assigned]
jobs:
add_assigned_to_project:
runs-on: ubuntu-latest
name: Add issue to project (beta)
steps:
- name: "Add issue that have been assigned to austenstone to project board"
uses: austenstone/project-add@v1
if: contains(github.event.issue.assignees.*.login, 'austenstone')
with:
github-token: ${{ secrets.MY_TOKEN }}
project-number: 5Various inputs are defined in action.yml:
| Name | Description | Default |
|---|---|---|
| project-number | The project number. Get this from the URL. | N/A |
| github-token | Token to use to authorize. This should be a personal access token. | ${{ github.token }} |
| organization | The organization that owns of the project. | the repository owner |
| user | The user that owns of the project. | N/A |
If you are using a user owned project board you must provide the user input.${{ github.repository_owner }} is fine if you're the owner of the repository.
Until GitHub supports permissions for projects (beta) we will need to create a PAT(Personal Access Token) with admin:org scope.
Once support is added you we can utilize Assigning permissions to jobs and the action will default to the token ${{ github.token }}.
permissions:
repository-projects: writeAnother option is to use something like tibdex/github-app-token to get a token during the workflow.