Get git projects from Gogs
This commit is contained in:
parent
9fd9beb860
commit
292d7729f2
9 changed files with 122 additions and 10 deletions
27
Website/Data/GitServerApi.cs
Normal file
27
Website/Data/GitServerApi.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Website.Data.States;
|
||||
using Website.Models;
|
||||
|
||||
namespace Website.Data {
|
||||
public class GitServerApi {
|
||||
private readonly HttpClient _client;
|
||||
private readonly string _domain;
|
||||
private readonly string _token;
|
||||
|
||||
public GitServerApi(HttpClient client, string domain, string token) {
|
||||
_client = client;
|
||||
_domain = domain;
|
||||
_token = token;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<GitRepository>> GetRepositories() {
|
||||
var response = await _client.GetStringAsync($"https://{_domain}/api/v1/users/rob/repos?token={_token}");
|
||||
var states = JsonConvert.DeserializeObject<IEnumerable<GitRepositoryState>>(response);
|
||||
return states.Select(state => new GitRepository(state));
|
||||
}
|
||||
}
|
||||
}
|
10
Website/Data/States/GitRepositoryOwnerState.cs
Normal file
10
Website/Data/States/GitRepositoryOwnerState.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace Website.Data.States {
|
||||
public class GitRepositoryOwnerState {
|
||||
public int id { get; set; }
|
||||
public string username { get; set; }
|
||||
public string login { get; set; }
|
||||
public string full_name { get; set; }
|
||||
public string email { get; set; }
|
||||
public string avatar_url { get; set; }
|
||||
}
|
||||
}
|
7
Website/Data/States/GitRepositoryPermissionsState.cs
Normal file
7
Website/Data/States/GitRepositoryPermissionsState.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Website.Data.States {
|
||||
public class GitRepositoryPermissionsState {
|
||||
public bool admin { get; set; }
|
||||
public bool push { get; set; }
|
||||
public bool pull { get; set; }
|
||||
}
|
||||
}
|
31
Website/Data/States/GitRepositoryState.cs
Normal file
31
Website/Data/States/GitRepositoryState.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
|
||||
namespace Website.Data.States {
|
||||
public class GitRepositoryState {
|
||||
public int id { get; set; }
|
||||
public GitRepositoryOwnerState owner { get; set; }
|
||||
public string name { get; set; }
|
||||
public string full_name { get; set; }
|
||||
public string description { get; set; }
|
||||
public bool _private { get; set; }
|
||||
public bool fork { get; set; }
|
||||
public object parent { get; set; }
|
||||
public bool empty { get; set; }
|
||||
public bool mirror { get; set; }
|
||||
public int size { get; set; }
|
||||
public string html_url { get; set; }
|
||||
public string ssh_url { get; set; }
|
||||
public string clone_url { get; set; }
|
||||
public string website { get; set; }
|
||||
public int stars_count { get; set; }
|
||||
public int forks_count { get; set; }
|
||||
public int watchers_count { get; set; }
|
||||
public int open_issues_count { get; set; }
|
||||
public string default_branch { get; set; }
|
||||
public DateTime created_at { get; set; }
|
||||
public DateTime updated_at { get; set; }
|
||||
public GitRepositoryPermissionsState permissions { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
13
Website/Models/GitRepository.cs
Normal file
13
Website/Models/GitRepository.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using Website.Data.States;
|
||||
|
||||
namespace Website.Models {
|
||||
public class GitRepository {
|
||||
public GitRepository(GitRepositoryState state) {
|
||||
Name = state.name;
|
||||
Url = state.html_url;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
@ -39,7 +40,8 @@ namespace Website
|
|||
private void RegisterRepositories(IServiceCollection services) =>
|
||||
services.AddSingleton<IDatabaseProvider, MySQLDatabaseProvider>()
|
||||
.AddSingleton<BlogRepository, BlogRepository>()
|
||||
.AddSingleton<UserRepository, UserRepository>();
|
||||
.AddSingleton<UserRepository, UserRepository>()
|
||||
.AddSingleton(new GitServerApi(new HttpClient(), Configuration["gitDomain"], Configuration["gitToken"]));
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
|
|
19
Website/ViewComponents/ProjectNavigationViewComponent.cs
Normal file
19
Website/ViewComponents/ProjectNavigationViewComponent.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Website.Data;
|
||||
|
||||
namespace Website.ViewComponents {
|
||||
public class ProjectNavigationViewComponent :ViewComponent {
|
||||
private readonly GitServerApi _api;
|
||||
|
||||
public ProjectNavigationViewComponent(GitServerApi api) {
|
||||
_api = api;
|
||||
}
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync() {
|
||||
var repositories = await _api.GetRepositories();
|
||||
return View(repositories.Take(5));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
@model IEnumerable<Website.Models.GitRepository>
|
||||
|
||||
<h5>Projects:</h5>
|
||||
<ul class="nav-list">
|
||||
@foreach (var repository in Model) {
|
||||
<li class="nav-list__link"><a href="@repository.Url">@repository.Name</a></li>
|
||||
}
|
||||
<li><a href="//git.robware.uk">View All</a></li>
|
||||
</ul>
|
|
@ -23,13 +23,7 @@
|
|||
@RenderBody()
|
||||
</main>
|
||||
<nav>
|
||||
<h5>Projects:</h5>
|
||||
<ul>
|
||||
<li><a href="link 1">Link 1</a></li>
|
||||
<li><a href="link 2">Link 2</a></li>
|
||||
<li><a href="link 3">Link 3</a></li>
|
||||
<li><a href="//git.robware.uk">View All</a></li>
|
||||
</ul>
|
||||
@await Component.InvokeAsync("ProjectNavigation")
|
||||
@await Component.InvokeAsync("BlogNavigation")
|
||||
</nav>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue