Skip to content

Commit

Permalink
Merge pull request #5 from teufelaudio/FixGitAuth
Browse files Browse the repository at this point in the history
Fix Git Auth request
  • Loading branch information
luizmb authored Nov 23, 2021
2 parents 4f5585d + 939e197 commit 99e3a08
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 20 deletions.
40 changes: 20 additions & 20 deletions Sources/Models/GitHub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ import Helper
public typealias GitHubRepository = (owner: String, name: String)

public struct GitHubLicense: Decodable {
let name: String
let path: String
let sha: String
let size: Int
let url: URL?
let htmlUrl: URL?
let gitUrl: URL?
let downloadUrl: URL
let type: String?
let content: String?
let encoding: String?
let license: LicenseDetails
public let name: String
public let path: String
public let sha: String
public let size: Int
public let url: URL?
public let htmlUrl: URL?
public let gitUrl: URL?
public let downloadUrl: URL
public let type: String?
public let content: String?
public let encoding: String?
public let license: LicenseDetails

var licenseName: String {
public var licenseName: String {
license.name
}

struct LicenseDetails: Decodable {
let key: String
let name: String
let spdx_id: String?
let url: URL?
let node_id: String?
public struct LicenseDetails: Decodable {
public let key: String
public let name: String
public let spdxId: String?
public let url: URL?
public let nodeId: String?
}
}

Expand Down Expand Up @@ -70,7 +70,7 @@ public func githubLicensingAPI(

var request = URLRequest(url: url)
zip(githubClientID, githubClientSecret)
.flatMap { "\($0):\($0)".data(using: .utf8) }
.flatMap { (clientId, clientSecret) in "\(clientId):\(clientSecret)".data(using: .utf8) }
.map { "Basic \($0.base64EncodedString())" }
.analysis(ifSome: { request.addValue($0, forHTTPHeaderField: "Authorization") }, ifNone: { })

Expand Down
2 changes: 2 additions & 0 deletions Tests/SwiftPackageAcknowledgementTests/BridgeTests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright © 2021 Lautsprecher Teufel GmbH. All rights reserved.

import Models
import XCTest

Expand Down
62 changes: 62 additions & 0 deletions Tests/SwiftPackageAcknowledgementTests/GithubTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright © 2021 Lautsprecher Teufel GmbH. All rights reserved.

import Foundation

import Models
import XCTest

class GithubTests: XCTestCase {
func test_github_license_decode() throws {
let data = try XCTUnwrap(json.data(using: .utf8))
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase

let sut = try decoder.decode(GitHubLicense.self, from: data)
XCTAssertEqual(sut.name, "LICENSE")
XCTAssertEqual(sut.path, "LICENSE")
XCTAssertEqual(sut.sha, "261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64")
XCTAssertEqual(sut.size, 11357)
XCTAssertEqual(sut.url, try XCTUnwrap(URL(string: "https://api.github.com/repos/SwiftRex/SwiftRex/contents/LICENSE?ref=develop")))
XCTAssertEqual(sut.htmlUrl, try XCTUnwrap(URL(string: "https://github.com/SwiftRex/SwiftRex/blob/develop/LICENSE")))
XCTAssertEqual(sut.gitUrl, try XCTUnwrap(URL(string: "https://api.github.com/repos/SwiftRex/SwiftRex/git/blobs/261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64")))
XCTAssertEqual(sut.downloadUrl, try XCTUnwrap(URL(string: "https://raw.githubusercontent.com/SwiftRex/SwiftRex/develop/LICENSE")))
XCTAssertEqual(sut.type, "file")
XCTAssertEqual(sut.content, "GVyIHRoZSBMaWNlbnNlLgo=\n")
XCTAssertEqual(sut.encoding, "base64")
XCTAssertEqual(sut.license.key, "apache-2.0")
XCTAssertEqual(sut.license.name, "Apache License 2.0")
XCTAssertEqual(sut.license.spdxId, "Apache-2.0")
XCTAssertEqual(sut.license.url, try XCTUnwrap(URL(string: "https://api.github.com/licenses/apache-2.0")))
XCTAssertEqual(sut.license.nodeId, "MDc6TGljZW5zZTI=")
}
}


let json =
"""
{
"name": "LICENSE",
"path": "LICENSE",
"sha": "261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64",
"size": 11357,
"url": "https://api.github.com/repos/SwiftRex/SwiftRex/contents/LICENSE?ref=develop",
"html_url": "https://github.com/SwiftRex/SwiftRex/blob/develop/LICENSE",
"git_url": "https://api.github.com/repos/SwiftRex/SwiftRex/git/blobs/261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64",
"download_url": "https://raw.githubusercontent.com/SwiftRex/SwiftRex/develop/LICENSE",
"type": "file",
"content": "GVyIHRoZSBMaWNlbnNlLgo=\\n",
"encoding": "base64",
"_links": {
"self": "https://api.github.com/repos/SwiftRex/SwiftRex/contents/LICENSE?ref=develop",
"git": "https://api.github.com/repos/SwiftRex/SwiftRex/git/blobs/261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64",
"html": "https://github.com/SwiftRex/SwiftRex/blob/develop/LICENSE"
},
"license": {
"key": "apache-2.0",
"name": "Apache License 2.0",
"spdx_id": "Apache-2.0",
"url": "https://api.github.com/licenses/apache-2.0",
"node_id": "MDc6TGljZW5zZTI="
}
}
"""

0 comments on commit 99e3a08

Please sign in to comment.