Skip to content

Commit

Permalink
refactor(Provenance): Allow blank resolvedRevision for VcsInfo.EMPTY
Browse files Browse the repository at this point in the history
This will allow tests using `Repository` objects using `VcsInfo.EMPTY` to
continue to function, even though `RepositoryProvenance` does not usually
allow blank revisions. By restricting the exception to `VcsInfo.EMPTY` any
other bahaviour of `RepositoryProvenance` should be retained.

Some unrelated `OrtResultTest`s had to be given non-blank revisions:
    Both `fail if no vcs matches` and `use the correct vcs` don't hinge
on the given blank revision, so to assure they do not fail for unrelated
reasons, we just add the default git revision "main" to these example
repos.

Signed-off-by: Jens Keim <[email protected]>
  • Loading branch information
keimje1 committed Jun 26, 2024
1 parent 507004d commit 1cf8e21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion model/src/main/kotlin/Provenance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ data class RepositoryProvenance(
val resolvedRevision: String
) : KnownProvenance {
init {
require(resolvedRevision.isNotBlank()) { "The resolved revision must not be blank." }
require(vcsInfo == VcsInfo.EMPTY || resolvedRevision.isNotBlank()) {
"The resolved revision must not be blank."
}
}

/**
Expand Down
12 changes: 6 additions & 6 deletions model/src/test/kotlin/OrtResultTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class OrtResultTest : WordSpec({

"getDefinitionFilePathRelativeToAnalyzerRoot()" should {
"use the correct vcs" {
val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "")
val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "")
val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "")
val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "main")
val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "main")
val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "main")
val project1 = Project.EMPTY.copy(
id = Identifier("Gradle:org.ossreviewtoolkit:project1:1.0"),
definitionFilePath = "project1/build.gradle",
Expand Down Expand Up @@ -123,9 +123,9 @@ class OrtResultTest : WordSpec({
}

"fail if no vcs matches" {
val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "")
val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "")
val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "")
val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "main")
val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "main")
val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "main")
val project = Project.EMPTY.copy(
id = Identifier("Gradle:org.ossreviewtoolkit:project1:1.0"),
definitionFilePath = "build.gradle",
Expand Down

0 comments on commit 1cf8e21

Please sign in to comment.