diff --git a/MAUIsland.GitHubProvider/Implementations/OctokitGitHubClient.cs b/MAUIsland.GitHubProvider/Implementations/OctokitGitHubClient.cs index a052e2ef..e5311bef 100644 --- a/MAUIsland.GitHubProvider/Implementations/OctokitGitHubClient.cs +++ b/MAUIsland.GitHubProvider/Implementations/OctokitGitHubClient.cs @@ -1,46 +1,275 @@  +using Octokit; +using static System.Runtime.InteropServices.JavaScript.JSType; +using System.Net.Sockets; +using System.Reflection.Emit; +using System.Xml.Linq; +using System; + + namespace MAUIsland.GitHubProvider; public class OctokitGitHubClient : IGitHubService { #region [ Fields ] - private readonly string httpHeader = "Totechs Corps"; + private readonly GitHubClient gitClient; + private readonly string httpHeader = "totechs-corp"; #endregion #region [ CTor ] public OctokitGitHubClient() { - + this.gitClient = new GitHubClient(new ProductHeaderValue(httpHeader)); } #endregion #region [ Methods ] - public Task GetAuthor(string owner) + public async Task GetAuthor(string owner) { - throw new NotImplementedException(); + var author = await this.gitClient.User.Get(owner); + return new GitHubAuthorModel + { + AvatarUrl = author.AvatarUrl, + Bio = author.Bio, + Blog = author.Blog, + Company = author.Company, + CreatedAt = author.CreatedAt.Date, + Email = author.Email, + Followers = author.Followers, + Following = author.Following, + Hireable = author.Hireable, + HtmlUrl = author.HtmlUrl, + OwnerId = author.Id, + Location = author.Location, + Login = author.Login, + Name = author.Name, + Url = author.Url + }; } - public Task GetGitHubIssueById(string owner, string repository, string issueNumber) + public async Task GetGitHubIssueById(string owner, string repository, string issueNumber) { - throw new NotImplementedException(); + var issue = await this.gitClient.Issue.Get(owner, repository, int.Parse(issueNumber)); + return new GitHubIssueModel + { + Id = issue.Id, + Url = issue.Url, + RepositoryUrl = issue.Url, + CommentsUrl = issue.CommentsUrl, + EventsUrl = issue.EventsUrl, + HtmlUrl = issue.HtmlUrl, + Number = issue.Number, + State = issue.State.StringValue, + Title = issue.Title, + Body = issue.Body, + User = new GitHubAuthorModel + { + Id = issue.User.Id, + Login = issue.User.Login, + AvatarUrl = issue.User.AvatarUrl, + Url = issue.User.Url, + HtmlUrl = issue.User.HtmlUrl + }, + Labels = issue.Labels.Select(label => new GitHubLabelModel + { + Id = label.Id, + Name = label.Name, + Color = label.Color, + Description = label.Description, + IsDefault = label.Default + }).ToList(), + Assignee = new GitHubAuthorModel + { + Id = issue.Assignee.Id, + Login = issue.Assignee.Login, + AvatarUrl = issue.Assignee.AvatarUrl, + Url = issue.Assignee.Url, + HtmlUrl = issue.Assignee.HtmlUrl + }, + Assignees = issue.Assignees.Select(assignee => new GitHubAuthorModel + { + Id = assignee.Id, + Login = assignee.Login, + AvatarUrl = assignee.AvatarUrl, + Url = assignee.Url, + HtmlUrl = assignee.HtmlUrl + }).ToList(), + Milestone = new GitHubMilestoneModel + { + Id = issue.Milestone.Id, + Number = issue.Milestone.Number, + Title = issue.Milestone.Title, + Description = issue.Milestone.Description, + State = issue.Milestone.State.StringValue, + CreatedAt = issue.Milestone.CreatedAt, + UpdatedAt = issue.Milestone.UpdatedAt, + ClosedAt = issue.Milestone.ClosedAt + }, + Locked = issue.Locked, + Comments = issue.Comments, + ClosedAt = issue.ClosedAt, + CreatedAt = issue.CreatedAt, + UpdatedAt = issue.UpdatedAt, + }; } - public Task> GetGitHubIssues(string owner, string repository) + public async Task> GetGitHubIssues(string owner, string repository) { - throw new NotImplementedException(); + var issues = await this.gitClient.Issue.GetAllForRepository(owner, repository); + return issues.Select(issue => new GitHubIssueModel + { + Id = issue.Id, + Url = issue.Url, + RepositoryUrl = issue.Url, + CommentsUrl = issue.CommentsUrl, + EventsUrl = issue.EventsUrl, + HtmlUrl = issue.HtmlUrl, + Number = issue.Number, + State = issue.State.StringValue, + Title = issue.Title, + Body = issue.Body, + User = new GitHubAuthorModel + { + Id = issue.User.Id, + Login = issue.User.Login, + AvatarUrl = issue.User.AvatarUrl, + Url = issue.User.Url, + HtmlUrl = issue.User.HtmlUrl + }, + Labels = issue.Labels.Select(label => new GitHubLabelModel + { + Id = label.Id, + Name = label.Name, + Color = label.Color, + Description = label.Description, + IsDefault = label.Default + }).ToList(), + Assignee = new GitHubAuthorModel + { + Id = issue.Assignee.Id, + Login = issue.Assignee.Login, + AvatarUrl = issue.Assignee.AvatarUrl, + Url = issue.Assignee.Url, + HtmlUrl = issue.Assignee.HtmlUrl + }, + Assignees = issue.Assignees.Select(assignee => new GitHubAuthorModel + { + Id = assignee.Id, + Login = assignee.Login, + AvatarUrl = assignee.AvatarUrl, + Url = assignee.Url, + HtmlUrl = assignee.HtmlUrl + }).ToList(), + Milestone = new GitHubMilestoneModel + { + Id = issue.Milestone.Id, + Number = issue.Milestone.Number, + Title = issue.Milestone.Title, + Description = issue.Milestone.Description, + State = issue.Milestone.State.StringValue, + CreatedAt = issue.Milestone.CreatedAt, + UpdatedAt = issue.Milestone.UpdatedAt, + ClosedAt = issue.Milestone.ClosedAt + }, + Locked = issue.Locked, + Comments = issue.Comments, + ClosedAt = issue.ClosedAt, + CreatedAt = issue.CreatedAt, + UpdatedAt = issue.UpdatedAt, + }); } - public Task> GetGitHubIssuesByLabels(string owner, string repository, IEnumerable labels) + public async Task> GetGitHubIssuesByLabels(string owner, string repository, IEnumerable labels) { - throw new NotImplementedException(); + var request = new RepositoryIssueRequest + { + State = ItemStateFilter.All, + }; + foreach (var label in labels) + { + request.Labels.Add(label); + } + + var issues = await this.gitClient.Issue.GetAllForRepository(owner, repository, request); + return issues.Select(issue => new GitHubIssueModel + { + Id = issue.Id, + Url = issue.Url, + RepositoryUrl = issue.Url, + CommentsUrl = issue.CommentsUrl, + EventsUrl = issue.EventsUrl, + HtmlUrl = issue.HtmlUrl, + Number = issue.Number, + State = issue.State.StringValue, + Title = issue.Title, + Body = issue.Body, + User = new GitHubAuthorModel + { + Id = issue.User.Id, + Login = issue.User.Login, + AvatarUrl = issue.User.AvatarUrl, + Url = issue.User.Url, + HtmlUrl = issue.User.HtmlUrl + }, + Labels = issue.Labels.Select(label => new GitHubLabelModel + { + Id = label.Id, + Name = label.Name, + Color = label.Color, + Description = label.Description, + IsDefault = label.Default + }).ToList(), + Assignee = new GitHubAuthorModel + { + Id = issue.Assignee.Id, + Login = issue.Assignee.Login, + AvatarUrl = issue.Assignee.AvatarUrl, + Url = issue.Assignee.Url, + HtmlUrl = issue.Assignee.HtmlUrl + }, + Assignees = issue.Assignees.Select(assignee => new GitHubAuthorModel + { + Id = assignee.Id, + Login = assignee.Login, + AvatarUrl = assignee.AvatarUrl, + Url = assignee.Url, + HtmlUrl = assignee.HtmlUrl + }).ToList(), + Milestone = new GitHubMilestoneModel + { + Id = issue.Milestone.Id, + Number = issue.Milestone.Number, + Title = issue.Milestone.Title, + Description = issue.Milestone.Description, + State = issue.Milestone.State.StringValue, + CreatedAt = issue.Milestone.CreatedAt, + UpdatedAt = issue.Milestone.UpdatedAt, + ClosedAt = issue.Milestone.ClosedAt + }, + Locked = issue.Locked, + Comments = issue.Comments, + ClosedAt = issue.ClosedAt, + CreatedAt = issue.CreatedAt, + UpdatedAt = issue.UpdatedAt, + }); } - public Task GetRepository(string owner, string repository) + public async Task GetRepository(string owner, string repository) { - throw new NotImplementedException(); + var repo = await this.gitClient.Repository.Get(owner, repository); + return new GitHubRepositoryModel + { + GitHubId = repo.Id, + Name = repo.Name, + Url = repo.Url, + CloneUrl = repo.CloneUrl, + GitUrl = repo.GitUrl, + SvnUrl = repo.SvnUrl, + Description = repo.Description, + }; } #endregion } diff --git a/MAUIsland.GitHubProvider/MAUIsland.GitHubProvider.csproj b/MAUIsland.GitHubProvider/MAUIsland.GitHubProvider.csproj index 619a131e..9bd081bb 100644 --- a/MAUIsland.GitHubProvider/MAUIsland.GitHubProvider.csproj +++ b/MAUIsland.GitHubProvider/MAUIsland.GitHubProvider.csproj @@ -7,6 +7,7 @@ + diff --git a/MAUIsland.GitHubProvider/Models/GitHubAuthorModel.cs b/MAUIsland.GitHubProvider/Models/GitHubAuthorModel.cs index b8a85561..985ebc17 100644 --- a/MAUIsland.GitHubProvider/Models/GitHubAuthorModel.cs +++ b/MAUIsland.GitHubProvider/Models/GitHubAuthorModel.cs @@ -27,7 +27,7 @@ public partial class GitHubAuthorModel : GitHubBaseModel int following; [ObservableProperty] - bool hireable; + bool? hireable; [ObservableProperty] string htmlUrl; diff --git a/MAUIsland.GitHubProvider/Models/GitHubIssueModel.cs b/MAUIsland.GitHubProvider/Models/GitHubIssueModel.cs index dabea5c5..13f13a2f 100644 --- a/MAUIsland.GitHubProvider/Models/GitHubIssueModel.cs +++ b/MAUIsland.GitHubProvider/Models/GitHubIssueModel.cs @@ -11,9 +11,6 @@ public partial class GitHubIssueModel : GitHubBaseModel [ObservableProperty] string repositoryUrl; - [ObservableProperty] - string labelsUrl; - [ObservableProperty] string commentsUrl; @@ -63,5 +60,5 @@ public partial class GitHubIssueModel : GitHubBaseModel DateTimeOffset createdAt; [ObservableProperty] - DateTimeOffset updatedAt; + DateTimeOffset? updatedAt; } diff --git a/MAUIsland.GitHubProvider/ServiceExtension.cs b/MAUIsland.GitHubProvider/ServiceExtension.cs index 072d8497..d71e1d51 100644 --- a/MAUIsland.GitHubProvider/ServiceExtension.cs +++ b/MAUIsland.GitHubProvider/ServiceExtension.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.DependencyInjection; +using Octokit; namespace MAUIsland.GitHubProvider; @@ -7,6 +8,7 @@ public static class ServiceExtension public static void RegisterLogicProvider(this IServiceCollection services) { + services.AddTransient(x => new GitHubClient(new ProductHeaderValue("Totechs Corps"))); services.AddTransient(); } } diff --git a/MAUIsland.IntegrationTests/GitHubServiceIntegrationTest.cs b/MAUIsland.IntegrationTests/GitHubServiceIntegrationTest.cs index 92ffd8c4..6adb3dbe 100644 --- a/MAUIsland.IntegrationTests/GitHubServiceIntegrationTest.cs +++ b/MAUIsland.IntegrationTests/GitHubServiceIntegrationTest.cs @@ -62,7 +62,7 @@ public async Task GetGitHubIssuesByLabelsTest() [Fact] public async Task GetGitHubIssueByIdTest() { - string issueId = "Provide a valid issue id"; + string issueId = "1"; var gitHubService = serviceProvider!.GetRequiredService(); await gitHubService.GetGitHubIssueById(owner, repositoryName, issueId);