Use new projects API
This commit is contained in:
parent
11bca4cf53
commit
8bf483b334
24 changed files with 141 additions and 222 deletions
16
Website/Data/GitApi.cs
Normal file
16
Website/Data/GitApi.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Website.Models.Git;
|
||||
|
||||
namespace Website.Data {
|
||||
public class GitApi : ApiClient, IGitApi {
|
||||
|
||||
public GitApi(HttpClient client) : base(client) {
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Repository>> GetRepositories(string user) => await Get<IEnumerable<Repository>>("repositories", new { user });
|
||||
public async Task<IEnumerable<Branch>> GetBranches(string user, string repository) => await Get<IEnumerable<Branch>>("branches", new {user, repository});
|
||||
public async Task<Commit> GetCommit(string user, string repository, string hash) => await Get<Commit>("commit", new {user, repository, hash});
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Website.Data.States.Git;
|
||||
using Website.Models.Git;
|
||||
|
||||
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<Repository>> GetRepositories() {
|
||||
var response = await _client.GetStringAsync($"https://{_domain}/api/v1/users/rob/repos?token={_token}");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
11
Website/Data/IGitApi.cs
Normal file
11
Website/Data/IGitApi.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Website.Models.Git;
|
||||
|
||||
namespace Website.Data {
|
||||
public interface IGitApi {
|
||||
Task<IEnumerable<Repository>> GetRepositories(string user);
|
||||
Task<IEnumerable<Branch>> GetBranches(string user, string repository);
|
||||
Task<Commit> GetCommit(string user, string repository, string hash);
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
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; }
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
namespace Website.Data.States.Git {
|
||||
public class BranchState
|
||||
{
|
||||
public string name { get; set; }
|
||||
public CommitState commit { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
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; }
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
namespace Website.Data.States.Git {
|
||||
public partial class CommitPointerState {
|
||||
public string url { get; set; }
|
||||
public string sha { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
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,10 +0,0 @@
|
|||
namespace Website.Data.States.Git {
|
||||
public class RepositoryOwnerState {
|
||||
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; }
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
namespace Website.Data.States.Git {
|
||||
public class RepositoryPermissionsState {
|
||||
public bool admin { get; set; }
|
||||
public bool push { get; set; }
|
||||
public bool pull { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace Website.Data.States.Git {
|
||||
public class RepositoryState {
|
||||
public int id { get; set; }
|
||||
public RepositoryOwnerState 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 RepositoryPermissionsState permissions { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
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