Skip to content

senzing-factory/github-action-add-issue-to-project

Repository files navigation

github-action-add-issue-to-project

Overview

The repository holds and shows example usage of the GitHub workflow that can automatically add issues and pull-requests to GitHub projects. The workflow can check labels, project columns, and repository topics to conditionally add issues or pull-requests to selected projects.

Contents

  1. Inputs
    1. Projects
    2. Topics
    3. Column_name
  2. Examples
    1. Repository project
    2. Organization or user projects
    3. Using topics
  3. References

Legend

  1. 🤔 - A "thinker" icon means that a little extra thinking may be required. Perhaps you'll need to make some choices. Perhaps it's an optional step.
  2. ✏️ - A "pencil" icon means that the instructions may need modification before performing.
  3. ⚠️ - A "warning" icon means that something tricky is happening, so pay attention.

Inputs

Projects

🤔 The URL of the project to be assigned to. You must use one of the follow sets of inputs:

  • project
  • project1 and/or project2

Topics

🤔 The string of the topics to check for. Required if you are using the project1 and/or project 2 inputs.

Column_name

Optional: The column name of the project, defaults to 'To do' for issues and 'In progress' for pull requests.

Examples

Repository project

✏️

name: Auto Assign to Project

on:
  issues:
    types: [opened, labeled]
  pull_request:
    types: [opened, labeled]
env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
  assign_one_project:
    runs-on: ubuntu-latest
    name: Assign to One Project
    steps:
    - name: Assign NEW issues or NEW pull requests to project 2
      uses: Senzing/github-action-add-issue-to-project@1.0.0
      with:
        project: 'https://github.com/{user}/{repository-name}/projects/2'
        column_name: 'Backlog'

    - name: Assign issues and pull requests with `bug` label to project 3
      uses: Senzing/github-action-add-issue-to-project@1.0.0
      if: |
        contains(github.event.issue.labels.*.name, 'bug') ||
        contains(github.event.pull_request.labels.*.name, 'bug')
      with:
        project: 'https://github.com/{user}/{repository-name}/projects/2'
        column_name: 'Labeled'

Notes

🤔 Be careful of using the conditions above (opened and labeled issues/PRs) because in such workflow, if the issue/PR is opened and labeled at the same time, it will be assigned to both projects!

You can use any combination of conditions. For example, to assign new issues or issues labeled with 'mylabel' to a project column, use:

...

if: |
  github.event == 'issue' &&
  (
    github.event.action == 'opened' ||
    contains(github.event.issue.labels.*.name, 'mylabel')
  )
...

Organization or User project

✏️

Generate a token from the Organization settings or User Settings and add it as a secret in the repository secrets as MY_GITHUB_TOKEN

name: Auto Assign to Project(s)

on:
  issues:
    types: [opened, labeled]
  pull_request_target:
    types: [opened, labeled]
env:
  MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}

jobs:
  assign_one_project:
    runs-on: ubuntu-latest
    name: Assign to One Project
    steps:
    - name: Assign NEW issues and NEW pull requests to project 2
      uses: Senzing/github-action-add-issue-to-project@1.0.0
      with:
        project: 'https://github.com/org/{org-name}/projects/2'

    - name: Assign issues and pull requests with `bug` label to project 3
      uses: srggrs/assign-one-project-github-action@1.2.1
      if: |
        contains(github.event.issue.labels.*.name, 'bug') ||
        contains(github.event.pull_request.labels.*.name, 'bug')
      with:
        project: 'https://github.com/org/{org-name}/projects/3'
        column_name: 'Labeled'

Using topics

✏️ Generate a token from the organization settings or User Settings and add it as a secret in the repository secrets as MY_GITHUB_TOKEN. Under 'env:' add the "REPO_URL" variable and use the project1, project2, topic1, and topic2 inputs. If the repository has topic1 then it will be put in project1 and topic2 will be put in project2. If you are using the "column_name" input make sure that both projects have that column.

name: Auto Assign to Project

on:
  issues:
    types: [opened, labeled]
  pull_request_target:
    types: [opened, labeled]
env:
  MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
  REPO_URL: ${{ github.event.repository.url}}
  
jobs:
  assign_one_project:
    runs-on: ubuntu-latest
    name: Assign to One Project
    steps:
    - name: Check for repository topics and add to project based on topic
      uses: Senzing/github-action-add-issue-to-project@1.0.0
      with:
        project1: 'https://github.com/org/{org-name}/projects/2'
        project2: 'https://github.com/org/{org-name}/projects/4'
        topic1: 'my-topic1'
        topic2: 'my-topic2'
        column_name: 'Backlog'

References

  1. GitHub workflow
    1. Documentation
    2. GitHub actions
  2. Inspiration
    1. GitHub