Compare commits

..

38 Commits

Author SHA1 Message Date
MaksimZhukov
9fcb2c2f55 Merge pull request #578 from actions/dependabot/npm_and_yarn/typescript-eslint/eslint-plugin-5.59.8
Bump @typescript-eslint/eslint-plugin from 5.59.7 to 5.59.8
2023-06-05 11:48:27 +02:00
dependabot[bot]
0d06c50435 Bump @typescript-eslint/eslint-plugin from 5.59.7 to 5.59.8
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 5.59.7 to 5.59.8.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.59.8/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-05 09:45:08 +00:00
MaksimZhukov
1d399c3ab6 Merge pull request #577 from actions/dependabot/npm_and_yarn/typescript-eslint/parser-5.59.8
Bump @typescript-eslint/parser from 5.59.7 to 5.59.8
2023-06-05 11:44:17 +02:00
MaksimZhukov
82a4f6fc25 Merge pull request #316 from kachkaev/dot-option
Implement dot option
2023-06-05 11:43:35 +02:00
Alexander Kachkaev
d40596e5db micromatch → minimatch 2023-06-02 16:06:39 +01:00
MaksimZhukov
3cbc54c641 Merge pull request #451 from Youssef1313/patch-1
Simplify globbing examples in README
2023-06-01 11:57:06 +02:00
Alexander Kachkaev
639ba81ab1 Rebuild 2023-05-31 18:46:34 +01:00
Alexander Kachkaev
71d2484daa Address review comment 2023-05-31 18:46:23 +01:00
Alexander Kachkaev
59d3310a72 Rebuild 2023-05-31 17:32:09 +01:00
Youssef Victor
a78a6c7eb7 Update README.md
Co-authored-by: MaksimZhukov <46996400+MaksimZhukov@users.noreply.github.com>
2023-05-31 19:27:34 +03:00
Alexander Kachkaev
54d434dac5 Remove required: false 2023-05-31 17:23:26 +01:00
Youssef Victor
d07f38b87f Merge branch 'main' into patch-1 2023-05-31 18:46:05 +03:00
Alexander Kachkaev
e3b3815c8d Further diff reduction 2023-05-31 01:54:22 +01:00
Alexander Kachkaev
673c7e22a7 Rebuild 2023-05-31 01:50:27 +01:00
Alexander Kachkaev
44414dbc7d Fix tests 2023-05-31 01:50:00 +01:00
Alexander Kachkaev
a27020c135 Undo unwanted change in diff 2023-05-31 01:49:55 +01:00
Alexander Kachkaev
97762039fe Update build 2023-05-31 01:46:05 +01:00
Alexander Kachkaev
60f44e7cf1 Fix unrelated test 2023-05-31 01:45:27 +01:00
Alexander Kachkaev
092c979868 Update src/labeler.ts
Co-authored-by: AndreiLobanovich <andreilobanovich@github.com>
2023-05-31 01:44:56 +01:00
Alexander Kachkaev
cecbd94bd4 Merge remote-tracking branch 'u/main' into dot-option 2023-05-31 01:35:46 +01:00
dependabot[bot]
7fef7e3d17 Bump @typescript-eslint/parser from 5.59.7 to 5.59.8
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.59.7 to 5.59.8.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.59.8/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-30 15:56:35 +00:00
Alexander Kachkaev
012b89238e Merge remote-tracking branch 'u/main' into dot-option 2023-05-19 17:26:35 +01:00
Alexander Kachkaev
a7cc8a62ef Fix 2023-03-27 09:47:52 +01:00
Alexander Kachkaev
b28379f6ed Cleanup 2023-03-27 09:44:05 +01:00
Alexander Kachkaev
b898cc8e29 Merge remote-tracking branch 'u/main' into dot-option 2023-03-27 09:39:25 +01:00
Alexander Kachkaev
4a96e771de Merge branch 'main' into dot-option 2023-03-12 22:13:26 +00:00
Alexander Kachkaev
305cfeb74c Rebuild 2023-01-16 17:40:12 +00:00
Alexander Kachkaev
866eff55a5 Merge remote-tracking branch 'origin/main' into dot-option 2023-01-16 17:36:24 +00:00
Youssef Victor
b78dba3eb5 Simplify globbing examples in README 2022-10-23 04:53:56 +02:00
Alexander Kachkaev
20251547f9 Simplify glob 2022-10-05 14:37:24 +01:00
Alexander Kachkaev
d89797c51d Merge remote-tracking branch 'upstream/main' into dot-option 2022-09-14 14:54:45 +01:00
Alexander Kachkaev
f3632d3e9f Update README.md 2022-02-04 14:47:58 +00:00
Alexander Kachkaev
e05b7c1927 Update README.md 2022-02-04 14:45:39 +00:00
Alexander Kachkaev
8b8677b4ce Improve warning 2022-02-04 13:54:21 +00:00
Alexander Kachkaev
920e9b6169 Add comments 2022-02-04 13:47:52 +00:00
Alexander Kachkaev
409a5a2095 Fix typo in test caption 2022-02-04 13:34:07 +00:00
Alexander Kachkaev
6a0b7265cb Rebuild 2022-02-04 13:29:12 +00:00
Alexander Kachkaev
b0d9292064 Implement dot option 2022-02-04 13:26:54 +00:00
8 changed files with 220 additions and 129 deletions

