Skip to content

Commit

Permalink
Add support for CreateEventPayload and DeleteEvent payload (octokit#1646
Browse files Browse the repository at this point in the history
)
  • Loading branch information
GMouron committed Jan 30, 2019
1 parent 3470f45 commit 639830e
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Octokit.Tests/Clients/EventsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down Expand Up @@ -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()
{
Expand Down
4 changes: 4 additions & 0 deletions Octokit/Http/SimpleJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
13 changes: 13 additions & 0 deletions Octokit/Models/Response/ActivityPayloads/CreateEventPayload.cs
Original file line number Diff line number Diff line change
@@ -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> RefType { get; protected set; }
}
}
13 changes: 13 additions & 0 deletions Octokit/Models/Response/ActivityPayloads/DeleteEventPayload.cs
Original file line number Diff line number Diff line change
@@ -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> RefType { get; protected set; }
}
}
31 changes: 31 additions & 0 deletions Octokit/Models/Response/RefType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Diagnostics;
using System.Globalization;
using Octokit.Internal;

namespace Octokit
{
/// <summary>
/// Represents the type of object created or deleted
/// </summary>
public enum RefType
{
/// <summary>
/// The object is of type repository
/// </summary>
[Parameter(Value = "repository")]
Repository,

/// <summary>
/// The object is of type branch
/// </summary>
[Parameter(Value = "branch")]
Branch,

/// <summary>
/// The object is of type tag
/// </summary>
[Parameter(Value = "tag")]
Tag
}
}

0 comments on commit 639830e

Please sign in to comment.