Skip to content

Commit

Permalink
Add fields to activity call (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jontdelorme authored Jun 2, 2021
1 parent 1c407d9 commit 4e71956
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
37 changes: 32 additions & 5 deletions NGitLab/Models/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,53 @@ public class Event
[DataMember(Name = "push_data")]
public PushData PushData { get; set; }

/// <summary>
/// The target is either a gitlab object (like a merge request)
/// or a commit object
/// </summary>
public string ResolvedTargetTitle
{
get
{
if (TargetTitle != null)
{
return $"{TargetType} '{TargetTitle}'";
}

if (PushData != null)
{
return $"{PushData.RefType} '{PushData.Ref}'";
}

return string.Empty;
}
}

/// <summary>
/// Debug display
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"{AuthorUserName} {Action} {TargetType} {GetAge(CreatedAt)}";
return ToString(ProjectId.ToString());
}

public string ToString(string projectName)
{
return $"{AuthorUserName} {Action} {ResolvedTargetTitle} at {projectName} ({GetAge(CreatedAt)})";
}

private static string GetAge(DateTime date)
{
var age = DateTime.Now.Subtract(date);
var age = DateTime.UtcNow.Subtract(date);

if (age.TotalDays > 1)
return $"{age.TotalDays:0.0} days ago";
return $"{age.TotalDays:0} days ago";

if (age.TotalHours > 1)
return $"{age.Hours:0.0} hours ago";
return $"{age.Hours:0} hours ago";

return $"{age.Minutes:0.0} minutes ago";
return $"{age.Minutes:0} minutes ago";
}
}
}
9 changes: 9 additions & 0 deletions NGitLab/Models/PushData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@ public class PushData

[DataMember(Name = "action")]
public PushDataAction Action { get; set; }

[DataMember(Name = "ref")]
public string Ref { get; set; }

[DataMember(Name = "ref_type")]
public CommitRefType RefType { get; set; }

[DataMember(Name = "commit_title")]
public string CommitTitle { get; set; }
}
}

0 comments on commit 4e71956

Please sign in to comment.