From e1781aa02c40850db0ff0dfb91b72062add1f505 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Mon, 12 Feb 2024 14:14:59 +0100 Subject: [PATCH] fix(swiftpm): Simplify `PinV2.toVcsInfo()` 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 --- .../swiftpm/src/main/kotlin/SwiftPm.kt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt b/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt index bf6bdbcccca23..7dbae12fa504a 100644 --- a/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt +++ b/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt @@ -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 @@ -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())