From 82f1a4ac7f5ce0a7be2fb7bfc19db6bbbdc485dd Mon Sep 17 00:00:00 2001 From: Wojciech Rutkowski Date: Tue, 4 Feb 2020 15:58:19 +1100 Subject: [PATCH] Adds support for SSH GitHub url for Swift Package Manager --- Sources/LicensePlistCore/Entity/SwiftPackage.swift | 9 ++++++--- .../Entity/SwiftPackageManagerTests.swift | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Sources/LicensePlistCore/Entity/SwiftPackage.swift b/Sources/LicensePlistCore/Entity/SwiftPackage.swift index 5285878b..dcaa3881 100644 --- a/Sources/LicensePlistCore/Entity/SwiftPackage.swift +++ b/Sources/LicensePlistCore/Entity/SwiftPackage.swift @@ -45,10 +45,13 @@ extension SwiftPackage { .replacingOccurrences(of: "http://", with: "") .components(separatedBy: "/") - guard urlParts.count >= 3 else { return nil } - let name = urlParts.last?.deletingSuffix(".git") ?? "" - let owner = urlParts[urlParts.count - 2] + let owner: String + if urlParts.count >= 3 { + owner = urlParts[urlParts.count - 2] + } else { + owner = urlParts.first?.components(separatedBy: ":").last ?? "" + } return GitHub(name: name, nameSpecified: renames[name], diff --git a/Tests/LicensePlistTests/Entity/SwiftPackageManagerTests.swift b/Tests/LicensePlistTests/Entity/SwiftPackageManagerTests.swift index 6d8c3b6a..9ee53bf5 100644 --- a/Tests/LicensePlistTests/Entity/SwiftPackageManagerTests.swift +++ b/Tests/LicensePlistTests/Entity/SwiftPackageManagerTests.swift @@ -94,6 +94,14 @@ class SwiftPackageManagerTests: XCTestCase { XCTAssertEqual(result, GitHub(name: "R.swift.Library", nameSpecified: nil, owner: "mac-cain13", version: nil)) } + func testConvertToGithubSSH() { + let package = SwiftPackage(package: "LicensePlist", + repositoryURL: "git@github.com:mono0926/LicensePlist.git", + state: SwiftPackage.State(branch: nil, revision: "3365947d725398694d6ed49f2e6622f05ca3fc0e", version: nil)) + let result = package.toGitHub(renames: [:]) + XCTAssertEqual(result, GitHub(name: "LicensePlist", nameSpecified: nil, owner: "mono0926", version: nil)) + } + func testRename() { let package = SwiftPackage(package: "Commander", repositoryURL: "https://github.com/kylef/Commander.git",