From 3ec01bd05ae7149929195aafc59420591e5608b9 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Sun, 25 Feb 2018 05:18:26 -0500 Subject: [PATCH] Adds PullRequestReviewEventPayload (#1767) * Adds PullRequestReviewEventPayload * Remove random A --- Octokit.Tests/Clients/EventsClientTests.cs | 38 +++++++++++++++++++ Octokit/Http/SimpleJsonSerializer.cs | 2 + .../PullRequestReviewEventPayload.cs | 12 ++++++ 3 files changed, 52 insertions(+) create mode 100644 Octokit/Models/Response/ActivityPayloads/PullRequestReviewEventPayload.cs diff --git a/Octokit.Tests/Clients/EventsClientTests.cs b/Octokit.Tests/Clients/EventsClientTests.cs index ccce328bbf..803f6fb487 100644 --- a/Octokit.Tests/Clients/EventsClientTests.cs +++ b/Octokit.Tests/Clients/EventsClientTests.cs @@ -558,6 +558,7 @@ public async Task EnsuresNonNullArguments() {"IssueCommentEvent", typeof(IssueCommentPayload)}, {"IssuesEvent", typeof(IssueEventPayload)}, {"PullRequestEvent", typeof(PullRequestEventPayload)}, + {"PullRequestReviewEvent", typeof(PullRequestReviewEventPayload)}, {"PullRequestReviewCommentEvent", typeof(PullRequestCommentPayload)}, {"PushEvent", typeof(PushEventPayload)}, {"StatusEvent", typeof(StatusEventPayload)}, @@ -743,6 +744,43 @@ public async Task DeserializesPullRequestEventCorrectly() Assert.Equal("PR Title", payload.PullRequest.Title); } + [Fact] + public async Task DeserializesPullRequestReviewEventCorrectly() + { + var jsonObj = new JsonObject + { + { "type", "PullRequestReviewEvent" }, + { + "payload", new + { + action = "submitted", + review = new { + id = 2626884, + body = "Looks great!", + state = "approved", + html_url = "https://github.com/baxterthehacker/public-repo/pull/8#pullrequestreview-2626884", + }, + pull_request = new + { + title = "PR Title" + } + } + } + }; + + var client = GetTestingEventsClient(jsonObj); + var activities = await client.GetAll(); + Assert.Equal(1, activities.Count); + + var payload = activities.FirstOrDefault().Payload as PullRequestReviewEventPayload; + Assert.Equal("submitted", payload.Action); + Assert.Equal(2626884, payload.Review.Id); + Assert.Equal("Looks great!", payload.Review.Body); + Assert.Equal(PullRequestReviewState.Approved, payload.Review.State.Value); + Assert.Equal("https://github.com/baxterthehacker/public-repo/pull/8#pullrequestreview-2626884", payload.Review.HtmlUrl); + Assert.Equal("PR Title", payload.PullRequest.Title); + } + [Fact] public async Task DeserializesPullRequestCommentEventCorrectly() { diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index 97eec56ee5..e85ff70d99 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -216,6 +216,8 @@ private static Type GetPayloadType(string activityType) return typeof(IssueEventPayload); case "PullRequestEvent": return typeof(PullRequestEventPayload); + case "PullRequestReviewEvent": + return typeof(PullRequestReviewEventPayload); case "PullRequestReviewCommentEvent": return typeof(PullRequestCommentPayload); case "PushEvent": diff --git a/Octokit/Models/Response/ActivityPayloads/PullRequestReviewEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/PullRequestReviewEventPayload.cs new file mode 100644 index 0000000000..c0a7b10b5d --- /dev/null +++ b/Octokit/Models/Response/ActivityPayloads/PullRequestReviewEventPayload.cs @@ -0,0 +1,12 @@ +using System.Diagnostics; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class PullRequestReviewEventPayload : ActivityPayload + { + public string Action { get; protected set; } + public PullRequest PullRequest { get; protected set; } + public PullRequestReview Review { get; protected set; } + } +}