From 2ae782f6af7513bb7b1da505c971e6008aabc377 Mon Sep 17 00:00:00 2001 From: Luka Grabarevic Date: Fri, 3 Aug 2018 15:06:48 +0200 Subject: [PATCH] Fixed handling of build request user in build overview (#33) --- BuildsAppReborn.Access/TFS/Models/TfsBuild.cs | 14 +++++++++++--- BuildsAppReborn.Access/TFS/Models/TfsUser.cs | 3 +++ BuildsAppReborn.Access/TFS/TfsBuildProviderBase.cs | 2 +- BuildsAppReborn.Contracts.UI/BuildItem.cs | 6 +++--- BuildsAppReborn.Contracts/Models/IUser.cs | 2 ++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/BuildsAppReborn.Access/TFS/Models/TfsBuild.cs b/BuildsAppReborn.Access/TFS/Models/TfsBuild.cs index f1360f5..4de279e 100644 --- a/BuildsAppReborn.Access/TFS/Models/TfsBuild.cs +++ b/BuildsAppReborn.Access/TFS/Models/TfsBuild.cs @@ -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; } } @@ -99,7 +107,7 @@ public BuildReason Reason } } - [JsonProperty("requestedFor")] + [JsonProperty("requestedBy")] public abstract IUser Requester { get; protected set; } [JsonIgnore] diff --git a/BuildsAppReborn.Access/TFS/Models/TfsUser.cs b/BuildsAppReborn.Access/TFS/Models/TfsUser.cs index 764edba..28c2fa7 100644 --- a/BuildsAppReborn.Access/TFS/Models/TfsUser.cs +++ b/BuildsAppReborn.Access/TFS/Models/TfsUser.cs @@ -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; } diff --git a/BuildsAppReborn.Access/TFS/TfsBuildProviderBase.cs b/BuildsAppReborn.Access/TFS/TfsBuildProviderBase.cs index 83f64d7..9dcd2c4 100644 --- a/BuildsAppReborn.Access/TFS/TfsBuildProviderBase.cs +++ b/BuildsAppReborn.Access/TFS/TfsBuildProviderBase.cs @@ -188,7 +188,7 @@ private static async Task 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"; diff --git a/BuildsAppReborn.Contracts.UI/BuildItem.cs b/BuildsAppReborn.Contracts.UI/BuildItem.cs index 886bec2..ff7417c 100644 --- a/BuildsAppReborn.Contracts.UI/BuildItem.cs +++ b/BuildsAppReborn.Contracts.UI/BuildItem.cs @@ -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 "-"; @@ -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() @@ -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; } diff --git a/BuildsAppReborn.Contracts/Models/IUser.cs b/BuildsAppReborn.Contracts/Models/IUser.cs index 313bf04..dd3f838 100644 --- a/BuildsAppReborn.Contracts/Models/IUser.cs +++ b/BuildsAppReborn.Contracts/Models/IUser.cs @@ -13,6 +13,8 @@ public interface IUser : IObjectItem String ImageUrl { get; } + Boolean IsServiceUser { get; } + String UniqueName { get; } } } \ No newline at end of file