-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1554 from intuit/pr-label-body
Add pr-body-labels plugin
- Loading branch information
Showing
15 changed files
with
277 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
# What Changed | ||
|
||
# Why | ||
## Why | ||
|
||
Todo: | ||
|
||
- [ ] Add tests | ||
- [ ] Add docs | ||
|
||
## Change Type | ||
|
||
Indicate the type of change your pull request is: | ||
|
||
- [ ] `documentation` | ||
- [ ] `patch` | ||
- [ ] `minor` | ||
- [ ] `major` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Pr-Body-Labels Plugin | ||
|
||
Allow outside contributors to indicate what semver label should be applied to the Pull Request. | ||
|
||
## Installation | ||
|
||
This plugin is not included with the `auto` CLI installed via NPM. To install: | ||
|
||
```bash | ||
npm i --save-dev @auto-it/pr-body-labels | ||
# or | ||
yarn add -D @auto-it/pr-body-labels | ||
``` | ||
|
||
## Usage | ||
|
||
```json | ||
{ | ||
"plugins": [ | ||
["pr-body-labels"] | ||
// other plugins | ||
] | ||
} | ||
``` | ||
|
||
Then something like the following to your `.github/PULL_REQUEST_TEMPLATE.md`. | ||
The only part of this that really matters is a markdown checkbox + one of your labels. | ||
You control what labels an outside contributor can apply through the PR body. | ||
This example only exposes the semantic versioning labels but you can include any label in your project. | ||
|
||
```md | ||
## Change Type | ||
|
||
Indicate the type of change your pull request is: | ||
|
||
- [ ] `patch` | ||
- [ ] `minor` | ||
- [ ] `major` | ||
``` | ||
|
||
## Options | ||
|
||
### `disabledLabels` | ||
|
||
Labels the user cannot apply through the PR. | ||
|
||
```json | ||
{ | ||
"plugins": [["pr-body-labels", { "disabledLabels": ["release"] }]] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { makeHooks } from "@auto-it/core/dist/utils/make-hooks"; | ||
|
||
import PrBodyLabels from "../src"; | ||
|
||
describe("Pr-Body-Labels Plugin", () => { | ||
test("not add labels not present in project", async () => { | ||
const plugin = new PrBodyLabels(); | ||
const hooks = makeHooks(); | ||
const addLabelToPr = jest.fn(); | ||
|
||
plugin.apply({ | ||
hooks, | ||
labels: [], | ||
git: { addLabelToPr }, | ||
} as any); | ||
|
||
await hooks.prCheck.promise({ | ||
pr: { body: "- [x] `unknown-label`" }, | ||
} as any); | ||
expect(addLabelToPr).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test("add labels present in project", async () => { | ||
const plugin = new PrBodyLabels(); | ||
const hooks = makeHooks(); | ||
const addLabelToPr = jest.fn(); | ||
|
||
plugin.apply({ | ||
hooks, | ||
labels: [{ name: "patch" }], | ||
git: { addLabelToPr }, | ||
} as any); | ||
|
||
await hooks.prCheck.promise({ | ||
pr: { body: "- [x] `patch`", number: 1 }, | ||
} as any); | ||
expect(addLabelToPr).toHaveBeenCalledWith(1, "patch"); | ||
}); | ||
|
||
test("not add labels in disabledLabels list", async () => { | ||
const plugin = new PrBodyLabels({ disabledLabels: ["patch"] }); | ||
const hooks = makeHooks(); | ||
const addLabelToPr = jest.fn(); | ||
|
||
plugin.apply({ | ||
hooks, | ||
labels: [{ name: "patch" }], | ||
git: { addLabelToPr }, | ||
} as any); | ||
|
||
await hooks.prCheck.promise({ | ||
pr: { body: "- [x] `patch`", number: 1 }, | ||
} as any); | ||
expect(addLabelToPr).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "@auto-it/pr-body-labels", | ||
"version": "9.53.1", | ||
"main": "dist/index.js", | ||
"description": "Allow outside contributors to indicate what semver label should be applied to the Pull Request", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Andrew Lisowski", | ||
"email": "lisowski54@gmail.com" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/", | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/intuit/auto" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"automation", | ||
"semantic", | ||
"release", | ||
"github", | ||
"labels", | ||
"automated", | ||
"continuos integration", | ||
"changelog" | ||
], | ||
"scripts": { | ||
"build": "tsc -b", | ||
"start": "npm run build -- -w", | ||
"lint": "eslint src --ext .ts", | ||
"test": "jest --maxWorkers=2 --config ../../package.json" | ||
}, | ||
"dependencies": { | ||
"@auto-it/core": "link:../../packages/core", | ||
"fp-ts": "^2.5.3", | ||
"io-ts": "^2.1.2", | ||
"tslib": "1.10.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Auto, IPlugin } from "@auto-it/core"; | ||
import * as t from "io-ts"; | ||
|
||
const pluginOptions = t.partial({ | ||
/** Labels the user cannot apply through the PR */ | ||
disabledLabels: t.array(t.string), | ||
}); | ||
|
||
export type IPrBodyLabelsPluginOptions = t.TypeOf<typeof pluginOptions>; | ||
|
||
/** Allow outside contributors to indicate what semver label should be applied to the Pull Request */ | ||
export default class PrBodyLabelsPlugin implements IPlugin { | ||
/** The name of the plugin */ | ||
name = "pr-body-labels"; | ||
|
||
/** The options of the plugin */ | ||
private readonly options: Required<IPrBodyLabelsPluginOptions>; | ||
|
||
/** Initialize the plugin with it's options */ | ||
constructor(options: IPrBodyLabelsPluginOptions = {}) { | ||
this.options = { | ||
disabledLabels: options.disabledLabels || [], | ||
}; | ||
} | ||
|
||
/** Tap into auto plugin points. */ | ||
apply(auto: Auto) { | ||
auto.hooks.prCheck.tapPromise(this.name, async ({ pr }) => { | ||
if (!auto.git || !auto.labels) { | ||
return; | ||
} | ||
|
||
await Promise.all( | ||
auto.labels.map(async (label) => { | ||
if ( | ||
pr.body.includes(`- [x] \`${label.name}\``) && | ||
!this.options.disabledLabels.includes(label.name) | ||
) { | ||
await auto.git?.addLabelToPr(pr.number, label.name); | ||
} | ||
}) | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src/**/*", "../../typings/**/*"], | ||
|
||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"rootDir": "./src", | ||
"composite": true | ||
}, | ||
|
||
"references": [ | ||
{ | ||
"path": "../../packages/core" | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,9 @@ | |
}, | ||
{ | ||
"path": "plugins/docker" | ||
}, | ||
{ | ||
"path": "plugins/pr-body-labels" | ||
} | ||
] | ||
} | ||
} |