Comments updated and weeks additions and deletions logic added
This commit is contained in:
@@ -135,7 +135,7 @@ else
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h1 class="text-center">Community GitHub Contributions</h1>
|
<h1 class="text-center">GitHub Contributions</h1>
|
||||||
<p>
|
<p>
|
||||||
Contributions to Umbraco GitHub repositories
|
Contributions to Umbraco GitHub repositories
|
||||||
<small class="link-list">
|
<small class="link-list">
|
||||||
|
|||||||
@@ -4,13 +4,17 @@
|
|||||||
{
|
{
|
||||||
foreach (var contributor in Model.Contributors)
|
foreach (var contributor in Model.Contributors)
|
||||||
{
|
{
|
||||||
var author = contributor.First().Author;
|
var author = contributor.Author;
|
||||||
if (author != null)
|
if (author != null)
|
||||||
{
|
{
|
||||||
<a href="@author.HtmlUrl" class="contributor" target="_blank">
|
<a href="@author.HtmlUrl" class="contributor" target="_blank">
|
||||||
<div class="avatar">
|
<div class="avatar">
|
||||||
<img alt="@author.Login" src="@author.AvatarUrl&s=112" title="@author.Login" />
|
<img alt="@author.Login" src="@author.AvatarUrl&s=112" title="@author.Login" />
|
||||||
<span class="contrib-count" title="@(contributor.Sum(x=>x.Total) + " contributions")">@contributor.Sum(x => x.Total)</span>
|
<span class="contrib-count" title="@(contributor.TotalCommits + " contributions")">@contributor.TotalCommits</span>
|
||||||
|
<div>
|
||||||
|
Additions: @contributor.TotalAdditions
|
||||||
|
<br />Deletions: @contributor.TotalDeletions
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Web.Http;
|
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using OurUmbraco.Community.Models;
|
using OurUmbraco.Community.Models;
|
||||||
using OurUmbraco.Our.Api;
|
using OurUmbraco.Our.Api;
|
||||||
@@ -16,7 +15,7 @@ namespace OurUmbraco.Community.Controllers
|
|||||||
public class GitHubContributorController : SurfaceController
|
public class GitHubContributorController : SurfaceController
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Repositories to include in the combination
|
/// Repositories to include in the combination of contributions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly string[] Repositories =
|
private readonly string[] Repositories =
|
||||||
{
|
{
|
||||||
@@ -44,9 +43,9 @@ namespace OurUmbraco.Community.Controllers
|
|||||||
LogHelper.Debug<GitHubContributorController>("Config file was not found: " + configPath);
|
LogHelper.Debug<GitHubContributorController>("Config file was not found: " + configPath);
|
||||||
return PartialView("~/Views/Partials/Home/GitHubContributors.cshtml", model);
|
return PartialView("~/Views/Partials/Home/GitHubContributors.cshtml", model);
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] login = System.IO.File.ReadAllLines(configPath).Where(x => x.Trim() != "").Distinct().ToArray();
|
string[] login = System.IO.File.ReadAllLines(configPath).Where(x => x.Trim() != "").Distinct().ToArray();
|
||||||
var contributors = ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem<List<GitHubContributorModel>>("UmbracoGitHubContributors",
|
var contributors = ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem<List<GitHubGlobalContributorModel>>("UmbracoGitHubContributors",
|
||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
var githubController = new GitHubController();
|
var githubController = new GitHubController();
|
||||||
@@ -64,16 +63,25 @@ namespace OurUmbraco.Community.Controllers
|
|||||||
LogHelper.Warn<IGitHubContributorsModel>(string.Format("Invalid HTTP response for repository {0}", repo));
|
LogHelper.Warn<IGitHubContributorsModel>(string.Format("Invalid HTTP response for repository {0}", repo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return gitHubContributors;
|
|
||||||
|
var filteredContributors = gitHubContributors
|
||||||
|
.Where(g => !login.Contains(g.Author.Login))
|
||||||
|
.GroupBy(g => g.Author.Id)
|
||||||
|
.OrderByDescending(c => c.Sum(g => g.Total));
|
||||||
|
|
||||||
|
List<GitHubGlobalContributorModel> temp = new List<GitHubGlobalContributorModel>();
|
||||||
|
|
||||||
|
foreach (var group in filteredContributors)
|
||||||
|
{
|
||||||
|
temp.Add(new GitHubGlobalContributorModel(group));
|
||||||
|
}
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
|
||||||
}, TimeSpan.FromDays(1));
|
}, TimeSpan.FromDays(1));
|
||||||
|
|
||||||
var filteredContributors = contributors
|
|
||||||
.Where(g => !login.Contains(g.Author.Login))
|
|
||||||
.GroupBy(g => g.Author.Id)
|
|
||||||
.OrderByDescending(c => c.Sum(g => g.Total));
|
|
||||||
|
|
||||||
model.Contributors = filteredContributors;
|
model.Contributors = contributors;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using OurUmbraco.Community.Models;
|
||||||
|
|
||||||
|
namespace OurUmbraco.Community.Controllers
|
||||||
|
{
|
||||||
|
public class GitHubGlobalContributorModel
|
||||||
|
{
|
||||||
|
public List<GitHubContributorModel> Items { get; set; }
|
||||||
|
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
get { return Author.Id; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public int TotalCommits
|
||||||
|
{
|
||||||
|
get { return Items.Sum(x => x.Total); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public int TotalAdditions
|
||||||
|
{
|
||||||
|
get { return Items.Sum(x => x.TotalAdditions); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public int TotalDeletions
|
||||||
|
{
|
||||||
|
get { return Items.Sum(x => x.TotalDeletions); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Author Author
|
||||||
|
{
|
||||||
|
get { return Items.First().Author; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public GitHubGlobalContributorModel(IEnumerable<GitHubContributorModel> items)
|
||||||
|
{
|
||||||
|
Items = items.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using OurUmbraco.Community.Controllers;
|
||||||
|
|
||||||
namespace OurUmbraco.Community.Models
|
namespace OurUmbraco.Community.Models
|
||||||
{
|
{
|
||||||
public class GitHubContributorsModel : IGitHubContributorsModel
|
public class GitHubContributorsModel : IGitHubContributorsModel
|
||||||
{
|
{
|
||||||
public IEnumerable<IGrouping<int, GitHubContributorModel>> Contributors { get; set; }
|
public List<GitHubGlobalContributorModel> Contributors { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,25 +6,62 @@ namespace OurUmbraco.Community.Models
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class GitHubContributorModel : IGitHubContributorModel
|
public class GitHubContributorModel : IGitHubContributorModel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private List<Week> _weeks;
|
||||||
|
|
||||||
public int Total { get; set; }
|
public int Total { get; set; }
|
||||||
public List<Week> Weeks { get; set; }
|
public int TotalAdditions { get; set; }
|
||||||
|
public int TotalDeletions { get; set; }
|
||||||
|
|
||||||
|
[DataMember(Name = "weeks")]
|
||||||
|
public List<Week> Weeks
|
||||||
|
{
|
||||||
|
get { return _weeks; }
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_weeks = value;
|
||||||
|
|
||||||
|
|
||||||
|
int totalAdditions = 0;
|
||||||
|
int totalDeletions = 0;
|
||||||
|
foreach (var week in _weeks)
|
||||||
|
{
|
||||||
|
totalDeletions += week.D;
|
||||||
|
totalAdditions += week.A;
|
||||||
|
}
|
||||||
|
|
||||||
|
TotalAdditions = totalAdditions;
|
||||||
|
TotalDeletions = totalDeletions;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
public Author Author { get; set; }
|
public Author Author { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class Week
|
public class Week
|
||||||
{
|
{
|
||||||
[DataMember(Name = "w")]
|
/// <summary>
|
||||||
public int Timestamp { get; set; }
|
/// Timestamp
|
||||||
|
/// </summary>
|
||||||
|
public int W { get; set; }
|
||||||
|
|
||||||
[DataMember(Name = "a")]
|
/// <summary>
|
||||||
public int Additions { get; set; }
|
/// Additions
|
||||||
|
/// </summary>
|
||||||
|
public int A { get; set; }
|
||||||
|
|
||||||
[DataMember(Name = "d")]
|
/// <summary>
|
||||||
public int Deletions { get; set; }
|
/// Deletions
|
||||||
|
/// </summary>
|
||||||
|
public int D { get; set; }
|
||||||
|
|
||||||
[DataMember(Name = "c")]
|
/// <summary>
|
||||||
public int Commits { get; set; }
|
/// Commits
|
||||||
|
/// </summary>
|
||||||
|
public int C { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
|
|||||||
Reference in New Issue
Block a user