Skip to content

Commit ae16557

Browse files
authored
Add the ability to configure ignoredFiles (#236)
* Add the ability to configure ignoredFiles * doc tweak
1 parent c5977c7 commit ae16557

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ affectedModuleDetector {
9292
excludedModules = [
9393
"sample-util", ":(app|library):.+"
9494
]
95+
ignoredFiles = [
96+
".*\\.md", ".*\\.txt", ".*README"
97+
]
9598
includeUncommitted = true
9699
top = "HEAD"
97100
customTasks = [
@@ -109,6 +112,7 @@ affectedModuleDetector {
109112
- `logFilename`: A filename for the output detector to use
110113
- `logFolder`: A folder to output the log file in
111114
- `specifiedBranch`: A branch to specify changes against. Must be used in combination with configuration `compareFrom = "SpecifiedBranchCommit"`
115+
- `ignoredFiles`: A set of files that will be filtered out of the list of changed files retrieved by git.
112116
- `compareFrom`: A commit to compare the branch changes against. Can be either:
113117
- PreviousCommit: compare against the previous commit
114118
- ForkCommit: compare against the commit the branch was forked from

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ class AffectedModuleConfiguration {
105105
*/
106106
var excludedModules = emptySet<String>()
107107

108+
/**
109+
* A set of files that will be filtered out of the list of changed files retrieved by git.
110+
*/
111+
var ignoredFiles = emptySet<String>()
112+
108113
/**
109114
* If uncommitted files should be considered affected
110115
*/

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ class AffectedModuleDetectorImpl constructor(
330330
injectedGitClient ?: GitClientImpl(
331331
rootProject.projectDir,
332332
logger,
333-
commitShaProvider = CommitShaProvider.fromString(config.compareFrom, config.specifiedBranch)
333+
commitShaProvider = CommitShaProvider.fromString(config.compareFrom, config.specifiedBranch),
334+
ignoredFiles = config.ignoredFiles
334335
)
335336
}
336337

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/GitClient.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ internal class GitClientImpl(
7272
workingDir = workingDir,
7373
logger = logger
7474
),
75-
private val commitShaProvider: CommitShaProvider
75+
private val commitShaProvider: CommitShaProvider,
76+
private val ignoredFiles: Set<String>?
7677
) : GitClient {
7778

7879
/**
@@ -85,13 +86,20 @@ internal class GitClientImpl(
8586
val sha = commitShaProvider.get(commandRunner)
8687

8788
// use this if we don't want local changes
88-
return commandRunner.executeAndParse(
89+
val changedFiles = commandRunner.executeAndParse(
8990
if (includeUncommitted) {
9091
"$CHANGED_FILES_CMD_PREFIX $sha"
9192
} else {
9293
"$CHANGED_FILES_CMD_PREFIX $top..$sha"
9394
}
9495
)
96+
97+
return ignoredFiles
98+
.orEmpty()
99+
.map { it.toRegex() }
100+
.foldRight(changedFiles){ignoredFileRegex: Regex, fileList: List<String> ->
101+
fileList.filterNot { it.matches(ignoredFileRegex) }
102+
}
95103
}
96104

97105
private fun findGitDirInParentFilepath(filepath: File): File? {

affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/GitClientImplTest.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ class GitClientImplTest {
2727
workingDir = workingDir,
2828
logger = logger,
2929
commandRunner = commandRunner,
30-
commitShaProvider = commitShaProvider
30+
commitShaProvider = commitShaProvider,
31+
ignoredFiles = setOf(".*\\.ignore", ".*IGNORED_FILE")
3132
)
3233

3334
@Test
3435
fun givenChangedFiles_whenFindChangedFilesIncludeUncommitted_thenReturnChanges() {
3536
val changes = listOf(
37+
convertToFilePath("d", "e", ".ignoredNot"),
3638
convertToFilePath("a", "b", "c.java"),
3739
convertToFilePath("d", "e", "f.java"))
40+
val changesWithIgnores = listOf(
41+
convertToFilePath("a", "b", "anything.ignore"),
42+
convertToFilePath("d", "e", ".ignore"),
43+
convertToFilePath("d", "e", "IGNORED_FILE")
44+
) + changes
3845
commandRunner.addReply(
3946
"$CHANGED_FILES_CMD_PREFIX mySha",
40-
changes.joinToString(System.lineSeparator())
47+
changesWithIgnores.joinToString(System.lineSeparator())
4148
)
4249
commitShaProvider.addReply("mySha")
4350

@@ -58,11 +65,17 @@ class GitClientImplTest {
5865
@Test
5966
fun findChangesSince_twoCls() {
6067
val changes = listOf(
68+
convertToFilePath("d", "e", ".ignoredNot"),
6169
convertToFilePath("a", "b", "c.java"),
6270
convertToFilePath("d", "e", "f.java"))
71+
val changesWithIgnores = listOf(
72+
convertToFilePath("a", "b", "anything.ignore"),
73+
convertToFilePath("d", "e", ".ignore"),
74+
convertToFilePath("d", "e", "IGNORED_FILE")
75+
) + changes
6376
commandRunner.addReply(
6477
"$CHANGED_FILES_CMD_PREFIX otherSha..mySha",
65-
changes.joinToString(System.lineSeparator())
78+
changesWithIgnores.joinToString(System.lineSeparator())
6679
)
6780
commitShaProvider.addReply("mySha")
6881
assertEquals(

0 commit comments

Comments
 (0)