Skip to content

Commit

Permalink
feat(generate-paths-matrix): allow glob to override filter (#40)
Browse files Browse the repository at this point in the history
* feat(generate-path-matrix): add filtering by glob

* fix: updated logic

Co-authored-by: spincsak <[email protected]>
  • Loading branch information
spincsak and spincsak authored Dec 15, 2021
1 parent f193f81 commit 5cc73b0
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 8 deletions.
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ inputs:
note:
description: 'The body text that should be added into a Project Card'
required: false
project_origin_column_name:
project_origin_column_name:
description: 'The name of the column from where the card should be taken'
required: false
sha:
Expand Down Expand Up @@ -94,6 +94,9 @@ inputs:
globs:
description: 'A list of file paths (newline/comma separated) using glob syntax'
required: false
override_filter_globs:
description: 'A list of file paths in glob syntax (newline/comma separated) that is used to override the filter'
required: false
outputs:
output:
description: 'The output of the helper'
Expand Down
13 changes: 11 additions & 2 deletions dist/533.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/533.index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion dist/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ inputs:
note:
description: 'The body text that should be added into a Project Card'
required: false
project_origin_column_name:
project_origin_column_name:
description: 'The name of the column from where the card should be taken'
required: false
sha:
Expand Down Expand Up @@ -94,6 +94,9 @@ inputs:
globs:
description: 'A list of file paths (newline/comma separated) using glob syntax'
required: false
override_filter_globs:
description: 'A list of file paths in glob syntax (newline/comma separated) that is used to override the filter'
required: false
outputs:
output:
description: 'The output of the helper'
Expand Down
2 changes: 2 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18871,11 +18871,13 @@ var map = {
"./generate-path-matrix": [
2533,
438,
228,
533
],
"./generate-path-matrix.ts": [
2533,
438,
228,
533
],
"./get-changed-files": [
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions src/helpers/generate-path-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,32 @@ limitations under the License.

import { chunk } from 'lodash';
import { getChangedFilepaths } from '../utils/get-changed-filepaths';
import micromatch from 'micromatch';

interface GeneratePathMatrix {
pull_number: string;
paths: string;
override_filter_paths?: string;
override_filter_globs?: string;
paths_no_filter?: string;
batches?: string;
}

export const generatePathMatrix = async ({ pull_number, paths, override_filter_paths, paths_no_filter, batches }: GeneratePathMatrix) => {
export const generatePathMatrix = async ({
pull_number,
paths,
override_filter_paths,
override_filter_globs,
paths_no_filter,
batches
}: GeneratePathMatrix) => {
const changedFiles = await getChangedFilepaths(pull_number);
const shouldOverrideFilter = changedFiles.some(changedFile => override_filter_paths?.split(/[\n,]/).includes(changedFile));
let shouldOverrideFilter: boolean;
if (override_filter_globs) {
shouldOverrideFilter = micromatch(changedFiles, override_filter_globs.split('\n')).length > 0;
} else {
shouldOverrideFilter = changedFiles.some(changedFile => override_filter_paths?.split(/[\n,]/).includes(changedFile));
}
const splitPaths = paths.split(/[\n,]/);
const matrixValues = shouldOverrideFilter
? splitPaths
Expand Down
38 changes: 38 additions & 0 deletions test/helpers/generate-path-matrix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,44 @@ describe('generatePathMatrix', () => {
});
});

describe('override filter globs case', () => {
const override_filter_globs = 'package.json\ntotally/crazy';

it('should call listFiles with correct params', async () => {
await generatePathMatrix({
paths,
pull_number,
override_filter_globs
});
expect(octokit.pulls.listFiles).toHaveBeenCalledWith({
pull_number: 123,
per_page: 100,
...context.repo
});
});

it('should return expected result', async () => {
const result = await generatePathMatrix({
paths,
pull_number,
override_filter_globs
});
expect(result).toEqual({
include: [
{
path: filePath1
},
{
path: filePath2
},
{
path: filePath3
}
]
});
});
});

describe('additional no-filter paths case', () => {
const extraPath = 'an/extra/path';

Expand Down

0 comments on commit 5cc73b0

Please sign in to comment.