Initial addition of GitHub contributors code

This commit is contained in:
Emma Garland
2017-06-04 16:19:21 +01:00
parent 2fcd7f3911
commit 9799071d04
11 changed files with 213 additions and 0 deletions
+1
View File
@@ -4330,6 +4330,7 @@
<Content Include="Views\Partials\Grid\Bootstrap3-Fluid.cshtml" />
<Content Include="Views\Partials\Grid\Bootstrap2.cshtml" />
<Content Include="Views\Partials\Grid\Bootstrap2-Fluid.cshtml" />
<Content Include="Views\Partials\Home\GitHubContributors.cshtml" />
<None Include="web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</None>
@@ -59,6 +59,7 @@
@if (Members.IsLoggedIn())
{
@ForumActivity()
@GitHubContributors()
@TwitterSearch()
@Html.Partial("home/documentation")
}
@@ -66,6 +67,7 @@ else
{
@Html.Partial("home/documentation")
@ForumActivity()
@GitHubContributors()
@TwitterSearch()
}
@@ -122,6 +124,35 @@ else
<a class="button green" href="https://twitter.com/search?f=tweets&vertical=default&q=umbraco&src=typd">Join the conversation on Twitter &rarr;</a>
</div>
</div>
</div>
</section>
}
@helper GitHubContributors()
{
<section class="github-contributors">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="text-center">GitHub Contributors Activity</h1>
<p>
Recent activity on GitHub, where people are talking about Umbraco.
</p>
</div>
<div class="col-md-12">
<small>Recent tweets</small>
</div>
<div class="col-md-12 flex" id="github-contributors">
<h2>Loading GitHub search results...</h2>
</div>
<div class="col-md-12 goto-forum">
<a class="button green" href="https://twitter.com/search?f=tweets&vertical=default&q=umbraco&src=typd">Join the conversation on Twitter &rarr;</a>
</div>
</div>
</div>
</section>
@@ -13,5 +13,12 @@
catch (errForum) {
console.log("Couldn't load latest forum activity", errForum.message);
}
try {
$("#github-contributors").load("@Url.Action("GitHubGetContributorsResult", "GitHubContributor")");
}
catch (errForum) {
console.log("Couldn't load latest GitHub contributor activity", errForum.message);
}
});
</script>
@@ -0,0 +1,15 @@
@model OurUmbraco.Community.Models.GitHubContributorsModel
@foreach (var contributor in Model.Contributors)
{
<a href="@contributor.Url">
<div class="avatar">
<img alt="@contributor.Id" src="@contributor.AvatarUrl" />
</div>
</a>
}
@if (Model.Contributors.Any() == false)
{
<h2>Could not load recent GitHub contributors.</h2>
}
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Web.Http;
using System.Web.Mvc;
using OurUmbraco.Community.Models;
using OurUmbraco.Our.Api;
using RestSharp;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Web.Mvc;
namespace OurUmbraco.Community.Controllers
{
public class GitHubContributorController : SurfaceController
{
public ActionResult GitHubGetContributorsResult()
{
var model = new GitHubContributorsModel();
try
{
var contributors = ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem<List<GitHubContributorModel>>("UmbracoGitHubContributors",
() =>
{
//TODO: GitHub keys if required
var githubController = new GitHubController();
var response = githubController.GetAllContributors();
if (response.StatusCode == HttpStatusCode.OK && response.ResponseStatus == ResponseStatus.Completed)
{
return response.Data;
}
throw new HttpResponseException(HttpStatusCode.BadRequest);
}, TimeSpan.FromMinutes(2));
var filteredContributors = contributors;
//TODO: filter contributors
model.Contributors = filteredContributors;
}
catch (Exception ex)
{
LogHelper.Error<IGitHubContributorsModel>("Could not get GitHub Contributors", ex);
}
return PartialView("~/Views/Partials/Home/GitHubContributors.cshtml", model);
}
}
}
@@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace OurUmbraco.Community.Models
{
public class GitHubContributorsModel : IGitHubContributorsModel
{
public IEnumerable<GitHubContributorModel> Contributors { get; set; }
}
}
@@ -0,0 +1,57 @@
using System.Runtime.Serialization;
namespace OurUmbraco.Community.Models
{
[DataContract]
public class GitHubContributorModel : IGitHubContributorModel
{
public string Login { get; set; }
public int Id { get; set; }
[DataMember(Name = "avatar_url")]
public string AvatarUrl { get; set; }
[DataMember(Name = "gravatar_id")]
public string GravatarId { get; set; }
public string Url { get; set; }
[DataMember(Name = "html_url")]
public string HtmlUrl { get; set; }
[DataMember(Name = "followers_url")]
public string FollowersUrl { get; set; }
[DataMember(Name = "following_url")]
public string FollowingsUrl { get; set; }
[DataMember(Name = "gists_url")]
public string GistsUrl { get; set; }
[DataMember(Name = "starred_url")]
public string StarredUrl { get; set; }
[DataMember(Name = "subscriptions_url")]
public string SubscriptionsUrl { get; set; }
[DataMember(Name = "organizations_url")]
public string OrganizationsUrl { get; set; }
[DataMember(Name = "repos_url")]
public string ReposUrl { get; set; }
[DataMember(Name = "events_url")]
public string EventsUrl { get; set; }
[DataMember(Name = "received_events_url")]
public string ReceivedEventsUrl { get; set; }
public string Type { get; set; }
[DataMember(Name = "site_admin")]
public bool SiteAdmin { get; set; }
public int Contributions { get; set; }
}
}
@@ -0,0 +1,6 @@
namespace OurUmbraco.Community.Models
{
public interface IGitHubContributorModel
{
}
}
@@ -0,0 +1,6 @@
namespace OurUmbraco.Community.Models
{
public interface IGitHubContributorsModel
{
}
}
+28
View File
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OurUmbraco.Community.Models;
using RestSharp;
namespace OurUmbraco.Our.Api
{
public class GitHubController
{
/// <summary>
/// Get all contributors from GitHub Umbraco repositories
/// </summary>
/// <returns></returns>
public IRestResponse<List<GitHubContributorModel>> GetAllContributors()
{
//https://api.github.com/repos/umbraco/OurUmbraco/contributors
var client = new RestClient("https://api.github.com");
var request = new RestRequest("/repos/umbraco/OurUmbraco/contributors", Method.GET);
client.UserAgent = "OurUmbraco";
var response = client.Execute<List<GitHubContributorModel>>(request);
return response;
}
}
}
+6
View File
@@ -391,7 +391,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CamelCaseFormatter.cs" />
<Compile Include="Community\Controllers\GitHubContributorController.cs" />
<Compile Include="Community\Controllers\TwitterSearchController.cs" />
<Compile Include="Community\Models\GitHubContributorModel.cs" />
<Compile Include="Community\Models\IGitHubContributorModel.cs" />
<Compile Include="Community\Models\GitHubContributorsModel.cs" />
<Compile Include="Community\Models\IGitHubContributorsModel.cs" />
<Compile Include="Community\Models\TweetsModel.cs" />
<Compile Include="CustomDateTimeConvertor.cs" />
<Compile Include="Documentation\Busineslogic\ConventionExtensions.cs" />
@@ -504,6 +509,7 @@
<Compile Include="NotificationsWeb\Services\NotificationService.cs" />
<Compile Include="NotificationsWeb\Singleton.cs" />
<Compile Include="Our\Api\CommunityController.cs" />
<Compile Include="Our\Api\GitHubController.cs" />
<Compile Include="Our\Api\SearchController.cs" />
<Compile Include="Our\Api\YouTrackApiController.cs" />
<Compile Include="Our\Businesslogic\ProjectContributor.cs" />