Skip to content

Commit

Permalink
Add support from #279 for custom base sha
Browse files Browse the repository at this point in the history
  • Loading branch information
joshafeinberg committed Jan 29, 2025
1 parent 054168c commit 43d6870
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ abstract class AffectedModuleDetector(protected val logger: Logger?) {
val gitClient = GitClientImpl(
rootProject.projectDir,
logger,
commitShaProviderConfiguration = CommitShaProviderConfiguration(config.compareFrom, config.specifiedBranch, config.top, config.includeUncommitted),
commitShaProviderConfiguration = CommitShaProviderConfiguration(
type = config.compareFrom,
specifiedBranch = config.specifiedBranch,
specifiedSha = config.specifiedRawCommitSha,
top = config.top,
includeUncommitted = config.includeUncommitted
),
ignoredFiles = config.ignoredFiles
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.dropbox.affectedmoduledetector.commitshaproviders.ForkCommit
import com.dropbox.affectedmoduledetector.commitshaproviders.PreviousCommit
import com.dropbox.affectedmoduledetector.commitshaproviders.SpecifiedBranchCommit
import com.dropbox.affectedmoduledetector.commitshaproviders.SpecifiedBranchCommitMergeBase
import com.dropbox.affectedmoduledetector.commitshaproviders.SpecifiedRawCommitSha
import com.dropbox.affectedmoduledetector.util.toOsSpecificLineEnding
import com.dropbox.affectedmoduledetector.util.toOsSpecificPath
import org.gradle.api.Project
Expand Down Expand Up @@ -228,6 +229,7 @@ internal abstract class GitChangedFilesSource :

private fun getSha(): Sha {
val specifiedBranch = parameters.commitShaProvider.specifiedBranch
val specifiedSha = parameters.commitShaProvider.specifiedSha
val type = when (parameters.commitShaProvider.type) {
"PreviousCommit" -> PreviousCommit()
"ForkCommit" -> ForkCommit()
Expand All @@ -243,6 +245,12 @@ internal abstract class GitChangedFilesSource :
}
SpecifiedBranchCommitMergeBase(specifiedBranch)
}
"SpecifiedRawCommitSha" -> {
requireNotNull(specifiedSha) {
"Provide a Commit SHA for the specifiedRawCommitSha property when using SpecifiedRawCommitSha comparison strategy."
}
SpecifiedRawCommitSha(specifiedSha)
}
else -> throw IllegalArgumentException("Unsupported compareFrom type")
}
return type.get(commandRunner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface CommitShaProvider : Serializable {
data class CommitShaProviderConfiguration(
val type: String,
val specifiedBranch: String? = null,
val specifiedSha: String? = null,
val top: Sha,
val includeUncommitted: Boolean
) : Serializable

0 comments on commit 43d6870

Please sign in to comment.