diff --git a/Octokit.Tests/Clients/EventsClientTests.cs b/Octokit.Tests/Clients/EventsClientTests.cs index 99a65a7cd4..fb38f29252 100644 --- a/Octokit.Tests/Clients/EventsClientTests.cs +++ b/Octokit.Tests/Clients/EventsClientTests.cs @@ -556,6 +556,8 @@ public async Task EnsuresNonNullArguments() {"CheckRunEvent", typeof(CheckRunEventPayload)}, {"CheckSuiteEvent", typeof(CheckSuiteEventPayload)}, {"CommitCommentEvent", typeof(CommitCommentPayload)}, + {"CreateEvent", typeof(CreateEventPayload)}, + {"DeleteEvent", typeof(DeleteEventPayload)}, {"ForkEvent", typeof(ForkEventPayload)}, {"IssueCommentEvent", typeof(IssueCommentPayload)}, {"IssuesEvent", typeof(IssueEventPayload)}, @@ -623,6 +625,54 @@ public async Task DeserializesCommitCommentEventCorrectly() Assert.Equal(1337, payload.Comment.Id); } + [Fact] + public async Task DeserializesCreateEventCorrectly() + { + var jsonObj = new JsonObject + { + { "type", "CreateEvent" }, + { + "payload", new + { + @ref = "master", + ref_type = "branch", + } + } + }; + + var client = GetTestingEventsClient(jsonObj); + var activities = await client.GetAll(); + Assert.Equal(1, activities.Count); + + var payload = activities.FirstOrDefault().Payload as CreateEventPayload; + Assert.Equal("master", payload.Ref); + Assert.Equal(RefType.Branch, payload.RefType); + } + + [Fact] + public async Task DeserializesDeleteEventCorrectly() + { + var jsonObj = new JsonObject + { + { "type", "DeleteEvent" }, + { + "payload", new + { + @ref = "master", + ref_type = "branch", + } + } + }; + + var client = GetTestingEventsClient(jsonObj); + var activities = await client.GetAll(); + Assert.Equal(1, activities.Count); + + var payload = activities.FirstOrDefault().Payload as DeleteEventPayload; + Assert.Equal("master", payload.Ref); + Assert.Equal(RefType.Branch, payload.RefType); + } + [Fact] public async Task DeserializesForkEventCorrectly() { diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index 0e6aa45ba3..dee7f87f62 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -212,6 +212,10 @@ private static Type GetPayloadType(string activityType) return typeof(CheckSuiteEventPayload); case "CommitCommentEvent": return typeof(CommitCommentPayload); + case "CreateEvent": + return typeof(CreateEventPayload); + case "DeleteEvent": + return typeof(DeleteEventPayload); case "ForkEvent": return typeof(ForkEventPayload); case "IssueCommentEvent": diff --git a/Octokit/Models/Response/ActivityPayloads/CreateEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/CreateEventPayload.cs new file mode 100644 index 0000000000..cca64ab8be --- /dev/null +++ b/Octokit/Models/Response/ActivityPayloads/CreateEventPayload.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Diagnostics; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CreateEventPayload : ActivityPayload + { + public string Ref { get; protected set; } + + public StringEnum RefType { get; protected set; } + } +} diff --git a/Octokit/Models/Response/ActivityPayloads/DeleteEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/DeleteEventPayload.cs new file mode 100644 index 0000000000..6abd970c01 --- /dev/null +++ b/Octokit/Models/Response/ActivityPayloads/DeleteEventPayload.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Diagnostics; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class DeleteEventPayload : ActivityPayload + { + public string Ref { get; protected set; } + + public StringEnum RefType { get; protected set; } + } +} diff --git a/Octokit/Models/Response/RefType.cs b/Octokit/Models/Response/RefType.cs new file mode 100644 index 0000000000..5fda1695b8 --- /dev/null +++ b/Octokit/Models/Response/RefType.cs @@ -0,0 +1,30 @@ +using System; +using System.Diagnostics; +using System.Globalization; +using Octokit.Internal; + +namespace Octokit +{ + /// + /// Represents the type of object created or deleted + /// + public enum RefType + { + /// + /// The object is of type repository + /// + [Parameter(Value = "repository")] + Repository, + /// + /// The object is of type branch + /// + [Parameter(Value = "branch")] + Branch, + + /// + /// The object is of type tag + /// + [Parameter(Value = "tag")] + Tag + } +}