Skip to content

Commit 02e14ae

Browse files
committed
feat: Introduce filterFiles argument
1 parent d4cacf0 commit 02e14ae

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

.changeset/light-days-fry.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@changesets/ghcommit": minor
3+
---
4+
5+
Introduce `filterFiles` argument for `commitChangesFromRepo`
6+
7+
Allow for a custom function to be specified to filter which files should be
8+
included in the commit

src/git.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const commitChangesFromRepo = async ({
2121
base,
2222
repoDirectory,
2323
addFromDirectory,
24+
filterFiles,
2425
log,
2526
...otherArgs
2627
}: CommitChangesFromRepoArgs): Promise<CommitFilesResult> => {
@@ -91,6 +92,10 @@ export const commitChangesFromRepo = async ({
9192
// Iterate through these directories
9293
return true;
9394
}
95+
if (filterFiles && !filterFiles(filepath)) {
96+
// Ignore out files that don't match any specified filter
97+
return null;
98+
}
9499
if (!workdir) {
95100
// File was deleted
96101
deletions.push(filepath);

src/interface.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,11 @@ export interface CommitChangesFromRepoArgs extends CommitFilesBasedArgs {
120120
* which will add all changed files in the repository.
121121
*/
122122
addFromDirectory?: string;
123+
/**
124+
* An optional function that can be used to filter which files are included
125+
* in the commit. True should be returned for files that should be included.
126+
*
127+
* By default, all files are included.
128+
*/
129+
filterFiles?: (file: string) => boolean;
123130
}

0 commit comments

Comments
 (0)