Created
November 1, 2018 09:14
-
-
Save VatthanachaiW/f2dbe6c036beb395520a2004753935f5 to your computer and use it in GitHub Desktop.
Gitlab Push Event Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Microsoft.Ajax.Utilities; | |
using Newtonsoft.Json; | |
namespace GitlabNotifications.Models | |
{ | |
public class PushEvent | |
{ | |
[JsonProperty("object_kind")] public string ObjectKind { get; set; } | |
[JsonProperty("before")] public string Before { get; set; } | |
[JsonProperty("after")] public string After { get; set; } | |
[JsonProperty("_ref")] public string Ref { get; set; } | |
[JsonProperty("checkout_sha")] public string CheckoutSha { get; set; } | |
[JsonProperty("user_id")] public int UserId { get; set; } | |
[JsonProperty("user_name")] public string UserName { get; set; } | |
[JsonProperty("user_username")] public string UserUsername { get; set; } | |
[JsonProperty("user_email")] public string UserEmail { get; set; } | |
[JsonProperty("user_avatar")] public string UserAvatar { get; set; } | |
[JsonProperty("project_id")] public int ProjectId { get; set; } | |
[JsonProperty("project")] public Project Project { get; set; } | |
[JsonProperty("repository")] public Repository Repository { get; set; } | |
[JsonProperty("commits")] public List<Commit> Commits { get; set; } | |
[JsonProperty("total_commits_count")] public int TotalCommitsCount { get; set; } | |
public override string ToString() | |
{ | |
return | |
$"\nRepository: {Repository} ({Project.Homepage})\nUser: {Commits.FirstOrDefault().Author}\n\nCommits:\n{string.Join("\n", Commits)}"; | |
} | |
} | |
public class Project | |
{ | |
[JsonProperty("id")] public int Id { get; set; } | |
[JsonProperty("name")] public string Name { get; set; } | |
[JsonProperty("description")] public string Description { get; set; } | |
[JsonProperty("web_url")] public string WebUrl { get; set; } | |
[JsonProperty("avatar_url")] public object AvatarUrl { get; set; } | |
[JsonProperty("git_ssh_url")] public string GitSshUrl { get; set; } | |
[JsonProperty("git_http_url")] public string GitHttpUrl { get; set; } | |
[JsonProperty("_namespace")] public string Namespace { get; set; } | |
[JsonProperty("visibility_level")] public int VisibilityLevel { get; set; } | |
[JsonProperty("path_with_namespace")] public string PathWithNamespace { get; set; } | |
[JsonProperty("default_branch")] public string DefaultBranch { get; set; } | |
[JsonProperty("homepage")] public string Homepage { get; set; } | |
[JsonProperty("url")] public string Url { get; set; } | |
[JsonProperty("ssh_url")] public string SshUrl { get; set; } | |
[JsonProperty("http_url")] public string HttpUrl { get; set; } | |
public override string ToString() | |
{ | |
return $"{Name} : {Description} ({Url})"; | |
} | |
} | |
public class Repository | |
{ | |
[JsonProperty("name")] public string Name { get; set; } | |
[JsonProperty("url")] public string Url { get; set; } | |
[JsonProperty("description")] public string Description { get; set; } | |
[JsonProperty("homepage")] public string Homepage { get; set; } | |
[JsonProperty("git_http_url")] public string GitHttpUrl { get; set; } | |
[JsonProperty("git_ssh_url")] public string GitSshUrl { get; set; } | |
[JsonProperty("visibility_level")] public int VisibilityLevel { get; set; } | |
public override string ToString() | |
{ | |
return $"\bRepository : [{Name}]"; | |
} | |
} | |
public class Commit | |
{ | |
[JsonProperty("id")] public string Id { get; set; } | |
[JsonProperty("message")] public string Message { get; set; } | |
[JsonProperty("timestamp")] public DateTime Timestamp { get; set; } | |
[JsonProperty("url")] public string Url { get; set; } | |
[JsonProperty("author")] public Author Author { get; set; } | |
[JsonProperty("added")] public List<string> Added { get; set; } | |
[JsonProperty("modified")] public List<string> Modified { get; set; } | |
[JsonProperty("removed")] public List<string> Removed { get; set; } | |
public override string ToString() | |
{ | |
StringBuilder sb = new StringBuilder(); | |
sb.Append($"\b\bMessage: {Message}"); | |
if (Added.Any()) | |
{ | |
sb.Append($"\b\b\b\bAdded: [{string.Join(", ", Added)}]"); | |
} | |
if (Modified.Any()) | |
{ | |
sb.Append($"\b\b\b\bModified: [{string.Join(", ", Modified)}]"); | |
} | |
if (Removed.Any()) | |
{ | |
sb.Append($"\b\b\b\bRemoved: [{string.Join(", ", Removed)}]"); | |
} | |
return sb.ToString(); | |
} | |
} | |
public class Author | |
{ | |
[JsonProperty("name")] public string Name { get; set; } | |
[JsonProperty("email")] public string Email { get; set; } | |
public override string ToString() | |
{ | |
return $"{Name} ({Email})"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment