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 StatusEventPayload #1732

Merged
merged 2 commits into from
Jan 9, 2018
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 @@ -560,6 +560,7 @@ public async Task EnsuresNonNullArguments()
{"PullRequestEvent", typeof(PullRequestEventPayload)},
{"PullRequestReviewCommentEvent", typeof(PullRequestCommentPayload)},
{"PushEvent", typeof(PushEventPayload)},
{"StatusEvent", typeof(StatusEventPayload)},
{"WatchEvent", typeof(StarredEventPayload)},
{"unknown", typeof(ActivityPayload)}
};
Expand Down Expand Up @@ -810,6 +811,55 @@ public async Task DeserializesPushEventCorrectly()
Assert.Equal("message", payload.Commits.FirstOrDefault().Message);
}

[Fact]
public async Task DeserializesStatusEventCorrectly()
{
var jsonObj = new JsonObject
{
{ "type", "StatusEvent" },
{
"payload", new
{
id = 214015194,
sha = "9049f1265b7d61be4a8904a9a27120d2064dab3b",
name = "baxterthehacker/public-repo",
target_url = "https://www.some_target_url.com",
context = "default",
description = "some human readable text",
state = "success",
branches = new []
{
new
{
name = "master",
commit = new
{
sha = "9049f1265b7d61be4a8904a9a27120d2064dab3b",
url = "https://api.github.com/repos/baxterthehacker/public-repo/commits/9049f1265b7d61be4a8904a9a27120d2064dab3b"
}
}
},
created_at = "2015-05-05T23:40:39Z"
}
}
};

var client = GetTestingEventsClient(jsonObj);
var activities = await client.GetAll();
Assert.Equal(1, activities.Count);

var payload = activities.FirstOrDefault().Payload as StatusEventPayload;
Assert.Equal(214015194, payload.Id);
Assert.Equal("9049f1265b7d61be4a8904a9a27120d2064dab3b", payload.Sha);
Assert.Equal("baxterthehacker/public-repo", payload.Name);
Assert.Equal("https://www.some_target_url.com", payload.TargetUrl);
Assert.Equal("default", payload.Context);
Assert.Equal("some human readable text", payload.Description);
Assert.Equal(CommitState.Success, payload.State.Value);
Assert.Equal(1, payload.Branches.Count);
Assert.Equal(new DateTimeOffset(2015, 05, 05, 23, 40, 39, TimeSpan.Zero), payload.CreatedAt);
}

[Fact]
public async Task DeserializesStarredEventCorrectly()
{
Expand Down
2 changes: 2 additions & 0 deletions Octokit/Http/SimpleJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ private static Type GetPayloadType(string activityType)
return typeof(PullRequestCommentPayload);
case "PushEvent":
return typeof(PushEventPayload);
case "StatusEvent":
return typeof(StatusEventPayload);
case "WatchEvent":
return typeof(StarredEventPayload);
}
Expand Down
72 changes: 72 additions & 0 deletions Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class StatusEventPayload : ActivityPayload
{
/// <summary>
/// The name of the repository.
/// </summary>
public string Name { get; protected set; }

/// <summary>
/// The SHA of the reference.
/// </summary>
public string Sha { get; protected set; }

/// <summary>
/// The date the commit status was created.
/// </summary>
public DateTimeOffset CreatedAt { get; protected set; }

/// <summary>
/// The date the commit status was updated.
/// </summary>
public DateTimeOffset UpdatedAt { get; protected set; }

/// <summary>
/// The state of the commit
/// </summary>
public StringEnum<CommitState> State { get; protected set; }

/// <summary>
/// URL associated with this status. GitHub.com displays this URL as a link to allow users to easily see the
/// ‘source’ of the Status.
/// </summary>
public string TargetUrl { get; protected set; }

/// <summary>
/// Short description of the status.
/// </summary>
public string Description { get; protected set; }

/// <summary>
/// A string label to differentiate this status from the status of other systems.
/// </summary>
public string Context { get; protected set; }

/// <summary>
/// The unique identifier of the status.
/// </summary>
public long Id { get; protected set; }

/// <summary>
/// The relevant commit.
/// </summary>
public GitHubCommit Commit { get; protected set; }

/// <summary>
/// The organization associated with the event.
/// </summary>
public Organization Organization { get; protected set; }

/// <summary>
/// The branches involved.
/// </summary>
public IReadOnlyList<Branch> Branches { get; protected set; }

}
}