Get the latest commit and show it on the home page
This commit is contained in:
parent
ffb3e791ab
commit
5d67e92245
23 changed files with 233 additions and 60 deletions
|
@ -3,8 +3,8 @@ using System.Linq;
|
|||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Website.Data.States;
|
||||
using Website.Models;
|
||||
using Website.Data.States.Git;
|
||||
using Website.Models.Git;
|
||||
|
||||
namespace Website.Data {
|
||||
public class GitServerApi {
|
||||
|
@ -18,10 +18,22 @@ namespace Website.Data {
|
|||
_token = token;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<GitRepository>> GetRepositories() {
|
||||
public async Task<IEnumerable<Repository>> 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));
|
||||
var states = JsonConvert.DeserializeObject<IEnumerable<RepositoryState>>(response);
|
||||
return states.Select(state => new Repository(state));
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Branch>> GetBranches(string repository) {
|
||||
var response = await _client.GetStringAsync($"https://{_domain}/api/v1/repos/rob/{repository}/branches?token={_token}");
|
||||
var states = JsonConvert.DeserializeObject<IEnumerable<BranchState>>(response);
|
||||
return states.Select(state => new Branch(state));
|
||||
}
|
||||
|
||||
public async Task<Commit> GetCommit(string repository, string hash) {
|
||||
var response = await _client.GetStringAsync($"https://{_domain}/api/v1/repos/rob/{repository}/commits/{hash}?token={_token}");
|
||||
var state = JsonConvert.DeserializeObject<CommitDetailsState>(response);
|
||||
return new Commit(state);
|
||||
}
|
||||
}
|
||||
}
|
10
Website/Data/States/Git/AuthorState.cs
Normal file
10
Website/Data/States/Git/AuthorState.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
|
||||
namespace Website.Data.States.Git {
|
||||
public class AuthorState {
|
||||
public string name { get; set; }
|
||||
public string email { get; set; }
|
||||
public string username { get; set; }
|
||||
public DateTimeOffset date { get; set; }
|
||||
}
|
||||
}
|
7
Website/Data/States/Git/BranchState.cs
Normal file
7
Website/Data/States/Git/BranchState.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Website.Data.States.Git {
|
||||
public class BranchState
|
||||
{
|
||||
public string name { get; set; }
|
||||
public CommitState commit { get; set; }
|
||||
}
|
||||
}
|
11
Website/Data/States/Git/CommitDetailsState.cs
Normal file
11
Website/Data/States/Git/CommitDetailsState.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace Website.Data.States.Git {
|
||||
public class CommitDetailsState {
|
||||
public string url { get; set; }
|
||||
public string sha { get; set; }
|
||||
public string html_url { get; set; }
|
||||
public CommitState commit { get; set; }
|
||||
public UserState author { get; set; }
|
||||
public UserState committer { get; set; }
|
||||
public CommitPointerState[] parents { get; set; }
|
||||
}
|
||||
}
|
6
Website/Data/States/Git/CommitPointerState.cs
Normal file
6
Website/Data/States/Git/CommitPointerState.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace Website.Data.States.Git {
|
||||
public partial class CommitPointerState {
|
||||
public string url { get; set; }
|
||||
public string sha { get; set; }
|
||||
}
|
||||
}
|
16
Website/Data/States/Git/CommitState.cs
Normal file
16
Website/Data/States/Git/CommitState.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
|
||||
namespace Website.Data.States.Git {
|
||||
public class CommitState {
|
||||
public string id { get; set; }
|
||||
public string message { get; set; }
|
||||
public string url { get; set; }
|
||||
public AuthorState author { get; set; }
|
||||
public AuthorState committer { get; set; }
|
||||
public object added { get; set; }
|
||||
public object removed { get; set; }
|
||||
public object modified { get; set; }
|
||||
public DateTimeOffset timestamp { get; set; }
|
||||
public CommitPointerState tree { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
namespace Website.Data.States {
|
||||
public class GitRepositoryOwnerState {
|
||||
namespace Website.Data.States.Git {
|
||||
public class RepositoryOwnerState {
|
||||
public int id { get; set; }
|
||||
public string username { get; set; }
|
||||
public string login { get; set; }
|
|
@ -1,5 +1,5 @@
|
|||
namespace Website.Data.States {
|
||||
public class GitRepositoryPermissionsState {
|
||||
namespace Website.Data.States.Git {
|
||||
public class RepositoryPermissionsState {
|
||||
public bool admin { get; set; }
|
||||
public bool push { get; set; }
|
||||
public bool pull { get; set; }
|
|
@ -1,9 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace Website.Data.States {
|
||||
public class GitRepositoryState {
|
||||
namespace Website.Data.States.Git {
|
||||
public class RepositoryState {
|
||||
public int id { get; set; }
|
||||
public GitRepositoryOwnerState owner { get; set; }
|
||||
public RepositoryOwnerState owner { get; set; }
|
||||
public string name { get; set; }
|
||||
public string full_name { get; set; }
|
||||
public string description { get; set; }
|
||||
|
@ -24,7 +24,7 @@ namespace Website.Data.States {
|
|||
public string default_branch { get; set; }
|
||||
public DateTime created_at { get; set; }
|
||||
public DateTime updated_at { get; set; }
|
||||
public GitRepositoryPermissionsState permissions { get; set; }
|
||||
public RepositoryPermissionsState permissions { get; set; }
|
||||
}
|
||||
}
|
||||
|
10
Website/Data/States/Git/UserState.cs
Normal file
10
Website/Data/States/Git/UserState.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace Website.Data.States.Git {
|
||||
public partial class UserState {
|
||||
public long 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; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue