Skip to content

Commit d425076

Browse files
authored
Merge pull request #41 from woocommerce/add/assign-milestone-workflow
Add Assign Milestone Workflow
2 parents f50057d + f226d2b commit d425076

File tree

17 files changed

+6340
-7365
lines changed

17 files changed

+6340
-7365
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
on: pull_request_review
2+
name: Add milestone when approved
3+
jobs:
4+
milestoneWhenApproved:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- uses: ./
9+
with:
10+
github_token: ${{ secrets.GITHUB_TOKEN }}
11+
automations: assign-milestone

.prettierrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Import the default config file and expose it in the project root.
2+
// Useful for editor integrations.
3+
module.exports = require( '@wordpress/prettier-config' );

README.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ This is a [GitHub Action](https://help.github.com/en/categories/automating-your-
44

55
## Available Automations
66

7-
| Automation | Description |
8-
| ---- | --------------|
9-
| [todos](./lib/automations/todos/README.md) | This automation parses for `@todo` or `@TODO` comments in code and adds formatted pull request comments for each todo found. When a pull request is merged to the main branch, issues will be created for each `@todo` in the diff if there is not already an issue for that todo. |
10-
| [release](./lib/automations/release/README.md) | This automation handles automating various parts of a somewhat opinionated release process.
7+
| Automation | Description |
8+
| ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9+
| [todos](./lib/automations/todos/README.md) | This automation parses for `@todo` or `@TODO` comments in code and adds formatted pull request comments for each todo found. When a pull request is merged to the main branch, issues will be created for each `@todo` in the diff if there is not already an issue for that todo. |
10+
| [release](./lib/automations/release/README.md) | This automation handles automating various parts of a somewhat opinionated release process. |
11+
| [assign-milestone](./lib/automations/assign-milestone/README.md) | This automation will assign the next milestone to a pull request once it has been approved. |
1112

1213
## Installation and Usage
1314

@@ -16,22 +17,22 @@ To use the action, include it in your workflow configuration file:
1617
```yaml
1718
on: pull_request
1819
jobs:
19-
pull-request-automation:
20-
runs-on: ubuntu-latest
21-
steps:
22-
- uses: woocommerce/automations@v1
23-
with:
24-
github_token: ${{ secrets.GITHUB_TOKEN }}
25-
# This can be a comma delimited list of automations to run, in this case we're just executing todos
26-
automations: todos
20+
pull-request-automation:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: woocommerce/automations@v1
24+
with:
25+
github_token: ${{ secrets.GITHUB_TOKEN }}
26+
# This can be a comma delimited list of automations to run, in this case we're just executing todos
27+
automations: todos
2728
```
2829
2930
## API
3031
3132
### Inputs
3233
33-
- `github_token`: Required. GitHub API token to use for making API requests. This should be stored as a secret in the GitHub repository.
34-
- `automations`: Optional. You can include a comma-delimited list of specific automations you want to run if you don't want to use them all in a given workflow.
34+
- `github_token`: Required. GitHub API token to use for making API requests. This should be stored as a secret in the GitHub repository.
35+
- `automations`: Optional. You can include a comma-delimited list of specific automations you want to run if you don't want to use them all in a given workflow.
3536

3637
### Outputs
3738

@@ -43,41 +44,41 @@ This will be expanded, but for reference:
4344

4445
### Developing
4546

46-
- Clone the repo and then `npm install`.
47+
- Clone the repo and then `npm install`.
4748

4849
### Builds and releases
4950

50-
- All pushes to trunk will automatically build the `dist/index.js` file for the action (then commit and push to trunk). So no need to worry about builds.
51-
- For releases, make sure you update the examples in the `README.md` if releasing a major version, otherwise just create a release manually (in the future this may get automated for releases).
51+
- All pushes to trunk will automatically build the `dist/index.js` file for the action (then commit and push to trunk). So no need to worry about builds.
52+
- For releases, make sure you update the examples in the `README.md` if releasing a major version, otherwise just create a release manually (in the future this may get automated for releases).
5253

5354
### Adding a new automation.
5455

5556
The design of this repository is setup so that automations can be their own discrete thing (eg. "todos") but still take advantage of various scaffolding and boilerplate when creating a new automation. The following is a rough list of steps to take to create and add a new automation:
5657

57-
- Create a new directory in `lib/automations` that is the name of your automation.
58-
- Your `lib/automations` directory must at a minimum export the following from the `index.js` file in the directory:
58+
- Create a new directory in `lib/automations` that is the name of your automation.
59+
- Your `lib/automations` directory must at a minimum export the following from the `index.js` file in the directory:
5960

6061
```js
6162
module.exports = {
62-
// the name of your automation
63-
name: 'my-automation',
64-
// what github action workflow events your automation reacts to.
65-
events: [ 'pull_request' ],
66-
// what github action workflow event actions your automation reacts to.
67-
actions: [ 'opened' ],
68-
// the runner for your automation.
69-
runner
70-
}
63+
// the name of your automation
64+
name: 'my-automation',
65+
// what github action workflow events your automation reacts to.
66+
events: ['pull_request'],
67+
// what github action workflow event actions your automation reacts to.
68+
actions: ['opened'],
69+
// the runner for your automation.
70+
runner,
71+
};
7172
```
72-
- As noted above, this export must include a `runner` for your automation. The runner is an async function that will receive two arguments: `context` (which is the GitHub action context value) and `octokit` (which is the GitHub api helper). See more about these two arguments [here](https://github.com/actions/toolkit/tree/trunk/packages/github) (they are essentially what gets exposed by the `@actions/github` package). You can use the [`todos` runner as an example](https://github.com/woocommerce/automations/blob/trunk/lib/automations/todos/runner.js).
73-
- Finally, in [`lib/automations.js`](https://github.com/woocommerce/automations/automations/blob/trunk/lib/automations.js), makes sure you import your automation configuration into this file and add it to the `moduleNames` array. So for example, if your automation was setup in `lib/automations/my-automation`, you would have something like this in the file after your changes:
7473

75-
```js
74+
- As noted above, this export must include a `runner` for your automation. The runner is an async function that will receive two arguments: `context` (which is the GitHub action context value) and `octokit` (which is the GitHub api helper). See more about these two arguments [here](https://github.com/actions/toolkit/tree/trunk/packages/github) (they are essentially what gets exposed by the `@actions/github` package). You can use the [`todos` runner as an example](https://github.com/woocommerce/automations/blob/trunk/lib/automations/todos/runner.js).
75+
- Finally, in [`lib/automations.js`](https://github.com/woocommerce/automations/automations/blob/trunk/lib/automations.js), makes sure you import your automation configuration into this file and add it to the `moduleNames` array. So for example, if your automation was setup in `lib/automations/my-automation`, you would have something like this in the file after your changes:
7676

77-
const todos = require( './automations/todos' );
78-
const myAutomation = require( './automations/my-automation' );
77+
```js
78+
const todos = require('./automations/todos');
79+
const myAutomation = require('./automations/my-automation');
7980
80-
const moduleNames = [ todos, myAutomation ];
81+
const moduleNames = [todos, myAutomation];
8182
8283
/**
8384
* @typedef {import('./typedefs').AutomationTask} AutomationTask
@@ -86,19 +87,18 @@ const moduleNames = [ todos, myAutomation ];
8687
/**
8788
* @type {AutomationTask[]}
8889
*/
89-
const automations = moduleNames.map( ( module ) => module );
90+
const automations = moduleNames.map((module) => module);
9091
9192
module.exports = automations;
9293
```
9394

94-
- make sure you list your automation name and a brief description of what it does in the **Available Automations** section of this readme file.
95+
- make sure you list your automation name and a brief description of what it does in the **Available Automations** section of this readme file.
9596

9697
That's it!
9798

9899
Don't forget to add tests for your automation. There are various helpers available for mocking the `context` and `octokit` values (you can view the various todos automation tests for examples).
99100

100-
101101
## Credits
102102

103-
- Thanks to the work of the [Gutenberg team](https://github.com/wordpress/gutenberg) (particularly [@aduth](https://github.com/aduth)) in providing some inspiration for this approach to bundling various automations together.
104-
- The `todos` automation was inspired by this [todo probot app](https://github.com/JasonEtco/todo). Initial iterations of this action borrowed heavily from the ideas in this app.
103+
- Thanks to the work of the [Gutenberg team](https://github.com/wordpress/gutenberg) (particularly [@aduth](https://github.com/aduth)) in providing some inspiration for this approach to bundling various automations together.
104+
- The `todos` automation was inspired by this [todo probot app](https://github.com/JasonEtco/todo). Initial iterations of this action borrowed heavily from the ideas in this app.

dist/index.js

Lines changed: 161 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/automations.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
module.exports = [
99
require( './automations/todos' ),
1010
require( './automations/release' ),
11+
require( './automations/assign-milestone' ),
1112
];
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Assign Milestone Automation
2+
3+
When a pull request is approved and is not already assigned a milestone, this automation will assign the next milestone to it
4+
automatically.
5+
6+
## Usage
7+
8+
To implement this action, include it in your workflow configuration file:
9+
10+
```yaml
11+
on:
12+
pull_request:
13+
types: [opened, synchronize, closed]
14+
push:
15+
issues:
16+
types: [edited]
17+
jobs:
18+
pull-request-automation:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: woocommerce/automations@v1
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
# This can be a comma delimited list of automations to run, in this case we're just executing assign-milestone
25+
automations: assign-milestone
26+
```
27+
28+
## API
29+
30+
### Inputs
31+
32+
- `github_token`: Required. GitHub API token to use for making API requests. You can use the default `secrets.GITHUB_TOKEN` used by GitHub actions or store a different one in the secrets configuration of your GitHub repository.
33+
- `automations`: Optional. You can include a comma-delimited list of specific automations you want to run if you don't want to use them all in a given workflow.
34+
35+
### Outputs
36+
37+
_None._
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const runner = require( './runner' );
2+
3+
module.exports = {
4+
name: 'assign-milestone',
5+
events: [ 'pull_request_review' ],
6+
actions: [ 'submitted', 'edited' ],
7+
runner,
8+
};

0 commit comments

Comments
 (0)