Skip to content

Commit

Permalink
Fixed handling of build request user in build overview (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Grabarevic authored Aug 3, 2018
1 parent a143566 commit 2ae782f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
14 changes: 11 additions & 3 deletions BuildsAppReborn.Access/TFS/Models/TfsBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@ public IUser DisplayUser
{
get
{
if (SourceVersion != null)
// if not requested by service user, it was by user. So show user.
if (Requester != null && !Requester.IsServiceUser)
{
if (SourceVersion.Pusher.Id != TfsConsts.MicrosoftTeamFoundationSystemId)
return Requester;
}

// tries to determine the pusher of the commit, and show him if not service user
if (SourceVersion?.Pusher != null)
{
if (!SourceVersion.Pusher.IsServiceUser)
{
return SourceVersion.Pusher;
}
}

// fallback value
return Requester;
}
}
Expand Down Expand Up @@ -99,7 +107,7 @@ public BuildReason Reason
}
}

[JsonProperty("requestedFor")]
[JsonProperty("requestedBy")]
public abstract IUser Requester { get; protected set; }

[JsonIgnore]
Expand Down
3 changes: 3 additions & 0 deletions BuildsAppReborn.Access/TFS/Models/TfsUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public Byte[] ImageData
[JsonProperty("imageUrl")]
public String ImageUrl { get; private set; }

[JsonIgnore]
public Boolean IsServiceUser => Id == TfsConsts.MicrosoftTeamFoundationSystemId;

public override String Name
{
get { return base.Name ?? DisplayName; }
Expand Down
2 changes: 1 addition & 1 deletion BuildsAppReborn.Access/TFS/TfsBuildProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private static async Task<TSourceVersion> GetTfsGitSourceVersionAsync(BuildMonit
if (build.Reason == BuildReason.PullRequest ||
build.Reason == BuildReason.Validation)
{
if (sourceVersion != null && sourceVersion.Parents.Length > 1 && sourceVersion.Pusher.Id == TfsConsts.MicrosoftTeamFoundationSystemId)
if (sourceVersion?.Parents != null && sourceVersion.Parents.Length > 1 && sourceVersion.Pusher != null && sourceVersion.Pusher.IsServiceUser)
{
var innerRequestUrl = $"{projectUrl}/_apis/git/repositories/{build.Repository.Id}/commits/{sourceVersion.Parents.Last()}?api-version=1.0";

Expand Down
6 changes: 3 additions & 3 deletions BuildsAppReborn.Contracts.UI/BuildItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public String Comment
{
if (Build?.SourceVersion?.Comment != null)
{
return ManualRequested ? $"{Build.DisplayUser.DisplayName}: {Build.SourceVersion.Comment}" : Build.SourceVersion.Comment;
return ManuallyRequested ? $"{Build.SourceVersion.Pusher.DisplayName}: {Build.SourceVersion.Comment}" : Build.SourceVersion.Comment;
}

return "-";
Expand All @@ -103,7 +103,7 @@ public String Description

public Byte[] DisplayUserImage => Build?.DisplayUser?.ImageData;

public String DisplayUserText => ManualRequested ? $"Requested by: {Build.Requester.DisplayName}" : Build.DisplayUser.DisplayName;
public String DisplayUserText => ManuallyRequested ? $"Requested by: {Build.Requester.DisplayName}" : Build.DisplayUser.DisplayName;

[SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")]
public void Refresh()
Expand All @@ -116,7 +116,7 @@ public void Refresh()
OnPropertyChanged(nameof(CurrentTestRun));
}

private Boolean ManualRequested => Build.Reason == BuildReason.Manual;
private Boolean ManuallyRequested => !Build.Requester.IsServiceUser;

private readonly BuildViewStyle viewStyle;
}
Expand Down
2 changes: 2 additions & 0 deletions BuildsAppReborn.Contracts/Models/IUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface IUser : IObjectItem

String ImageUrl { get; }

Boolean IsServiceUser { get; }

String UniqueName { get; }
}
}

0 comments on commit 2ae782f

Please sign in to comment.