View File

@@ -10,7 +10,7 @@ Automatically label new pull requests based on the paths of files being changed.
Create a `.github/labeler.yml` file with a list of labels and [minimatch](https://github.com/isaacs/minimatch) globs to match to apply the label. Create a `.github/labeler.yml` file with a list of labels and [minimatch](https://github.com/isaacs/minimatch) globs to match to apply the label.
The key is the name of the label in your repository that you want to add (eg: "merge conflict", "needs-updating") and the value is the path (glob) of the changed files (eg: `src/**/*`, `tests/*.spec.js`) or a match object. The key is the name of the label in your repository that you want to add (eg: "merge conflict", "needs-updating") and the value is the path (glob) of the changed files (eg: `src/**`, `tests/*.spec.js`) or a match object.
#### Match Object #### Match Object
@@ -40,12 +40,17 @@ label1:
From a boolean logic perspective, top-level match objects are `OR`-ed together and individual match rules within an object are `AND`-ed. Combined with `!` negation, you can write complex matching rules. From a boolean logic perspective, top-level match objects are `OR`-ed together and individual match rules within an object are `AND`-ed. Combined with `!` negation, you can write complex matching rules.
> ⚠️ This action uses [minimatch](https://www.npmjs.com/package/minimatch) to apply glob patterns.
> For historical reasons, paths starting with dot (e.g. `.github`) are not matched by default.
> You need to set `dot: true` to change this behavior.
> See [Inputs](#inputs) table below for details.
#### Basic Examples #### Basic Examples
```yml ```yml
# Add 'label1' to any changes within 'example' folder or any subfolders # Add 'label1' to any changes within 'example' folder or any subfolders
label1: label1:
- example/**/* - example/**
# Add 'label2' to any file changes within 'example2' folder # Add 'label2' to any file changes within 'example2' folder
label2: example2/* label2: example2/*
@@ -65,8 +70,7 @@ repo:
# Add '@domain/core' label to any change within the 'core' package # Add '@domain/core' label to any change within the 'core' package
'@domain/core': '@domain/core':
- package/core/* - package/core/**
- package/core/**/*
# Add 'test' label to any change to *.spec.js files within the source dir # Add 'test' label to any change to *.spec.js files within the source dir
test: test:
@@ -74,7 +78,7 @@ test:
# Add 'source' label to any change to src files within the source dir EXCEPT for the docs sub-folder # Add 'source' label to any change to src files within the source dir EXCEPT for the docs sub-folder
source: source:
- any: ['src/**/*', '!src/docs/*'] - any: ['src/**', '!src/docs/*']
# Add 'frontend` label to any change to *.js files as long as the `main.js` hasn't changed # Add 'frontend` label to any change to *.js files as long as the `main.js` hasn't changed
frontend: frontend:
@@ -109,8 +113,24 @@ Various inputs are defined in [`action.yml`](action.yml) to let you configure th
| - | - | - | | - | - | - |
| `repo-token` | Token to use to authorize label changes. Typically the GITHUB_TOKEN secret, with `contents:read` and `pull-requests:write` access | `github.token` | | `repo-token` | Token to use to authorize label changes. Typically the GITHUB_TOKEN secret, with `contents:read` and `pull-requests:write` access | `github.token` |
| `configuration-path` | The path to the label configuration file | `.github/labeler.yml` | | `configuration-path` | The path to the label configuration file | `.github/labeler.yml` |
| `sync-labels` | Whether or not to remove labels when matching files are reverted or no longer changed by the PR | `false`| | `sync-labels` | Whether or not to remove labels when matching files are reverted or no longer changed by the PR | `false` |
| `dot` | Whether or not to auto-include paths starting with dot (e.g. `.github`) | `false` |
# Contributions When `dot` is disabled and you want to include _all_ files in a folder:
```yml
label1:
- path/to/folder/**/*
- path/to/folder/**/.*
```
If `dot` is enabled:
```yml
label1:
- path/to/folder/**
```
## Contributions
Contributions are welcome! See the [Contributor's Guide](CONTRIBUTING.md). Contributions are welcome! See the [Contributor's Guide](CONTRIBUTING.md).

View File

@@ -15,15 +15,29 @@ const matchConfig = [{any: ['*.txt']}];
describe('checkGlobs', () => { describe('checkGlobs', () => {
it('returns true when our pattern does match changed files', () => { it('returns true when our pattern does match changed files', () => {
const changedFiles = ['foo.txt', 'bar.txt']; const changedFiles = ['foo.txt', 'bar.txt'];
const result = checkGlobs(changedFiles, matchConfig); const result = checkGlobs(changedFiles, matchConfig, false);
expect(result).toBeTruthy(); expect(result).toBeTruthy();
}); });
it('returns false when our pattern does not match changed files', () => { it('returns false when our pattern does not match changed files', () => {
const changedFiles = ['foo.docx']; const changedFiles = ['foo.docx'];
const result = checkGlobs(changedFiles, matchConfig); const result = checkGlobs(changedFiles, matchConfig, false);
expect(result).toBeFalsy(); expect(result).toBeFalsy();
}); });
it('returns false for a file starting with dot if `dot` option is false', () => {
const changedFiles = ['.foo.txt'];
const result = checkGlobs(changedFiles, matchConfig, false);
expect(result).toBeFalsy();
});
it('returns true for a file starting with dot if `dot` option is true', () => {
const changedFiles = ['.foo.txt'];
const result = checkGlobs(changedFiles, matchConfig, true);
expect(result).toBeTruthy();
});
}); });

View File

@@ -18,10 +18,27 @@ const yamlFixtures = {
'only_pdfs.yml': fs.readFileSync('__tests__/fixtures/only_pdfs.yml') 'only_pdfs.yml': fs.readFileSync('__tests__/fixtures/only_pdfs.yml')
}; };
const configureInput = (
mockInput: Partial<{
'repo-token': string;
'configuration-path': string;
'sync-labels': boolean;
dot: boolean;
}>
) => {
jest
.spyOn(core, 'getInput')
.mockImplementation((name: string, ...opts) => mockInput[name]);
jest
.spyOn(core, 'getBooleanInput')
.mockImplementation((name: string, ...opts) => mockInput[name]);
};
afterAll(() => jest.restoreAllMocks()); afterAll(() => jest.restoreAllMocks());
describe('run', () => { describe('run', () => {
it('adds labels to PRs that match our glob patterns', async () => { it('(with dot: false) adds labels to PRs that match our glob patterns', async () => {
configureInput({});
usingLabelerConfigYaml('only_pdfs.yml'); usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('foo.pdf'); mockGitHubResponseChangedFiles('foo.pdf');
@@ -37,7 +54,36 @@ describe('run', () => {
}); });
}); });
it('does not add labels to PRs that do not match our glob patterns', async () => { it('(with dot: true) adds labels to PRs that match our glob patterns', async () => {
configureInput({dot: true});
usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('.foo.pdf');
await run();
expect(removeLabelMock).toHaveBeenCalledTimes(0);
expect(addLabelsMock).toHaveBeenCalledTimes(1);
expect(addLabelsMock).toHaveBeenCalledWith({
owner: 'monalisa',
repo: 'helloworld',
issue_number: 123,
labels: ['touched-a-pdf-file']
});
});
it('(with dot: false) does not add labels to PRs that do not match our glob patterns', async () => {
configureInput({});
usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('.foo.pdf');
await run();
expect(removeLabelMock).toHaveBeenCalledTimes(0);
expect(addLabelsMock).toHaveBeenCalledTimes(0);
});
it('(with dot: true) does not add labels to PRs that do not match our glob patterns', async () => {
configureInput({dot: true});
usingLabelerConfigYaml('only_pdfs.yml'); usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('foo.txt'); mockGitHubResponseChangedFiles('foo.txt');
@@ -48,15 +94,11 @@ describe('run', () => {
}); });
it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => { it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => {
const mockInput = { configureInput({
'repo-token': 'foo', 'repo-token': 'foo',
'configuration-path': 'bar', 'configuration-path': 'bar',
'sync-labels': true 'sync-labels': true
}; });
jest
.spyOn(core, 'getInput')
.mockImplementation((name: string, ...opts) => mockInput[name]);
usingLabelerConfigYaml('only_pdfs.yml'); usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('foo.txt'); mockGitHubResponseChangedFiles('foo.txt');
@@ -79,15 +121,11 @@ describe('run', () => {
}); });
it('(with sync-labels: false) it issues no delete calls even when there are preexisting PR labels that no longer match the glob pattern', async () => { it('(with sync-labels: false) it issues no delete calls even when there are preexisting PR labels that no longer match the glob pattern', async () => {
const mockInput = { configureInput({
'repo-token': 'foo', 'repo-token': 'foo',
'configuration-path': 'bar', 'configuration-path': 'bar',
'sync-labels': false 'sync-labels': false
}; });
jest
.spyOn(core, 'getInput')
.mockImplementation((name: string, ...opts) => mockInput[name]);
usingLabelerConfigYaml('only_pdfs.yml'); usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('foo.txt'); mockGitHubResponseChangedFiles('foo.txt');

View File

@@ -14,6 +14,10 @@ inputs:
description: 'Whether or not to remove labels when matching files are reverted' description: 'Whether or not to remove labels when matching files are reverted'
default: false default: false
required: false required: false
dot:
description: 'Whether or not to auto-include paths starting with dot (e.g. `.github`)'
default: false
required: false
runs: runs:
using: 'node16' using: 'node16'

23
dist/index.js vendored
View File

@@ -49,7 +49,8 @@ function run() {
try { try {
const token = core.getInput('repo-token'); const token = core.getInput('repo-token');
const configPath = core.getInput('configuration-path', { required: true }); const configPath = core.getInput('configuration-path', { required: true });
const syncLabels = !!core.getInput('sync-labels', { required: false }); const syncLabels = !!core.getInput('sync-labels');
const dot = core.getBooleanInput('dot');
const prNumber = getPrNumber(); const prNumber = getPrNumber();
if (!prNumber) { if (!prNumber) {
core.info('Could not get pull request number from context, exiting'); core.info('Could not get pull request number from context, exiting');
@@ -68,7 +69,7 @@ function run() {
const labelsToRemove = []; const labelsToRemove = [];
for (const [label, globs] of labelGlobs.entries()) { for (const [label, globs] of labelGlobs.entries()) {
core.debug(`processing ${label}`); core.debug(`processing ${label}`);
if (checkGlobs(changedFiles, globs)) { if (checkGlobs(changedFiles, globs, dot)) {
labels.push(label); labels.push(label);
} }
else if (pullRequest.labels.find(l => l.name === label)) { else if (pullRequest.labels.find(l => l.name === label)) {
@@ -158,11 +159,11 @@ function toMatchConfig(config) {
function printPattern(matcher) { function printPattern(matcher) {
return (matcher.negate ? '!' : '') + matcher.pattern; return (matcher.negate ? '!' : '') + matcher.pattern;
} }
function checkGlobs(changedFiles, globs) { function checkGlobs(changedFiles, globs, dot) {
for (const glob of globs) { for (const glob of globs) {
core.debug(` checking pattern ${JSON.stringify(glob)}`); core.debug(` checking pattern ${JSON.stringify(glob)}`);
const matchConfig = toMatchConfig(glob); const matchConfig = toMatchConfig(glob);
if (checkMatch(changedFiles, matchConfig)) { if (checkMatch(changedFiles, matchConfig, dot)) {
return true; return true;
} }
} }
@@ -182,8 +183,8 @@ function isMatch(changedFile, matchers) {
return true; return true;
} }
// equivalent to "Array.some()" but expanded for debugging and clarity // equivalent to "Array.some()" but expanded for debugging and clarity
function checkAny(changedFiles, globs) { function checkAny(changedFiles, globs, dot) {
const matchers = globs.map(g => new minimatch_1.Minimatch(g)); const matchers = globs.map(g => new minimatch_1.Minimatch(g, { dot }));
core.debug(` checking "any" patterns`); core.debug(` checking "any" patterns`);
for (const changedFile of changedFiles) { for (const changedFile of changedFiles) {
if (isMatch(changedFile, matchers)) { if (isMatch(changedFile, matchers)) {
@@ -195,8 +196,8 @@ function checkAny(changedFiles, globs) {
return false; return false;
} }
// equivalent to "Array.every()" but expanded for debugging and clarity // equivalent to "Array.every()" but expanded for debugging and clarity
function checkAll(changedFiles, globs) { function checkAll(changedFiles, globs, dot) {
const matchers = globs.map(g => new minimatch_1.Minimatch(g)); const matchers = globs.map(g => new minimatch_1.Minimatch(g, { dot }));
core.debug(` checking "all" patterns`); core.debug(` checking "all" patterns`);
for (const changedFile of changedFiles) { for (const changedFile of changedFiles) {
if (!isMatch(changedFile, matchers)) { if (!isMatch(changedFile, matchers)) {
@@ -207,14 +208,14 @@ function checkAll(changedFiles, globs) {
core.debug(` "all" patterns matched all files`); core.debug(` "all" patterns matched all files`);
return true; return true;
} }
function checkMatch(changedFiles, matchConfig) { function checkMatch(changedFiles, matchConfig, dot) {
if (matchConfig.all !== undefined) { if (matchConfig.all !== undefined) {
if (!checkAll(changedFiles, matchConfig.all)) { if (!checkAll(changedFiles, matchConfig.all, dot)) {
return false; return false;
} }
} }
if (matchConfig.any !== undefined) { if (matchConfig.any !== undefined) {
if (!checkAny(changedFiles, matchConfig.any)) { if (!checkAny(changedFiles, matchConfig.any, dot)) {
return false; return false;
} }
} }

164
package-lock.json generated
View File

@@ -19,8 +19,8 @@
"@types/js-yaml": "^4.0.5", "@types/js-yaml": "^4.0.5",
"@types/minimatch": "^5.1.2", "@types/minimatch": "^5.1.2",
"@types/node": "^16.11.7", "@types/node": "^16.11.7",
"@typescript-eslint/eslint-plugin": "^5.59.7", "@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.7", "@typescript-eslint/parser": "^5.59.8",
"@vercel/ncc": "^0.36.1", "@vercel/ncc": "^0.36.1",
"eslint": "^8.41.0", "eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0", "eslint-config-prettier": "^8.8.0",
@@ -1423,15 +1423,15 @@
"dev": true "dev": true
}, },
"node_modules/@typescript-eslint/eslint-plugin": { "node_modules/@typescript-eslint/eslint-plugin": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.8.tgz",
"integrity": "sha512-BL+jYxUFIbuYwy+4fF86k5vdT9lT0CNJ6HtwrIvGh0PhH8s0yy5rjaKH2fDCrz5ITHy07WCzVGNvAmjJh4IJFA==", "integrity": "sha512-JDMOmhXteJ4WVKOiHXGCoB96ADWg9q7efPWHRViT/f09bA8XOMLAVHHju3l0MkZnG1izaWXYmgvQcUjTRcpShQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@eslint-community/regexpp": "^4.4.0", "@eslint-community/regexpp": "^4.4.0",
"@typescript-eslint/scope-manager": "5.59.7", "@typescript-eslint/scope-manager": "5.59.8",
"@typescript-eslint/type-utils": "5.59.7", "@typescript-eslint/type-utils": "5.59.8",
"@typescript-eslint/utils": "5.59.7", "@typescript-eslint/utils": "5.59.8",
"debug": "^4.3.4", "debug": "^4.3.4",
"grapheme-splitter": "^1.0.4", "grapheme-splitter": "^1.0.4",
"ignore": "^5.2.0", "ignore": "^5.2.0",
@@ -1490,14 +1490,14 @@
"dev": true "dev": true
}, },
"node_modules/@typescript-eslint/parser": { "node_modules/@typescript-eslint/parser": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.59.8.tgz",
"integrity": "sha512-VhpsIEuq/8i5SF+mPg9jSdIwgMBBp0z9XqjiEay+81PYLJuroN+ET1hM5IhkiYMJd9MkTz8iJLt7aaGAgzWUbQ==", "integrity": "sha512-AnR19RjJcpjoeGojmwZtCwBX/RidqDZtzcbG3xHrmz0aHHoOcbWnpDllenRDmDvsV0RQ6+tbb09/kyc+UT9Orw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/scope-manager": "5.59.7", "@typescript-eslint/scope-manager": "5.59.8",
"@typescript-eslint/types": "5.59.7", "@typescript-eslint/types": "5.59.8",
"@typescript-eslint/typescript-estree": "5.59.7", "@typescript-eslint/typescript-estree": "5.59.8",
"debug": "^4.3.4" "debug": "^4.3.4"
}, },
"engines": { "engines": {
@@ -1517,13 +1517,13 @@
} }
}, },
"node_modules/@typescript-eslint/scope-manager": { "node_modules/@typescript-eslint/scope-manager": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.59.8.tgz",
"integrity": "sha512-FL6hkYWK9zBGdxT2wWEd2W8ocXMu3K94i3gvMrjXpx+koFYdYV7KprKfirpgY34vTGzEPPuKoERpP8kD5h7vZQ==", "integrity": "sha512-/w08ndCYI8gxGf+9zKf1vtx/16y8MHrZs5/tnjHhMLNSixuNcJavSX4wAiPf4aS5x41Es9YPCn44MIe4cxIlig==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.59.7", "@typescript-eslint/types": "5.59.8",
"@typescript-eslint/visitor-keys": "5.59.7" "@typescript-eslint/visitor-keys": "5.59.8"
}, },
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@@ -1534,13 +1534,13 @@
} }
}, },
"node_modules/@typescript-eslint/type-utils": { "node_modules/@typescript-eslint/type-utils": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.59.8.tgz",
"integrity": "sha512-ozuz/GILuYG7osdY5O5yg0QxXUAEoI4Go3Do5xeu+ERH9PorHBPSdvD3Tjp2NN2bNLh1NJQSsQu2TPu/Ly+HaQ==", "integrity": "sha512-+5M518uEIHFBy3FnyqZUF3BMP+AXnYn4oyH8RF012+e7/msMY98FhGL5SrN29NQ9xDgvqCgYnsOiKp1VjZ/fpA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/typescript-estree": "5.59.7", "@typescript-eslint/typescript-estree": "5.59.8",
"@typescript-eslint/utils": "5.59.7", "@typescript-eslint/utils": "5.59.8",
"debug": "^4.3.4", "debug": "^4.3.4",
"tsutils": "^3.21.0" "tsutils": "^3.21.0"
}, },
@@ -1561,9 +1561,9 @@
} }
}, },
"node_modules/@typescript-eslint/types": { "node_modules/@typescript-eslint/types": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.59.8.tgz",
"integrity": "sha512-UnVS2MRRg6p7xOSATscWkKjlf/NDKuqo5TdbWck6rIRZbmKpVNTLALzNvcjIfHBE7736kZOFc/4Z3VcZwuOM/A==", "integrity": "sha512-+uWuOhBTj/L6awoWIg0BlWy0u9TyFpCHrAuQ5bNfxDaZ1Ppb3mx6tUigc74LHcbHpOHuOTOJrBoAnhdHdaea1w==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@@ -1574,13 +1574,13 @@
} }
}, },
"node_modules/@typescript-eslint/typescript-estree": { "node_modules/@typescript-eslint/typescript-estree": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.8.tgz",
"integrity": "sha512-4A1NtZ1I3wMN2UGDkU9HMBL+TIQfbrh4uS0WDMMpf3xMRursDbqEf1ahh6vAAe3mObt8k3ZATnezwG4pdtWuUQ==", "integrity": "sha512-Jy/lPSDJGNow14vYu6IrW790p7HIf/SOV1Bb6lZ7NUkLc2iB2Z9elESmsaUtLw8kVqogSbtLH9tut5GCX1RLDg==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.59.7", "@typescript-eslint/types": "5.59.8",
"@typescript-eslint/visitor-keys": "5.59.7", "@typescript-eslint/visitor-keys": "5.59.8",
"debug": "^4.3.4", "debug": "^4.3.4",
"globby": "^11.1.0", "globby": "^11.1.0",
"is-glob": "^4.0.3", "is-glob": "^4.0.3",
@@ -1634,17 +1634,17 @@
"dev": true "dev": true
}, },
"node_modules/@typescript-eslint/utils": { "node_modules/@typescript-eslint/utils": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.59.8.tgz",
"integrity": "sha512-yCX9WpdQKaLufz5luG4aJbOpdXf/fjwGMcLFXZVPUz3QqLirG5QcwwnIHNf8cjLjxK4qtzTO8udUtMQSAToQnQ==", "integrity": "sha512-Tr65630KysnNn9f9G7ROF3w1b5/7f6QVCJ+WK9nhIocWmx9F+TmCAcglF26Vm7z8KCTwoKcNEBZrhlklla3CKg==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/eslint-utils": "^4.2.0",
"@types/json-schema": "^7.0.9", "@types/json-schema": "^7.0.9",
"@types/semver": "^7.3.12", "@types/semver": "^7.3.12",
"@typescript-eslint/scope-manager": "5.59.7", "@typescript-eslint/scope-manager": "5.59.8",
"@typescript-eslint/types": "5.59.7", "@typescript-eslint/types": "5.59.8",
"@typescript-eslint/typescript-estree": "5.59.7", "@typescript-eslint/typescript-estree": "5.59.8",
"eslint-scope": "^5.1.1", "eslint-scope": "^5.1.1",
"semver": "^7.3.7" "semver": "^7.3.7"
}, },
@@ -1693,12 +1693,12 @@
"dev": true "dev": true
}, },
"node_modules/@typescript-eslint/visitor-keys": { "node_modules/@typescript-eslint/visitor-keys": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.8.tgz",
"integrity": "sha512-tyN+X2jvMslUszIiYbF0ZleP+RqQsFVpGrKI6e0Eet1w8WmhsAtmzaqm8oM8WJQ1ysLwhnsK/4hYHJjOgJVfQQ==", "integrity": "sha512-pJhi2ms0x0xgloT7xYabil3SGGlojNNKjK/q6dB3Ey0uJLMjK2UDGJvHieiyJVW/7C3KI+Z4Q3pEHkm4ejA+xQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.59.7", "@typescript-eslint/types": "5.59.8",
"eslint-visitor-keys": "^3.3.0" "eslint-visitor-keys": "^3.3.0"
}, },
"engines": { "engines": {
@@ -6996,15 +6996,15 @@
"dev": true "dev": true
}, },
"@typescript-eslint/eslint-plugin": { "@typescript-eslint/eslint-plugin": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.8.tgz",
"integrity": "sha512-BL+jYxUFIbuYwy+4fF86k5vdT9lT0CNJ6HtwrIvGh0PhH8s0yy5rjaKH2fDCrz5ITHy07WCzVGNvAmjJh4IJFA==", "integrity": "sha512-JDMOmhXteJ4WVKOiHXGCoB96ADWg9q7efPWHRViT/f09bA8XOMLAVHHju3l0MkZnG1izaWXYmgvQcUjTRcpShQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@eslint-community/regexpp": "^4.4.0", "@eslint-community/regexpp": "^4.4.0",
"@typescript-eslint/scope-manager": "5.59.7", "@typescript-eslint/scope-manager": "5.59.8",
"@typescript-eslint/type-utils": "5.59.7", "@typescript-eslint/type-utils": "5.59.8",
"@typescript-eslint/utils": "5.59.7", "@typescript-eslint/utils": "5.59.8",
"debug": "^4.3.4", "debug": "^4.3.4",
"grapheme-splitter": "^1.0.4", "grapheme-splitter": "^1.0.4",
"ignore": "^5.2.0", "ignore": "^5.2.0",
@@ -7040,53 +7040,53 @@
} }
}, },
"@typescript-eslint/parser": { "@typescript-eslint/parser": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.59.8.tgz",
"integrity": "sha512-VhpsIEuq/8i5SF+mPg9jSdIwgMBBp0z9XqjiEay+81PYLJuroN+ET1hM5IhkiYMJd9MkTz8iJLt7aaGAgzWUbQ==", "integrity": "sha512-AnR19RjJcpjoeGojmwZtCwBX/RidqDZtzcbG3xHrmz0aHHoOcbWnpDllenRDmDvsV0RQ6+tbb09/kyc+UT9Orw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/scope-manager": "5.59.7", "@typescript-eslint/scope-manager": "5.59.8",
"@typescript-eslint/types": "5.59.7", "@typescript-eslint/types": "5.59.8",
"@typescript-eslint/typescript-estree": "5.59.7", "@typescript-eslint/typescript-estree": "5.59.8",
"debug": "^4.3.4" "debug": "^4.3.4"
} }
}, },
"@typescript-eslint/scope-manager": { "@typescript-eslint/scope-manager": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.59.8.tgz",
"integrity": "sha512-FL6hkYWK9zBGdxT2wWEd2W8ocXMu3K94i3gvMrjXpx+koFYdYV7KprKfirpgY34vTGzEPPuKoERpP8kD5h7vZQ==", "integrity": "sha512-/w08ndCYI8gxGf+9zKf1vtx/16y8MHrZs5/tnjHhMLNSixuNcJavSX4wAiPf4aS5x41Es9YPCn44MIe4cxIlig==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/types": "5.59.7", "@typescript-eslint/types": "5.59.8",
"@typescript-eslint/visitor-keys": "5.59.7" "@typescript-eslint/visitor-keys": "5.59.8"
} }
}, },
"@typescript-eslint/type-utils": { "@typescript-eslint/type-utils": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.59.8.tgz",
"integrity": "sha512-ozuz/GILuYG7osdY5O5yg0QxXUAEoI4Go3Do5xeu+ERH9PorHBPSdvD3Tjp2NN2bNLh1NJQSsQu2TPu/Ly+HaQ==", "integrity": "sha512-+5M518uEIHFBy3FnyqZUF3BMP+AXnYn4oyH8RF012+e7/msMY98FhGL5SrN29NQ9xDgvqCgYnsOiKp1VjZ/fpA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/typescript-estree": "5.59.7", "@typescript-eslint/typescript-estree": "5.59.8",
"@typescript-eslint/utils": "5.59.7", "@typescript-eslint/utils": "5.59.8",
"debug": "^4.3.4", "debug": "^4.3.4",
"tsutils": "^3.21.0" "tsutils": "^3.21.0"
} }
}, },
"@typescript-eslint/types": { "@typescript-eslint/types": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.59.8.tgz",
"integrity": "sha512-UnVS2MRRg6p7xOSATscWkKjlf/NDKuqo5TdbWck6rIRZbmKpVNTLALzNvcjIfHBE7736kZOFc/4Z3VcZwuOM/A==", "integrity": "sha512-+uWuOhBTj/L6awoWIg0BlWy0u9TyFpCHrAuQ5bNfxDaZ1Ppb3mx6tUigc74LHcbHpOHuOTOJrBoAnhdHdaea1w==",
"dev": true "dev": true
}, },
"@typescript-eslint/typescript-estree": { "@typescript-eslint/typescript-estree": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.8.tgz",
"integrity": "sha512-4A1NtZ1I3wMN2UGDkU9HMBL+TIQfbrh4uS0WDMMpf3xMRursDbqEf1ahh6vAAe3mObt8k3ZATnezwG4pdtWuUQ==", "integrity": "sha512-Jy/lPSDJGNow14vYu6IrW790p7HIf/SOV1Bb6lZ7NUkLc2iB2Z9elESmsaUtLw8kVqogSbtLH9tut5GCX1RLDg==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/types": "5.59.7", "@typescript-eslint/types": "5.59.8",
"@typescript-eslint/visitor-keys": "5.59.7", "@typescript-eslint/visitor-keys": "5.59.8",
"debug": "^4.3.4", "debug": "^4.3.4",
"globby": "^11.1.0", "globby": "^11.1.0",
"is-glob": "^4.0.3", "is-glob": "^4.0.3",
@@ -7121,17 +7121,17 @@
} }
}, },
"@typescript-eslint/utils": { "@typescript-eslint/utils": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.59.8.tgz",
"integrity": "sha512-yCX9WpdQKaLufz5luG4aJbOpdXf/fjwGMcLFXZVPUz3QqLirG5QcwwnIHNf8cjLjxK4qtzTO8udUtMQSAToQnQ==", "integrity": "sha512-Tr65630KysnNn9f9G7ROF3w1b5/7f6QVCJ+WK9nhIocWmx9F+TmCAcglF26Vm7z8KCTwoKcNEBZrhlklla3CKg==",
"dev": true, "dev": true,
"requires": { "requires": {
"@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/eslint-utils": "^4.2.0",
"@types/json-schema": "^7.0.9", "@types/json-schema": "^7.0.9",
"@types/semver": "^7.3.12", "@types/semver": "^7.3.12",
"@typescript-eslint/scope-manager": "5.59.7", "@typescript-eslint/scope-manager": "5.59.8",
"@typescript-eslint/types": "5.59.7", "@typescript-eslint/types": "5.59.8",
"@typescript-eslint/typescript-estree": "5.59.7", "@typescript-eslint/typescript-estree": "5.59.8",
"eslint-scope": "^5.1.1", "eslint-scope": "^5.1.1",
"semver": "^7.3.7" "semver": "^7.3.7"
}, },
@@ -7163,12 +7163,12 @@
} }
}, },
"@typescript-eslint/visitor-keys": { "@typescript-eslint/visitor-keys": {
"version": "5.59.7", "version": "5.59.8",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.7.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.8.tgz",
"integrity": "sha512-tyN+X2jvMslUszIiYbF0ZleP+RqQsFVpGrKI6e0Eet1w8WmhsAtmzaqm8oM8WJQ1ysLwhnsK/4hYHJjOgJVfQQ==", "integrity": "sha512-pJhi2ms0x0xgloT7xYabil3SGGlojNNKjK/q6dB3Ey0uJLMjK2UDGJvHieiyJVW/7C3KI+Z4Q3pEHkm4ejA+xQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/types": "5.59.7", "@typescript-eslint/types": "5.59.8",
"eslint-visitor-keys": "^3.3.0" "eslint-visitor-keys": "^3.3.0"
} }
}, },

