Skip to content

Commit

Permalink
Merge pull request #56 from BertCotton/BC.JobRequests
Browse files Browse the repository at this point in the history
Fixing JobRequests now properly showing releases.
  • Loading branch information
BertCotton authored Sep 14, 2017
2 parents 178918a + 2d1b6b5 commit 5ddc988
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 24 deletions.
71 changes: 71 additions & 0 deletions src/TfsAdvanced.DataStore/Comparator/PullRequestComparator.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
8 changes: 3 additions & 5 deletions src/TfsAdvanced.DataStore/DataStore.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<AssemblyName>TFSAdvanced.DataStore</AssemblyName>
<RootNamespace>TFSAdvanced.DataStore</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TfsAdvanced.Models\Models.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.EntityFrameworkCore">
<HintPath>C:\Users\bertc\.nuget\packages\microsoft.entityframeworkcore\1.0.3\lib\netstandard1.3\Microsoft.EntityFrameworkCore.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<Folder Include="Comparitors" />
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions src/TfsAdvanced.DataStore/Repository/PullRequestRepository.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<PullRequest> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
19 changes: 19 additions & 0 deletions src/TfsAdvanced.Models/ComparisonResults/PullRequestComparison.cs
Original file line number Diff line number Diff line change
@@ -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<string> Messages { get; set; } = new List<string>();
}
}
2 changes: 2 additions & 0 deletions src/TfsAdvanced.Models/DTO/PullRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ public class PullRequest
public DateTime CreatedDate { get; set; }

public DateTime? ClosedDate { get; set; }

public string LastCommit { get; set; }
}
}
5 changes: 0 additions & 5 deletions src/TfsAdvanced.Models/Models.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<Company />
Expand All @@ -10,7 +9,6 @@
<AssemblyName>TFSAdvanced.Models</AssemblyName>
<RootNamespace>TFSAdvanced.Models</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore">
<HintPath>C:\Users\bertc\.nuget\packages\microsoft.aspnetcore.identity.entityframeworkcore\1.0.2\lib\netstandard1.3\Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll</HintPath>
Expand All @@ -19,13 +17,10 @@
<HintPath>C:\Users\bertc\.nuget\packages\microsoft.extensions.options\1.0.2\lib\netstandard1.0\Microsoft.Extensions.Options.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.2" />
</ItemGroup>

</Project>
6 changes: 4 additions & 2 deletions src/TfsAdvanced.Updater/Tasks/JobRequestUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/TfsAdvanced.Updater/Tasks/PullRequestUpdaterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ protected override void Update()
pullRequestDto.AcceptedReviewers++;
}
allPullRequests.Add(pullRequestDto);

}
catch (Exception e)
{
Expand Down Expand Up @@ -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<Reviewer>()
};

Expand Down
11 changes: 10 additions & 1 deletion src/TfsAdvanced/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,20 @@ <h2 class="text-center">TFS Advanced is Loading</h2>
});
};



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';


Expand Down
3 changes: 3 additions & 0 deletions src/TfsAdvanced/wwwroot/js/jobRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ $(document)
jobRequest.requestId +
"</a>";

if (jobRequest.name === "Claimant Management Service")
console.log(jobRequest);

if (jobRequest.jobType === 'release')
json[i][column++] = '<span class="glyphicon glyphicon-plane" style="color:blue"></span>' +
jobRequest.jobType;
Expand Down
3 changes: 3 additions & 0 deletions src/TfsAdvanced/wwwroot/js/pullRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
16 changes: 7 additions & 9 deletions src/TfsAdvanced/wwwroot/views/pullRequests.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,15 @@ <h2>My Completed Pull Requests - Past 2 Days</h2>
<div class="col-lg-4 col-md-12" style="padding: 5px">
<h4>
<a style="color:darkslategray" href="${Url}" target="_blank">${Title}</a>
<span class="hidden-xs">
{{if IsAutoCompleteSet}}
<span style="color:goldenrod"><i class="glyphicon glyphicon-thumbs-up" title="Autocomplete Set"></i><span class="hidden-xs"></span></span><br/>
{{/if}}
</span>
</h4>
<h5>
<div>
<span class="hidden-xs">
{{if isAutoCompleteSet}}
<span style="color:goldenrod"><i class="glyphicon glyphicon-thumbs-up"></i><span class="hidden-xs"> AutoComplete Set</span></span><br/>
{{/if}}
</span>

{{if MergeStatus == 'conflicts'}}
{{if MergeStatus == 'failed'}}
<span style="color:red"><i class="glyphicon glyphicon-remove"></i><span class="hidden-xs"> Merge Conflicts</span></span>
{{/if}}
</div>
Expand Down Expand Up @@ -157,8 +156,7 @@ <h5>
<span style="color:goldenrod"><i class="glyphicon glyphicon-thumbs-up"></i><span class="hidden-xs"> AutoComplete Set</span></span><br/>
{{/if}}
</span>

{{if MergeStatus == 'conflicts'}}
{{if MergeStatus == 'Failed'}}
<span style="color:red"><i class="glyphicon glyphicon-remove"></i><span class="hidden-xs"> Merge Conflicts</span></span>
{{/if}}
</div>
Expand Down

0 comments on commit 5ddc988

Please sign in to comment.