-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #547 from danger/parse_commit_verification
Parse GitHub commit verification
- Loading branch information
Showing
4 changed files
with
137 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ public let GitHubCommitWithEmptyAuthorJSON = """ | |
"comment_count": 0, | ||
"verification": { | ||
"verified": false, | ||
"reason": "unsigned", | ||
"reason": "unknown_signature_type", | ||
"signature": null, | ||
"payload": null | ||
} | ||
|
@@ -55,3 +55,61 @@ public let GitHubCommitWithEmptyAuthorJSON = """ | |
] | ||
} | ||
""" | ||
|
||
public let GitHubCommitVerifiedJSON = """ | ||
{ | ||
"sha": "cad494648f773cd4fad5a9ea948c1bfabf36032a", | ||
"node_id": "MDY6Q29tbWl0MTAxMzM5MjEyOmNhZDQ5NDY0OGY3NzNjZDRmYWQ1YTllYTk0OGMxYmZhYmYzNjAzMmE=", | ||
"commit": { | ||
"author": { | ||
"name": "Franco Meloni", | ||
"email": "[email protected]", | ||
"date": "2019-04-20T17:46:50Z" | ||
}, | ||
"committer": { | ||
"name": "Franco Meloni", | ||
"email": "[email protected]", | ||
"date": "2019-04-20T17:46:50Z" | ||
}, | ||
"message": "Re use the same executor on the runner", | ||
"tree": { | ||
"sha": "96b7fdf0ab04926cc9eee844a15d66e097922777", | ||
"url": "https://api.github.com/repos/danger/swift/git/trees/96b7fdf0ab04926cc9eee844a15d66e097922777" | ||
}, | ||
"url": "https://api.github.com/repos/danger/swift/git/commits/cad494648f773cd4fad5a9ea948c1bfabf36032a", | ||
"comment_count": 0, | ||
"verification": { | ||
"verified": true, | ||
"reason": "valid", | ||
"signature": "Test Signature", | ||
"payload": "Test Payload" | ||
} | ||
}, | ||
"url": "https://api.github.com/repos/danger/swift/commits/cad494648f773cd4fad5a9ea948c1bfabf36032a", | ||
"html_url": "https://github.com/danger/swift/commit/cad494648f773cd4fad5a9ea948c1bfabf36032a", | ||
"comments_url": "https://api.github.com/repos/danger/swift/commits/cad494648f773cd4fad5a9ea948c1bfabf36032a/comments", | ||
"author": {}, | ||
"committer": { | ||
"login": "f-meloni", | ||
"id": 17830956, | ||
"node_id": "MDQ6VXNlcjE3ODMwOTU2", | ||
"avatar_url": "https://avatars1.githubusercontent.com/u/17830956?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/f-meloni", | ||
"html_url": "https://github.com/f-meloni", | ||
"followers_url": "https://api.github.com/users/f-meloni/followers", | ||
"following_url": "https://api.github.com/users/f-meloni/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/f-meloni/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/f-meloni/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/f-meloni/subscriptions", | ||
"organizations_url": "https://api.github.com/users/f-meloni/orgs", | ||
"repos_url": "https://api.github.com/users/f-meloni/repos", | ||
"events_url": "https://api.github.com/users/f-meloni/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/f-meloni/received_events", | ||
"type": "User", | ||
"site_admin": false | ||
}, | ||
"parents": [ | ||
] | ||
} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,12 +254,36 @@ final class GitHubTests: XCTestCase { | |
XCTAssertNil(testCommit.author) | ||
XCTAssertEqual(testCommit.sha, "cad494648f773cd4fad5a9ea948c1bfabf36032a") | ||
XCTAssertEqual(testCommit.url, "https://api.github.com/repos/danger/swift/commits/cad494648f773cd4fad5a9ea948c1bfabf36032a") | ||
XCTAssertEqual(testCommit.commit, GitHub.Commit.CommitData(sha: nil, | ||
author: expectedAuthor, | ||
committer: expectedAuthor, | ||
message: "Re use the same executor on the runner", | ||
parents: nil, | ||
url: "https://api.github.com/repos/danger/swift/git/commits/cad494648f773cd4fad5a9ea948c1bfabf36032a")) | ||
XCTAssertEqual(testCommit.commit, GitHub.Commit.CommitData( | ||
sha: nil, | ||
author: expectedAuthor, | ||
committer: expectedAuthor, | ||
message: "Re use the same executor on the runner", | ||
parents: nil, | ||
url: "https://api.github.com/repos/danger/swift/git/commits/cad494648f773cd4fad5a9ea948c1bfabf36032a", | ||
verification: .unverified(.unknownSignatureType) | ||
)) | ||
XCTAssertEqual(testCommit.committer, GitHub.User(id: 17_830_956, login: "f-meloni", userType: .user)) | ||
} | ||
|
||
func test_GitHubCommit_decodesJSONWithVerifiedCommit() throws { | ||
let data = Data(GitHubCommitVerifiedJSON.utf8) | ||
let expectedAuthor = Git.Commit.Author(name: "Franco Meloni", email: "[email protected]", date: "2019-04-20T17:46:50Z") | ||
|
||
let testCommit = try decoder.decode(GitHub.Commit.self, from: data) | ||
|
||
XCTAssertNil(testCommit.author) | ||
XCTAssertEqual(testCommit.sha, "cad494648f773cd4fad5a9ea948c1bfabf36032a") | ||
XCTAssertEqual(testCommit.url, "https://api.github.com/repos/danger/swift/commits/cad494648f773cd4fad5a9ea948c1bfabf36032a") | ||
XCTAssertEqual(testCommit.commit, GitHub.Commit.CommitData( | ||
sha: nil, | ||
author: expectedAuthor, | ||
committer: expectedAuthor, | ||
message: "Re use the same executor on the runner", | ||
parents: nil, | ||
url: "https://api.github.com/repos/danger/swift/git/commits/cad494648f773cd4fad5a9ea948c1bfabf36032a", | ||
verification: .verified(signature: "Test Signature", payload: "Test Payload") | ||
)) | ||
XCTAssertEqual(testCommit.committer, GitHub.User(id: 17_830_956, login: "f-meloni", userType: .user)) | ||
} | ||
|
||
|