Skip to content

Commit

Permalink
Merge pull request #54 from mono0926/use-github-license-content
Browse files Browse the repository at this point in the history
Use GitHub license content
  • Loading branch information
mono0926 authored May 20, 2017
2 parents 9b60390 + fc9e110 commit f379d79
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ included:
- Sources
- Tests

line_length: 140
line_length: 150
Binary file modified LicensePlist.paw
Binary file not shown.
5 changes: 2 additions & 3 deletions Sources/LicensePlist/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ let main = command(Option("cartfile-path", Consts.cartfileName),
Option("config-path", Consts.configPath),
Flag("force"),
Flag("add-version-numbers"),
Flag("suppress-opening-directory")) {
cartfile, podsPath, output, gitHubToken, configPath, force, version, suppressOpeningDirectory in
Flag("suppress-opening-directory")) { cartfile, podsPath, output, gitHubToken, configPath, force, version, suppressOpen in

Logger.configure()
var config = loadConfig(configPath: URL(fileURLWithPath: configPath))
config.force = force
config.addVersionNumbers = version
config.suppressOpeningDirectory = suppressOpeningDirectory
config.suppressOpeningDirectory = suppressOpen
let options = Options(outputPath: URL(fileURLWithPath: output),
cartfilePath: URL(fileURLWithPath: cartfile),
podsPath: URL(fileURLWithPath: podsPath),
Expand Down
2 changes: 1 addition & 1 deletion Sources/LicensePlistCore/Entity/GitHubLicense.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension GitHubLicense {
}
case .success(let response):
let license = GitHubLicense(library: library,
body: response.downloadUrl.lp.download().resultSync().value!,
body: response.contentDecoded,
githubResponse: response)
return Result(value: license)
}
Expand Down
13 changes: 11 additions & 2 deletions Sources/LicensePlistCore/GitHubClient/RepoRequests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ struct RepoRequests {
}

struct LicenseResponse {
let downloadUrl: URL
let content: String
let contentDecoded: String
let encoding: String
let kind: LicenseKindResponse
}

extension LicenseResponse: Decodable {
static func decode(_ e: Extractor) throws -> LicenseResponse {
return try LicenseResponse(downloadUrl: URL(string: e.value("download_url"))!, kind: e.value("license"))
let content: String = try e.value("content")
let encofing: String = try e.value("encoding")
assert(encofing == "base64")
let contentDecoded = String(data: Data(base64Encoded: content, options: [.ignoreUnknownCharacters])!, encoding: .utf8)!
return try LicenseResponse(content: content,
contentDecoded: contentDecoded,
encoding: encofing,
kind: e.value("license"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class GitHubLicenseTests: XCTestCase {
let license = GitHubLicense.download(carthage).resultSync().value!
XCTAssertEqual(license.library, carthage)
XCTAssertTrue(license.body.hasPrefix("MIT License"))
XCTAssertEqual(license.githubResponse.downloadUrl,
URL(string: "https://raw.githubusercontent.com/mono0926/NativePopup/master/LICENSE"))
XCTAssertEqual(license.githubResponse.kind.spdxId, "MIT")
}

Expand All @@ -27,8 +25,6 @@ class GitHubLicenseTests: XCTestCase {
forked.owner = "adjust"
XCTAssertEqual(license.library, forked)
XCTAssertTrue(license.body.hasPrefix("Copyright (c)"))
XCTAssertEqual(license.githubResponse.downloadUrl,
URL(string: "https://raw.githubusercontent.com/adjust/ios_sdk/master/MIT-LICENSE"))
XCTAssertEqual(license.githubResponse.kind.spdxId, "MIT")
}
func testCollect_invalid() {
Expand Down
16 changes: 12 additions & 4 deletions Tests/LicensePlistTests/Entity/PlistInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ class PlistInfoTests: XCTestCase {
let github = GitHub(name: "LicensePlist", nameSpecified: nil, owner: "mono0926", version: nil)
let githubLicense = GitHubLicense(library: github,
body: "body",
githubResponse: LicenseResponse(downloadUrl: URL(fileURLWithPath: ""),
githubResponse: LicenseResponse(content: "",
contentDecoded: "",
encoding: "",
kind: LicenseKindResponse(name: "name",
spdxId: nil)))
target.cocoaPodsLicenses = []
Expand All @@ -120,7 +122,9 @@ class PlistInfoTests: XCTestCase {
let github = GitHub(name: "LicensePlist", nameSpecified: nil, owner: "mono0926", version: nil)
let githubLicense = GitHubLicense(library: github,
body: "body",
githubResponse: LicenseResponse(downloadUrl: URL(fileURLWithPath: ""),
githubResponse: LicenseResponse(content: "",
contentDecoded: "",
encoding: "",
kind: LicenseKindResponse(name: "name",
spdxId: nil)))
target.licenses = [githubLicense]
Expand All @@ -132,7 +136,9 @@ class PlistInfoTests: XCTestCase {
let github = GitHub(name: "LicensePlist", nameSpecified: nil, owner: "mono0926", version: nil)
let githubLicense = GitHubLicense(library: github,
body: "body",
githubResponse: LicenseResponse(downloadUrl: URL(fileURLWithPath: ""),
githubResponse: LicenseResponse(content: "",
contentDecoded: "",
encoding: "",
kind: LicenseKindResponse(name: "name",
spdxId: nil)))
target.githubLibraries = [github]
Expand All @@ -145,7 +151,9 @@ class PlistInfoTests: XCTestCase {
let github = GitHub(name: "LicensePlist", nameSpecified: nil, owner: "mono0926", version: nil)
let githubLicense = GitHubLicense(library: github,
body: "body",
githubResponse: LicenseResponse(downloadUrl: URL(fileURLWithPath: ""),
githubResponse: LicenseResponse(content: "",
contentDecoded: "",
encoding: "",
kind: LicenseKindResponse(name: "name",
spdxId: nil)))
target.githubLibraries = [github]
Expand Down
10 changes: 3 additions & 7 deletions Tests/LicensePlistTests/GitHubClient/RepoRequestsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class RepoRequestsTests: XCTestCase {
let result = Session.shared.lp.sendSync(request)
switch result {
case .success(let response):
XCTAssertEqual(
response.downloadUrl,
URL(string: "https://raw.githubusercontent.com/mono0926/NativePopup/master/LICENSE")!)
XCTAssertTrue(response.contentDecoded.hasPrefix("MIT License"))
case .failure(let error):
XCTFail(String(describing: error))
}
Expand All @@ -41,9 +39,7 @@ class RepoRequestsTests: XCTestCase {
queue.addOperations([o1, o2], waitUntilFinished: true)
let result = [o1.result!.value!, o2.result!.value!]
XCTAssertEqual(result.count, 2)
XCTAssertEqual(result[0].downloadUrl,
URL(string: "https://raw.githubusercontent.com/mono0926/NativePopup/master/LICENSE")!)
XCTAssertEqual(result[1].downloadUrl,
URL(string: "https://raw.githubusercontent.com/ReactiveX/RxSwift/master/LICENSE.md")!)
XCTAssertTrue(result[0].contentDecoded.hasPrefix("MIT License"))
XCTAssertTrue(result[1].contentDecoded.hasPrefix("**The MIT License**"))
}
}

0 comments on commit f379d79

Please sign in to comment.