Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit #186

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
253 changes: 241 additions & 12 deletions MAUIsland.GitHubProvider/Implementations/OctokitGitHubClient.cs
Original file line number Diff line number Diff line change
@@ -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<GitHubAuthorModel> GetAuthor(string owner)
public async Task<GitHubAuthorModel> 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<GitHubIssueModel> GetGitHubIssueById(string owner, string repository, string issueNumber)
public async Task<GitHubIssueModel> 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<IEnumerable<GitHubIssueModel>> GetGitHubIssues(string owner, string repository)
public async Task<IEnumerable<GitHubIssueModel>> 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<IEnumerable<GitHubIssueModel>> GetGitHubIssuesByLabels(string owner, string repository, IEnumerable<string> labels)
public async Task<IEnumerable<GitHubIssueModel>> GetGitHubIssuesByLabels(string owner, string repository, IEnumerable<string> 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<GitHubRepositoryModel> GetRepository(string owner, string repository)
public async Task<GitHubRepositoryModel> 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
}
1 change: 1 addition & 0 deletions MAUIsland.GitHubProvider/MAUIsland.GitHubProvider.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Octokit" Version="10.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion MAUIsland.GitHubProvider/Models/GitHubAuthorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial class GitHubAuthorModel : GitHubBaseModel
int following;

[ObservableProperty]
bool hireable;
bool? hireable;

[ObservableProperty]
string htmlUrl;
Expand Down
5 changes: 1 addition & 4 deletions MAUIsland.GitHubProvider/Models/GitHubIssueModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public partial class GitHubIssueModel : GitHubBaseModel
[ObservableProperty]
string repositoryUrl;

[ObservableProperty]
string labelsUrl;

[ObservableProperty]
string commentsUrl;

Expand Down Expand Up @@ -63,5 +60,5 @@ public partial class GitHubIssueModel : GitHubBaseModel
DateTimeOffset createdAt;

[ObservableProperty]
DateTimeOffset updatedAt;
DateTimeOffset? updatedAt;
}
2 changes: 2 additions & 0 deletions MAUIsland.GitHubProvider/ServiceExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Octokit;

namespace MAUIsland.GitHubProvider;

Expand All @@ -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<IGitHubService, OctokitGitHubClient>();
}
}
2 changes: 1 addition & 1 deletion MAUIsland.IntegrationTests/GitHubServiceIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IGitHubService>();
await gitHubService.GetGitHubIssueById(owner, repositoryName, issueId);
Expand Down