-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlabeler.ts
31 lines (30 loc) · 1.79 KB
/
labeler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import type {Preset} from '.'
import * as jsYaml from 'js-yaml'
import type {PackageGlobbable} from './util/monorepo'
import {getLeafPackages} from './util/monorepo'
/**
* Generates a yaml config for the [GitHub Pull Request Labeler Action](https://github.com/actions/labeler).
* Creates a label per package name, which will be applied to any file modified under the leaf package path.
* When packages are added or removed from the repo, or renamed, the yaml config will stay in sync with them.
* Additional labels can be added outside of the generated code block.
* See https://github.com/mmkal/ts/tree/main/.github/labeler.yml for an example.
*
* ##### Example
* ```yaml
* # codegen:start {preset: labeler}
* ```
*
* *Note*: eslint and related tools make it quite difficult to lint github action yaml files. To get it working, you'll need to:
* - add `'!.github'` to your `.eslintignore` file, or the `ignorePatterns` property in your lint config.
* - {vscode} add `"yaml"` to the `"eslint.validate"` list in `vscode/settings.json`.
* - {@typescript/eslint} add `'.yml'` (and/or `'.yaml'`) to the `parserOptions.extraFileExtensions` list in your lint config.
* - {@typescript/eslint} explicitly include 'hidden' files (with paths starting with `.`) in your tsconfig. See https://github.com/mmkal/ts/tree/main/tsconfig.eslint.json for an example.
*
* @param repoRoot [optional] path to the repository root. If not specified, the rule will recursively search parent directories for package.json files
*/
export const labeler: Preset<PackageGlobbable> = ({options, meta, dependencies}) => {
const packages = getLeafPackages(options.repoRoot, meta.filename, dependencies.fs)
return jsYaml.dump(
Object.fromEntries(packages.map(p => [p.packageJson.name, [p.path.replace(/package\.json$/, '**/*')]])),
)
}