Skip to content

Commit

Permalink
Merge pull request #1 from alexh97/project-assigner
Browse files Browse the repository at this point in the history
Moving the source from my private repo to Elastic's repo
  • Loading branch information
Alex Holmansky authored Dec 10, 2019
2 parents e7333ae + 0613e17 commit 3a4afe6
Show file tree
Hide file tree
Showing 7 changed files with 29,042 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This repository contains various GitHub actions that the Elastic team has developed to help us automate some common processes. Each action appears in it own folder.

To use these actions in your GitHub workfkflows, include them in the workflow configuration file step config. For example:

steps:
- name: Assign to project
uses: elastic/github-actions/[email protected]
id: project_assigner
with:
issue-mappings: '[{"label": "Test", "projectName": "test", "columnId": 1234},
{"label": "bug", "projectName": "test2", "columnId": 5678}]'
ghToken: ${{ secrets.GITHUB_TOKEN }}
65 changes: 65 additions & 0 deletions project-assigner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Project Assigner GitHub Action

This is a GitHub action, implemented in JavaScript, which does the following:
- Assigns an issue or pull request to a project when a specified label is applied
- Removes an issue or pull request from a project when a specified label is removed

You can provide multiple label to project mappings as the action input.

## Inputs

### `issue-mappings`
A JSON array of objects containing `label`, `projectName`, and `columnId` attributes.

**`label`** - name of the GitHub label that should trigger this action when it's applied to or removed from an issue or a pull request.

**`projectName`** - name of the project that an issue or pull request should be assinged to when the label is applied, or removed from when the label is removed.

**`columnId`** - *ID* of the GitHub project column that an issue or a pull request should be placed in when they're assigned to the project. For issues, this would typically be the ID of the "To Do" column. For pull requests, this may be the ID of the "In Review" column. You should use your own discression when choosing which columns to use for your particular project. A column ID can be found by copying the column URL using its "..." menu and then using the numeric ID at the end of the URL as the value for `columnId`.

Here's a sample format of the `issue-mappings` input:

issue-mappings: '[{"label": "Test", "projectName": "test", "columnId": 1234},
{"label": "bug", "projectName": "test2", "columnId": 5678}]'

## Example usage

In order to use this action, create a workflow configuration file (e.g. `issues-workflow.yml`) in your repository's `.github/workflows` directory. *Note that you need to have GitHub Actions enabled for your repository in order for this to work!*

### A workflow configuration for assigning issues to projects

on:
issues:
types: [labeled, unlabeled]

jobs:
assign_to_project:
runs-on: ubuntu-latest
name: Assign an issue to project based on label
steps:
- name: Assign to project
uses: elastic/github-actions/[email protected]
id: project_assigner
with:
issue-mappings: '[{"label": "Test", "projectName": "test", "columnId": 1234},
{"label": "bug", "projectName": "test2", "columnId": 5678}]'
ghToken: ${{ secrets.GITHUB_TOKEN }}

### A workflow configuration for assigning pull requests to projects

on:
pull_request:
types: [labeled, unlabeled]

jobs:
assign_to_project:
runs-on: ubuntu-latest
name: Assign a PR to project based on label
steps:
- name: Assign to project
uses: elastic/github-actions/[email protected]
id: project_assigner
with:
issue-mappings: '[{"label": "Test", "projectName": "test", "columnId": 1234},
{"label": "enhancement", "projectName": "test2", "columnId": 5678}]'
ghToken: ${{ secrets.GITHUB_TOKEN }}
9 changes: 9 additions & 0 deletions project-assigner/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: 'Project Assigner'
description: 'Assigns an issue to a project based on its lable at the time it is opened or labeled'
inputs:
issue-mappings:
description: 'A JSON array of objects containing label, projectName, and columnId attributes'
required: true
runs:
using: 'node12'
main: 'dist/index.js'
Loading

0 comments on commit 3a4afe6

Please sign in to comment.