From 2d1b6b56de781e906fce2ede52b0654e8011a443 Mon Sep 17 00:00:00 2001 From: Bert Cotton Date: Thu, 14 Sep 2017 12:35:15 -0600 Subject: [PATCH] Fixing JobRequests now properly showing releases. Starting to add in comparitors --- .../Comparator/PullRequestComparator.cs | 71 +++++++++++++++++++ src/TfsAdvanced.DataStore/DataStore.csproj | 8 +-- .../Repository/PullRequestRepository.cs | 9 +++ .../Repository/ReleaseDefinitionRepository.cs | 4 +- .../PullRequestComparison.cs | 19 +++++ src/TfsAdvanced.Models/DTO/PullRequest.cs | 2 + src/TfsAdvanced.Models/Models.csproj | 5 -- .../Tasks/JobRequestUpdater.cs | 6 +- .../Tasks/PullRequestUpdaterBase.cs | 2 + src/TfsAdvanced/wwwroot/index.html | 11 ++- src/TfsAdvanced/wwwroot/js/jobRequests.js | 3 + src/TfsAdvanced/wwwroot/js/pullRequests.js | 3 + .../wwwroot/views/pullRequests.html | 16 ++--- 13 files changed, 135 insertions(+), 24 deletions(-) create mode 100644 src/TfsAdvanced.DataStore/Comparator/PullRequestComparator.cs create mode 100644 src/TfsAdvanced.Models/ComparisonResults/PullRequestComparison.cs diff --git a/src/TfsAdvanced.DataStore/Comparator/PullRequestComparator.cs b/src/TfsAdvanced.DataStore/Comparator/PullRequestComparator.cs new file mode 100644 index 0000000..4a0e1e3 --- /dev/null +++ b/src/TfsAdvanced.DataStore/Comparator/PullRequestComparator.cs @@ -0,0 +1,71 @@ +using System.Linq; +using TFSAdvanced.Models.ComparisonResults; +using TFSAdvanced.Models.DTO; + +namespace TfsAdvanced.Data.Comparator +{ + public class PullRequestComparator + { + public static PullRequestComparison Compare(PullRequest original, PullRequest updated) + { + PullRequestComparison comparison = new PullRequestComparison(); + if (original == null) + { + comparison.IsNewPullRequest = true; + return comparison; + } + + if (original.buildId != updated.buildId) + { + comparison.BuildStatusUpdated = true; + comparison.Messages.Add($"Build has changed from {original.buildId} to {updated.buildId}."); + } + + if (original.BuildStatus != updated.BuildStatus) + { + comparison.BuildStatusUpdated = true; + comparison.Messages.Add($"Build Status has changed from {original.BuildStatus} to {updated.BuildStatus}."); + } + + if (original.LastCommit != updated.LastCommit) + { + comparison.FilesChanged = true; + comparison.Messages.Add($"Files have been updated from commit {original.LastCommit} to {updated.LastCommit}"); + } + + + if (original.MergeStatus != updated.MergeStatus) + { + comparison.MergeStatusUpdated = true; + comparison.Messages.Add($"Merge status changed from {original.MergeStatus} to {original.MergeStatus}"); + } + + + foreach (var reviewer in original.Reviewers) + { + var updatedReviewer = updated.Reviewers.FirstOrDefault(x => x.UniqueName == reviewer.UniqueName); + if (updatedReviewer == null) + { + comparison.ReviewersUpdated = true; + comparison.Messages.Add($"{reviewer.Name} removed as a reviewer"); + } + else if (reviewer.ReviewStatus != updatedReviewer.ReviewStatus) + { + comparison.ReviewersUpdated = true; + comparison.Messages.Add($"{reviewer.Name} changed review status from {reviewer.ReviewStatus} to {updatedReviewer.ReviewStatus}"); + } + + } + foreach (var updatedReviewer in updated.Reviewers) + { + if (original.Reviewers.Any(x => x.UniqueName == updatedReviewer.UniqueName)) + continue; + + comparison.ReviewersUpdated = true; + comparison.Messages.Add($"{updatedReviewer.Name} added as reviewer with status {updatedReviewer.ReviewStatus}"); + } + + return comparison; + } + } +} \ No newline at end of file diff --git a/src/TfsAdvanced.DataStore/DataStore.csproj b/src/TfsAdvanced.DataStore/DataStore.csproj index a3602a6..da45d3e 100644 --- a/src/TfsAdvanced.DataStore/DataStore.csproj +++ b/src/TfsAdvanced.DataStore/DataStore.csproj @@ -1,24 +1,22 @@  - netcoreapp1.1 TFSAdvanced.DataStore TFSAdvanced.DataStore - - - C:\Users\bertc\.nuget\packages\microsoft.entityframeworkcore\1.0.3\lib\netstandard1.3\Microsoft.EntityFrameworkCore.dll - + + + \ No newline at end of file diff --git a/src/TfsAdvanced.DataStore/Repository/PullRequestRepository.cs b/src/TfsAdvanced.DataStore/Repository/PullRequestRepository.cs index 4b77ee6..86f30e5 100644 --- a/src/TfsAdvanced.DataStore/Repository/PullRequestRepository.cs +++ b/src/TfsAdvanced.DataStore/Repository/PullRequestRepository.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using TfsAdvanced.Data.Comparator; using TFSAdvanced.DataStore.Interfaces; using TFSAdvanced.DataStore.Repository; +using TFSAdvanced.Models.ComparisonResults; using TFSAdvanced.Models.DTO; namespace TfsAdvanced.DataStore.Repository @@ -20,8 +22,15 @@ protected override int GetId(PullRequest item) return item.Id; } + public PullRequestComparison Update(PullRequest updatedPullRequest) + { + var existing = base.Get(request => request.Id == updatedPullRequest.Id); + return PullRequestComparator.Compare(existing, updatedPullRequest); + } + public override bool Update(IEnumerable updates) { + bool updated = base.Update(updates); // If an update was not received, then remove it var noUpdate = base.GetList(request => !updates.Select(x => x.Id).Contains(request.Id)); diff --git a/src/TfsAdvanced.DataStore/Repository/ReleaseDefinitionRepository.cs b/src/TfsAdvanced.DataStore/Repository/ReleaseDefinitionRepository.cs index f4ecb3b..7b63a69 100644 --- a/src/TfsAdvanced.DataStore/Repository/ReleaseDefinitionRepository.cs +++ b/src/TfsAdvanced.DataStore/Repository/ReleaseDefinitionRepository.cs @@ -9,9 +9,9 @@ protected override int GetId(ReleaseDefinition item) return item.Id; } - public ReleaseDefinition GetReleaseDefinition(int id) + public ReleaseDefinition GetReleaseDefinition(string projectId, int id) { - return Get(definition => definition.Id == id); + return Get(definition => definition.Project.Id == projectId && definition.Id == id); } } } diff --git a/src/TfsAdvanced.Models/ComparisonResults/PullRequestComparison.cs b/src/TfsAdvanced.Models/ComparisonResults/PullRequestComparison.cs new file mode 100644 index 0000000..da90f7e --- /dev/null +++ b/src/TfsAdvanced.Models/ComparisonResults/PullRequestComparison.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; + +namespace TFSAdvanced.Models.ComparisonResults +{ + public class PullRequestComparison + { + public bool IsNewPullRequest { get; set; } + + public bool ReviewersUpdated { get; set; } + + public bool BuildStatusUpdated { get; set; } + + public bool MergeStatusUpdated { get; set; } + + public bool FilesChanged { get; set; } + + public IList Messages { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/src/TfsAdvanced.Models/DTO/PullRequest.cs b/src/TfsAdvanced.Models/DTO/PullRequest.cs index 6f151fc..6a8b133 100644 --- a/src/TfsAdvanced.Models/DTO/PullRequest.cs +++ b/src/TfsAdvanced.Models/DTO/PullRequest.cs @@ -36,5 +36,7 @@ public class PullRequest public DateTime CreatedDate { get; set; } public DateTime? ClosedDate { get; set; } + + public string LastCommit { get; set; } } } diff --git a/src/TfsAdvanced.Models/Models.csproj b/src/TfsAdvanced.Models/Models.csproj index 615a40c..fe5b8bf 100644 --- a/src/TfsAdvanced.Models/Models.csproj +++ b/src/TfsAdvanced.Models/Models.csproj @@ -1,5 +1,4 @@  - netcoreapp1.1 @@ -10,7 +9,6 @@ TFSAdvanced.Models TFSAdvanced.Models - C:\Users\bertc\.nuget\packages\microsoft.aspnetcore.identity.entityframeworkcore\1.0.2\lib\netstandard1.3\Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll @@ -19,13 +17,10 @@ C:\Users\bertc\.nuget\packages\microsoft.extensions.options\1.0.2\lib\netstandard1.0\Microsoft.Extensions.Options.dll - - - \ No newline at end of file diff --git a/src/TfsAdvanced.Updater/Tasks/JobRequestUpdater.cs b/src/TfsAdvanced.Updater/Tasks/JobRequestUpdater.cs index c80b046..a892e5f 100644 --- a/src/TfsAdvanced.Updater/Tasks/JobRequestUpdater.cs +++ b/src/TfsAdvanced.Updater/Tasks/JobRequestUpdater.cs @@ -65,6 +65,7 @@ protected override void Update() if (poolJobRequest.planType == PlanTypes.Build) { + queueJob.JobType = JobType.Build; var build = buildRepository.GetBuild(poolJobRequest.owner.id); if (build != null) { @@ -98,7 +99,7 @@ protected override void Update() } var buildDefinition = buildDefinitionRepository.GetBuildDefinition(poolJobRequest.definition.id); - if (buildDefinition != null && buildDefinition.Repository != null) + if (buildDefinition?.Repository != null) { var project = projectRepository.GetProject(buildDefinition.Repository.Project.Id); if (project != null) @@ -129,6 +130,7 @@ protected override void Update() else if (poolJobRequest.planType == PlanTypes.Release) { + queueJob.JobType = JobType.Release; if (poolJobRequest.finishTime.HasValue) { switch (poolJobRequest.result) @@ -149,7 +151,7 @@ protected override void Update() } } - var releaseDefinition = releaseDefinitionRepository.GetReleaseDefinition(poolJobRequest.definition.id); + var releaseDefinition = releaseDefinitionRepository.GetReleaseDefinition(poolJobRequest.scopeId.ToString(), poolJobRequest.definition.id); if (releaseDefinition != null) { queueJob.Project = releaseDefinition.Project; diff --git a/src/TfsAdvanced.Updater/Tasks/PullRequestUpdaterBase.cs b/src/TfsAdvanced.Updater/Tasks/PullRequestUpdaterBase.cs index 8decd22..373b87d 100644 --- a/src/TfsAdvanced.Updater/Tasks/PullRequestUpdaterBase.cs +++ b/src/TfsAdvanced.Updater/Tasks/PullRequestUpdaterBase.cs @@ -86,6 +86,7 @@ protected override void Update() pullRequestDto.AcceptedReviewers++; } allPullRequests.Add(pullRequestDto); + } catch (Exception e) { @@ -135,6 +136,7 @@ private PullRequest BuildPullRequest(TFSAdvanced.Updater.Models.PullRequests.Pul HasEnoughReviewers = x.hasEnoughReviewers, AcceptedReviewers = x.acceptedReviewers, RequiredReviewers = x.requiredReviewers, + LastCommit = x.lastMergeSourceCommit.commitId, Reviewers = new List() }; diff --git a/src/TfsAdvanced/wwwroot/index.html b/src/TfsAdvanced/wwwroot/index.html index 0425401..f10b08c 100644 --- a/src/TfsAdvanced/wwwroot/index.html +++ b/src/TfsAdvanced/wwwroot/index.html @@ -114,11 +114,20 @@

TFS Advanced is Loading

}); }; - + + function FullRefresh() { + console.log("Full Refresh"); + window.location = "/"; + // 10 Minutes + setTimeout(FullRefresh, 600000); + } $(document) .ready(function () { + // 10 Minutes + setTimeout(FullRefresh, 600000); + $.fn.dataTable.ext.errMode = 'none'; diff --git a/src/TfsAdvanced/wwwroot/js/jobRequests.js b/src/TfsAdvanced/wwwroot/js/jobRequests.js index 043ad2e..1f5f5c2 100644 --- a/src/TfsAdvanced/wwwroot/js/jobRequests.js +++ b/src/TfsAdvanced/wwwroot/js/jobRequests.js @@ -16,6 +16,9 @@ $(document) jobRequest.requestId + ""; + if (jobRequest.name === "Claimant Management Service") + console.log(jobRequest); + if (jobRequest.jobType === 'release') json[i][column++] = '' + jobRequest.jobType; diff --git a/src/TfsAdvanced/wwwroot/js/pullRequests.js b/src/TfsAdvanced/wwwroot/js/pullRequests.js index 317131f..b0fe3ba 100644 --- a/src/TfsAdvanced/wwwroot/js/pullRequests.js +++ b/src/TfsAdvanced/wwwroot/js/pullRequests.js @@ -21,6 +21,9 @@ function fetchData() { } +// Every minute reformat so that the dates keep updated +setTimeout(formatPage, 60000); + function HandlMyPullRequests() { var myPullRequests = JSON.parse(localStorage.getItem("CurrentUserPullRequests")); diff --git a/src/TfsAdvanced/wwwroot/views/pullRequests.html b/src/TfsAdvanced/wwwroot/views/pullRequests.html index 360eb5f..5c02d85 100644 --- a/src/TfsAdvanced/wwwroot/views/pullRequests.html +++ b/src/TfsAdvanced/wwwroot/views/pullRequests.html @@ -82,16 +82,15 @@

My Completed Pull Requests - Past 2 Days

${Title} +

- - - {{if MergeStatus == 'conflicts'}} + {{if MergeStatus == 'failed'}} {{/if}}
@@ -157,8 +156,7 @@

{{/if}} - - {{if MergeStatus == 'conflicts'}} + {{if MergeStatus == 'Failed'}} {{/if}}