View File

@@ -34,8 +34,8 @@
"@types/js-yaml": "^4.0.5", "@types/js-yaml": "^4.0.5",
"@types/minimatch": "^5.1.2", "@types/minimatch": "^5.1.2",
"@types/node": "^16.11.7", "@types/node": "^16.11.7",
"@typescript-eslint/eslint-plugin": "^5.59.7", "@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.7", "@typescript-eslint/parser": "^5.59.8",
"@vercel/ncc": "^0.36.1", "@vercel/ncc": "^0.36.1",
"eslint": "^8.41.0", "eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0", "eslint-config-prettier": "^8.8.0",

View File

@@ -15,7 +15,8 @@ export async function run() {
try { try {
const token = core.getInput('repo-token'); const token = core.getInput('repo-token');
const configPath = core.getInput('configuration-path', {required: true}); const configPath = core.getInput('configuration-path', {required: true});
const syncLabels = !!core.getInput('sync-labels', {required: false}); const syncLabels = !!core.getInput('sync-labels');
const dot = core.getBooleanInput('dot');
const prNumber = getPrNumber(); const prNumber = getPrNumber();
if (!prNumber) { if (!prNumber) {
@@ -42,7 +43,7 @@ export async function run() {
const labelsToRemove: string[] = []; const labelsToRemove: string[] = [];
for (const [label, globs] of labelGlobs.entries()) { for (const [label, globs] of labelGlobs.entries()) {
core.debug(`processing ${label}`); core.debug(`processing ${label}`);
if (checkGlobs(changedFiles, globs)) { if (checkGlobs(changedFiles, globs, dot)) {
labels.push(label); labels.push(label);
} else if (pullRequest.labels.find(l => l.name === label)) { } else if (pullRequest.labels.find(l => l.name === label)) {
labelsToRemove.push(label); labelsToRemove.push(label);
@@ -157,12 +158,13 @@ function printPattern(matcher: Minimatch): string {
export function checkGlobs( export function checkGlobs(
changedFiles: string[], changedFiles: string[],
globs: StringOrMatchConfig[] globs: StringOrMatchConfig[],
dot: boolean
): boolean { ): boolean {
for (const glob of globs) { for (const glob of globs) {
core.debug(` checking pattern ${JSON.stringify(glob)}`); core.debug(` checking pattern ${JSON.stringify(glob)}`);
const matchConfig = toMatchConfig(glob); const matchConfig = toMatchConfig(glob);
if (checkMatch(changedFiles, matchConfig)) { if (checkMatch(changedFiles, matchConfig, dot)) {
return true; return true;
} }
} }
@@ -184,8 +186,12 @@ function isMatch(changedFile: string, matchers: Minimatch[]): boolean {
} }
// equivalent to "Array.some()" but expanded for debugging and clarity // equivalent to "Array.some()" but expanded for debugging and clarity
function checkAny(changedFiles: string[], globs: string[]): boolean { function checkAny(
const matchers = globs.map(g => new Minimatch(g)); changedFiles: string[],
globs: string[],
dot: boolean
): boolean {
const matchers = globs.map(g => new Minimatch(g, {dot}));
core.debug(` checking "any" patterns`); core.debug(` checking "any" patterns`);
for (const changedFile of changedFiles) { for (const changedFile of changedFiles) {
if (isMatch(changedFile, matchers)) { if (isMatch(changedFile, matchers)) {
@@ -199,8 +205,12 @@ function checkAny(changedFiles: string[], globs: string[]): boolean {
} }
// equivalent to "Array.every()" but expanded for debugging and clarity // equivalent to "Array.every()" but expanded for debugging and clarity
function checkAll(changedFiles: string[], globs: string[]): boolean { function checkAll(
const matchers = globs.map(g => new Minimatch(g)); changedFiles: string[],
globs: string[],
dot: boolean
): boolean {
const matchers = globs.map(g => new Minimatch(g, {dot}));
core.debug(` checking "all" patterns`); core.debug(` checking "all" patterns`);
for (const changedFile of changedFiles) { for (const changedFile of changedFiles) {
if (!isMatch(changedFile, matchers)) { if (!isMatch(changedFile, matchers)) {
@@ -213,15 +223,19 @@ function checkAll(changedFiles: string[], globs: string[]): boolean {
return true; return true;
} }
function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean { function checkMatch(
changedFiles: string[],
matchConfig: MatchConfig,
dot: boolean
): boolean {
if (matchConfig.all !== undefined) { if (matchConfig.all !== undefined) {
if (!checkAll(changedFiles, matchConfig.all)) { if (!checkAll(changedFiles, matchConfig.all, dot)) {
return false; return false;
} }
} }
if (matchConfig.any !== undefined) { if (matchConfig.any !== undefined) {
if (!checkAny(changedFiles, matchConfig.any)) { if (!checkAny(changedFiles, matchConfig.any, dot)) {
return false; return false;
} }
} }