Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New endpoint: Create a review for a pull request #169

Merged
merged 4 commits into from
May 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test case
417-72KI committed May 16, 2023
commit ea2418d75e2be3d979a0ed542eb603f8acf8497a
38 changes: 38 additions & 0 deletions Tests/OctoKitTests/Fixtures/review.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"_links" : {
"html" : {
"href" : "https:\/\/github.com\/octocat\/Hello-World\/pull\/12#pullrequestreview-80"
},
"pull_request" : {
"href" : "https:\/\/api.github.com\/repos\/octocat\/Hello-World\/pulls\/12"
}
},
"body" : "Here is the body for the review.",
"commit_id" : "ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091",
"html_url" : "https:\/\/github.com\/octocat\/Hello-World\/pull\/12#pullrequestreview-80",
"id" : 80,
"node_id" : "MDE3OlB1bGxSZXF1ZXN0UmV2aWV3ODA=",
"pull_request_url" : "https:\/\/api.github.com\/repos\/octocat\/Hello-World\/pulls\/12",
"state" : "APPROVED",
"submitted_at" : "2019-11-17T17:43:43Z",
"user" : {
"avatar_url" : "https:\/\/github.com\/images\/error\/octocat_happy.gif",
"events_url" : "https:\/\/api.github.com\/users\/octocat\/events{\/privacy}",
"followers_url" : "https:\/\/api.github.com\/users\/octocat\/followers",
"following_url" : "https:\/\/api.github.com\/users\/octocat\/following{\/other_user}",
"gists_url" : "https:\/\/api.github.com\/users\/octocat\/gists{\/gist_id}",
"gravatar_id" : "",
"html_url" : "https:\/\/github.com\/octocat",
"id" : 1,
"login" : "octocat",
"node_id" : "MDQ6VXNlcjE=",
"organizations_url" : "https:\/\/api.github.com\/users\/octocat\/orgs",
"received_events_url" : "https:\/\/api.github.com\/users\/octocat\/received_events",
"repos_url" : "https:\/\/api.github.com\/users\/octocat\/repos",
"site_admin" : false,
"starred_url" : "https:\/\/api.github.com\/users\/octocat\/starred{\/owner}{\/repo}",
"subscriptions_url" : "https:\/\/api.github.com\/users\/octocat\/subscriptions",
"type" : "User",
"url" : "https:\/\/api.github.com\/users\/octocat"
}
}
70 changes: 70 additions & 0 deletions Tests/OctoKitTests/ReviewTests.swift
Original file line number Diff line number Diff line change
@@ -69,4 +69,74 @@ class ReviewTests: XCTestCase {
XCTAssertTrue(session.wasCalled)
}
#endif

func testPostReview() {
let session = OctoKitURLTestSession(expectedURL: "https://api.github.com/repos/octocat/Hello-World/pulls/1/reviews", expectedHTTPMethod: "POST", jsonFile: "review", statusCode: 200)
let task = Octokit().postReview(
session,
owner: "octocat",
repository: "Hello-World",
pullRequestNumber: 1,
event: .approve
) {
switch $0 {
case let .success(review):
XCTAssertEqual(review.body, "Here is the body for the review.")
XCTAssertEqual(review.commitID, "ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091")
XCTAssertEqual(review.id, 80)
XCTAssertEqual(review.state, .approved)
XCTAssertEqual(review.submittedAt, Date(timeIntervalSince1970: 1_574_012_623.0))
XCTAssertEqual(review.user.avatarURL, "https://github.com/images/error/octocat_happy.gif")
XCTAssertNil(review.user.blog)
XCTAssertNil(review.user.company)
XCTAssertNil(review.user.email)
XCTAssertEqual(review.user.gravatarID, "")
XCTAssertEqual(review.user.id, 1)
XCTAssertNil(review.user.location)
XCTAssertEqual(review.user.login, "octocat")
XCTAssertNil(review.user.name)
XCTAssertNil(review.user.numberOfPublicGists)
XCTAssertNil(review.user.numberOfPublicRepos)
XCTAssertNil(review.user.numberOfPrivateRepos)
XCTAssertEqual(review.user.type, "User")
case .failure:
XCTFail("should not get an error")
}
}
XCTAssertNotNil(task)
XCTAssertTrue(session.wasCalled)
}

#if compiler(>=5.5.2) && canImport(_Concurrency)
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)
func testPostReviewAsync() async throws {
let session = OctoKitURLTestSession(expectedURL: "https://api.github.com/repos/octocat/Hello-World/pulls/1/reviews", expectedHTTPMethod: "POST", jsonFile: "review", statusCode: 200)
let review = try await Octokit().postReview(
session,
owner: "octocat",
repository: "Hello-World",
pullRequestNumber: 1,
event: .approve
)
XCTAssertEqual(review.body, "Here is the body for the review.")
XCTAssertEqual(review.commitID, "ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091")
XCTAssertEqual(review.id, 80)
XCTAssertEqual(review.state, .approved)
XCTAssertEqual(review.submittedAt, Date(timeIntervalSince1970: 1_574_012_623.0))
XCTAssertEqual(review.user.avatarURL, "https://github.com/images/error/octocat_happy.gif")
XCTAssertNil(review.user.blog)
XCTAssertNil(review.user.company)
XCTAssertNil(review.user.email)
XCTAssertEqual(review.user.gravatarID, "")
XCTAssertEqual(review.user.id, 1)
XCTAssertNil(review.user.location)
XCTAssertEqual(review.user.login, "octocat")
XCTAssertNil(review.user.name)
XCTAssertNil(review.user.numberOfPublicGists)
XCTAssertNil(review.user.numberOfPublicRepos)
XCTAssertNil(review.user.numberOfPrivateRepos)
XCTAssertEqual(review.user.type, "User")
XCTAssertTrue(session.wasCalled)
}
#endif
}