Skip to content

Commit 12a9c6d

Browse files
committed
Add support for providing the raw String of a commit SHA as a comparison strategy
1 parent 78f344e commit 12a9c6d

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,16 @@ class AffectedModuleConfiguration {
8181

8282
var specifiedBranch: String? = null
8383

84+
var specifiedRawCommitSha: String? = null
85+
8486
var compareFrom: String = "PreviousCommit"
8587
set(value) {
8688
val commitShaProviders = listOf(
8789
"PreviousCommit",
8890
"ForkCommit",
8991
"SpecifiedBranchCommit",
90-
"SpecifiedBranchCommitMergeBase"
92+
"SpecifiedBranchCommitMergeBase",
93+
"SpecifiedRawCommitSha"
9194
)
9295
require(commitShaProviders.contains(value)) {
9396
"The property configuration compareFrom must be one of the following: ${commitShaProviders.joinToString(", ")}"
@@ -97,6 +100,11 @@ class AffectedModuleConfiguration {
97100
"Specify a branch using the configuration specifiedBranch"
98101
}
99102
}
103+
if (value == "SpecifiedRawCommitSha") {
104+
requireNotNull(specifiedRawCommitSha) {
105+
"Provide a Commit SHA for the specifiedRawCommitSha property when using SpecifiedRawCommitSha comparison strategy."
106+
}
107+
}
100108
field = value
101109
}
102110

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class AffectedModuleDetectorImpl constructor(
340340
injectedGitClient ?: GitClientImpl(
341341
rootProject.projectDir,
342342
logger,
343-
commitShaProvider = CommitShaProvider.fromString(config.compareFrom, config.specifiedBranch),
343+
commitShaProvider = CommitShaProvider.fromString(config.compareFrom, config.specifiedBranch, config.specifiedRawCommitSha),
344344
ignoredFiles = config.ignoredFiles
345345
)
346346
}

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/CommitShaProvider.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ interface CommitShaProvider {
88
fun get(commandRunner: GitClient.CommandRunner): Sha
99

1010
companion object {
11-
fun fromString(string: String, specifiedBranch: String? = null): CommitShaProvider {
11+
fun fromString(
12+
string: String,
13+
specifiedBranch: String? = null,
14+
specifiedRawCommitSha: String? = null
15+
): CommitShaProvider {
1216
return when (string) {
1317
"PreviousCommit" -> PreviousCommit()
1418
"ForkCommit" -> ForkCommit()
@@ -24,6 +28,12 @@ interface CommitShaProvider {
2428
}
2529
SpecifiedBranchCommitMergeBase(specifiedBranch)
2630
}
31+
"SpecifiedRawCommitSha" -> {
32+
requireNotNull(specifiedRawCommitSha) {
33+
"Specified raw commit sha must be defined"
34+
}
35+
SpecifiedRawCommitSha(specifiedRawCommitSha)
36+
}
2737
else -> throw IllegalArgumentException("Unsupported compareFrom type")
2838
}
2939
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.dropbox.affectedmoduledetector.commitshaproviders
2+
3+
import com.dropbox.affectedmoduledetector.GitClient
4+
import com.dropbox.affectedmoduledetector.Sha
5+
6+
class SpecifiedRawCommitSha(private val commitSha: String) : CommitShaProvider {
7+
override fun get(commandRunner: GitClient.CommandRunner): Sha {
8+
return commitSha
9+
}
10+
}

0 commit comments

Comments
 (0)