take github key through env var
This commit is contained in:
@@ -6,6 +6,7 @@ using DotNetMashup.Web.Global;
|
|||||||
using DotNetMashup.Web.Model;
|
using DotNetMashup.Web.Model;
|
||||||
using DotNetMashup.Web.Repositories;
|
using DotNetMashup.Web.Repositories;
|
||||||
using Microsoft.Framework.Caching.Memory;
|
using Microsoft.Framework.Caching.Memory;
|
||||||
|
using Microsoft.Framework.Configuration;
|
||||||
|
|
||||||
namespace DotNetMashup.Web.Factory
|
namespace DotNetMashup.Web.Factory
|
||||||
{
|
{
|
||||||
@@ -15,7 +16,7 @@ namespace DotNetMashup.Web.Factory
|
|||||||
private List<IRepository> Repos;
|
private List<IRepository> Repos;
|
||||||
private const string cacheKey = "data";
|
private const string cacheKey = "data";
|
||||||
|
|
||||||
public RepositoryFactory(IEnumerable<IBlogMetaData> data, ISiteSetting setting, IMemoryCache cache)
|
public RepositoryFactory(IEnumerable<IBlogMetaData> data, ISiteSetting setting, IMemoryCache cache, IConfiguration config)
|
||||||
{
|
{
|
||||||
if(data == null)
|
if(data == null)
|
||||||
{
|
{
|
||||||
@@ -31,7 +32,7 @@ namespace DotNetMashup.Web.Factory
|
|||||||
}
|
}
|
||||||
Repos = new List<IRepository>()
|
Repos = new List<IRepository>()
|
||||||
{
|
{
|
||||||
new GitHubRepository(),
|
new GitHubRepository(config),
|
||||||
new BlogPostRepository(data, setting)
|
new BlogPostRepository(data, setting)
|
||||||
};
|
};
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
|
|||||||
@@ -2,12 +2,15 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DotNetMashup.Web.Model;
|
using DotNetMashup.Web.Model;
|
||||||
|
using Microsoft.Framework.Configuration;
|
||||||
using Octokit;
|
using Octokit;
|
||||||
|
|
||||||
namespace DotNetMashup.Web.Repositories
|
namespace DotNetMashup.Web.Repositories
|
||||||
{
|
{
|
||||||
public class GitHubRepository : IRepository
|
public class GitHubRepository : IRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConfiguration config;
|
||||||
|
|
||||||
public string FactoryName
|
public string FactoryName
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -16,13 +19,18 @@ namespace DotNetMashup.Web.Repositories
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GitHubRepository(IConfiguration config)
|
||||||
|
{
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<IExternalData>> GetData()
|
public async Task<IEnumerable<IExternalData>> GetData()
|
||||||
{
|
{
|
||||||
CommonMark.CommonMarkSettings.Default.AdditionalFeatures = CommonMark.CommonMarkAdditionalFeatures.All;
|
CommonMark.CommonMarkSettings.Default.AdditionalFeatures = CommonMark.CommonMarkAdditionalFeatures.All;
|
||||||
|
|
||||||
var client = new GitHubClient(new ProductHeaderValue("dotnetmashup"))
|
var client = new GitHubClient(new ProductHeaderValue("dotnetmashup"))
|
||||||
{
|
{
|
||||||
Credentials = new Credentials("151e2514adab9e8e44ab99fe8c71899fffa34caa")
|
Credentials = new Credentials(config["github"])
|
||||||
};
|
};
|
||||||
var issues = await client.Issue.GetAllForRepository("aspnet", "Announcements");
|
var issues = await client.Issue.GetAllForRepository("aspnet", "Announcements");
|
||||||
return issues.Select(a => new GithubAnnouncement
|
return issues.Select(a => new GithubAnnouncement
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Microsoft.AspNet.Builder;
|
|||||||
using Microsoft.AspNet.Hosting;
|
using Microsoft.AspNet.Hosting;
|
||||||
using Microsoft.Dnx.Runtime;
|
using Microsoft.Dnx.Runtime;
|
||||||
using Microsoft.Framework.Caching.Memory;
|
using Microsoft.Framework.Caching.Memory;
|
||||||
|
using Microsoft.Framework.Configuration;
|
||||||
using Microsoft.Framework.DependencyInjection;
|
using Microsoft.Framework.DependencyInjection;
|
||||||
using Microsoft.Framework.Logging;
|
using Microsoft.Framework.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -16,9 +17,13 @@ namespace DotNetMashup.Web
|
|||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
private IEnumerable<IBlogMetaData> _feedData = null;
|
private IEnumerable<IBlogMetaData> _feedData = null;
|
||||||
|
private IConfiguration config = null;
|
||||||
|
|
||||||
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
|
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
|
||||||
{
|
{
|
||||||
|
config = new ConfigurationBuilder()
|
||||||
|
.AddEnvironmentVariables()
|
||||||
|
.Build();
|
||||||
_feedData = JsonConvert.DeserializeObject<IEnumerable<BlogMetaData>>(File.ReadAllText(Path.Combine(appEnv.ApplicationBasePath, "blogfeed.json")));
|
_feedData = JsonConvert.DeserializeObject<IEnumerable<BlogMetaData>>(File.ReadAllText(Path.Combine(appEnv.ApplicationBasePath, "blogfeed.json")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +32,7 @@ namespace DotNetMashup.Web
|
|||||||
// This method gets called by the runtime.
|
// This method gets called by the runtime.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
services.AddInstance(config);
|
||||||
services.AddSingleton<ISiteSetting>(prov =>
|
services.AddSingleton<ISiteSetting>(prov =>
|
||||||
{
|
{
|
||||||
return new SiteSettings();
|
return new SiteSettings();
|
||||||
|
|||||||
Reference in New Issue
Block a user