Skip to content

Commit

Permalink
refactor(swiftpm): Split up PinV2.toPackage()
Browse files Browse the repository at this point in the history
This simplifies upcoming changes.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Feb 7, 2024
1 parent acfc84a commit 2dcbeeb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ private fun SwiftPackage.getTransitiveDependencies(): Set<SwiftPackage> {
return result
}

private fun PinV2.toPackage(): Package {
val id = Identifier(
private fun PinV2.toId(): Identifier =
Identifier(
type = PACKAGE_TYPE,
namespace = "",
name = getCanonicalName(location),
Expand All @@ -214,8 +214,9 @@ private fun PinV2.toPackage(): Package {
}.orEmpty()
)

private fun PinV2.toVcsInfo(): VcsInfo {
val vcsInfoFromUrl = VcsHost.parseUrl(location)
val vcsInfo = if (vcsInfoFromUrl.revision.isBlank() && state != null) {
return if (vcsInfoFromUrl.revision.isBlank() && state != null) {
when {
!state.revision.isNullOrBlank() -> vcsInfoFromUrl.copy(revision = state.revision)
!state.version.isNullOrBlank() -> vcsInfoFromUrl.copy(revision = state.version)
Expand All @@ -224,10 +225,10 @@ private fun PinV2.toPackage(): Package {
} else {
vcsInfoFromUrl
}

return createPackage(id, vcsInfo)
}

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

private fun createPackage(id: Identifier, vcsInfo: VcsInfo) =
Package(
vcs = vcsInfo,
Expand Down

0 comments on commit 2dcbeeb

Please sign in to comment.