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

Add support for CreateEventPayload and DeleteEvent payload (#1646) #1932

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
17 changes: 17 additions & 0 deletions Octokit/Models/Response/ActivityPayloads/CreateEventPayload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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; }

public string MasterBranch { get; protected set; }

public string Description { 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")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: missing a whitespace line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed :)

Branch,

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