Skip to content

Commit

Permalink
fix(swiftpm): Simplify PinV2.toVcsInfo()
Browse files Browse the repository at this point in the history
The property `PinV2.location` for `remoteSourceControl` dependencies
always hold a repository URL pointing to a Git repository. The existing
code is misleading, as it looks like a revision could be extracted from
the `location`. Furthermore, for `https` URLs which lack the `.git`
suffix, the VCS type could not be determined. Fix both issues by simply
normalizing the given `location`.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Feb 12, 2024
1 parent 9f2f094 commit e1781aa
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.ossreviewtoolkit.model.ProjectAnalyzerResult
import org.ossreviewtoolkit.model.RemoteArtifact
import org.ossreviewtoolkit.model.Scope
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.model.orEmpty
Expand Down Expand Up @@ -242,15 +243,11 @@ private fun PinV2.toId(): Identifier =
private fun PinV2.toVcsInfo(): VcsInfo {
if (kind != PinV2.Kind.REMOTE_SOURCE_CONTROL) return VcsInfo.EMPTY

val vcsInfoFromUrl = VcsHost.parseUrl(location)
return if (vcsInfoFromUrl.revision.isBlank() && state != null) {
when {
!state.revision.isNullOrBlank() -> vcsInfoFromUrl.copy(revision = state.revision)
else -> vcsInfoFromUrl
}
} else {
vcsInfoFromUrl
}
return VcsInfo(
type = VcsType.GIT,
url = normalizeVcsUrl(location),
revision = state?.revision.orEmpty()
)
}

private fun PinV2.toPackage(): Package = createPackage(toId(), toVcsInfo())
Expand Down

0 comments on commit e1781aa

Please sign in to comment.