diff --git a/README.md b/README.md index 5c1666e..371df4f 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,9 @@ affectedModuleDetector { excludedModules = [ "sample-util", ":(app|library):.+" ] + ignoredFiles = [ + ".*\\.md", ".*\\.txt", ".*README" + ] includeUncommitted = true top = "HEAD" customTasks = [ @@ -109,6 +112,7 @@ affectedModuleDetector { - `logFilename`: A filename for the output detector to use - `logFolder`: A folder to output the log file in - `specifiedBranch`: A branch to specify changes against. Must be used in combination with configuration `compareFrom = "SpecifiedBranchCommit"` + - `ignoredFiles`: A set of files that will be filtered out of the list of changed files retrieved by git. - `compareFrom`: A commit to compare the branch changes against. Can be either: - PreviousCommit: compare against the previous commit - ForkCommit: compare against the commit the branch was forked from diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt index 83bddda..82d4a1b 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt @@ -105,6 +105,11 @@ class AffectedModuleConfiguration { */ var excludedModules = emptySet() + /** + * A set of files that will be filtered out of the list of changed files retrieved by git. + */ + var ignoredFiles = emptySet() + /** * If uncommitted files should be considered affected */ diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt index 76012e2..2267465 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt @@ -330,7 +330,8 @@ class AffectedModuleDetectorImpl constructor( injectedGitClient ?: GitClientImpl( rootProject.projectDir, logger, - commitShaProvider = CommitShaProvider.fromString(config.compareFrom, config.specifiedBranch) + commitShaProvider = CommitShaProvider.fromString(config.compareFrom, config.specifiedBranch), + ignoredFiles = config.ignoredFiles ) } diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/GitClient.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/GitClient.kt index 1e5517c..7063a80 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/GitClient.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/GitClient.kt @@ -72,7 +72,8 @@ internal class GitClientImpl( workingDir = workingDir, logger = logger ), - private val commitShaProvider: CommitShaProvider + private val commitShaProvider: CommitShaProvider, + private val ignoredFiles: Set? ) : GitClient { /** @@ -85,13 +86,20 @@ internal class GitClientImpl( val sha = commitShaProvider.get(commandRunner) // use this if we don't want local changes - return commandRunner.executeAndParse( + val changedFiles = commandRunner.executeAndParse( if (includeUncommitted) { "$CHANGED_FILES_CMD_PREFIX $sha" } else { "$CHANGED_FILES_CMD_PREFIX $top..$sha" } ) + + return ignoredFiles + .orEmpty() + .map { it.toRegex() } + .foldRight(changedFiles){ignoredFileRegex: Regex, fileList: List -> + fileList.filterNot { it.matches(ignoredFileRegex) } + } } private fun findGitDirInParentFilepath(filepath: File): File? { diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/GitClientImplTest.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/GitClientImplTest.kt index 9002640..82cf334 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/GitClientImplTest.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/GitClientImplTest.kt @@ -27,17 +27,24 @@ class GitClientImplTest { workingDir = workingDir, logger = logger, commandRunner = commandRunner, - commitShaProvider = commitShaProvider + commitShaProvider = commitShaProvider, + ignoredFiles = setOf(".*\\.ignore", ".*IGNORED_FILE") ) @Test fun givenChangedFiles_whenFindChangedFilesIncludeUncommitted_thenReturnChanges() { val changes = listOf( + convertToFilePath("d", "e", ".ignoredNot"), convertToFilePath("a", "b", "c.java"), convertToFilePath("d", "e", "f.java")) + val changesWithIgnores = listOf( + convertToFilePath("a", "b", "anything.ignore"), + convertToFilePath("d", "e", ".ignore"), + convertToFilePath("d", "e", "IGNORED_FILE") + ) + changes commandRunner.addReply( "$CHANGED_FILES_CMD_PREFIX mySha", - changes.joinToString(System.lineSeparator()) + changesWithIgnores.joinToString(System.lineSeparator()) ) commitShaProvider.addReply("mySha") @@ -58,11 +65,17 @@ class GitClientImplTest { @Test fun findChangesSince_twoCls() { val changes = listOf( + convertToFilePath("d", "e", ".ignoredNot"), convertToFilePath("a", "b", "c.java"), convertToFilePath("d", "e", "f.java")) + val changesWithIgnores = listOf( + convertToFilePath("a", "b", "anything.ignore"), + convertToFilePath("d", "e", ".ignore"), + convertToFilePath("d", "e", "IGNORED_FILE") + ) + changes commandRunner.addReply( "$CHANGED_FILES_CMD_PREFIX otherSha..mySha", - changes.joinToString(System.lineSeparator()) + changesWithIgnores.joinToString(System.lineSeparator()) ) commitShaProvider.addReply("mySha") assertEquals(