Skip to content

Commit

Permalink
Adds support for SSH GitHub url for Swift Package Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Rutkowski committed Feb 4, 2020
1 parent 53dba18 commit 82f1a4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Sources/LicensePlistCore/Entity/SwiftPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
8 changes: 8 additions & 0 deletions Tests/LicensePlistTests/Entity/SwiftPackageManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]: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",
Expand Down

0 comments on commit 82f1a4a

Please sign in to comment.