Skip to content

Commit

Permalink
Merge pull request #7 from vicheanath/git-repo
Browse files Browse the repository at this point in the history
Add Git Service
  • Loading branch information
vicheanath authored Sep 13, 2024
2 parents 7521a8d + f8491e8 commit 355919a
Show file tree
Hide file tree
Showing 26 changed files with 315 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,4 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml

/SearchBugs.Api/repo/
src/SearchBugs.Api/repo/
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SearchBugs.Domain;
using SearchBugs.Domain.Git;
using SearchBugs.Domain.Projects;
using SearchBugs.Domain.Repositories;
using Shared.Messaging;
Expand All @@ -8,12 +9,12 @@ namespace SearchBugs.Application.Git.CreateGitRepo;

public sealed class CreateGitRepoCommandHandler : ICommandHandler<CreateGitRepoCommand>
{
private readonly IGitService _gitRepoService;
private readonly IGitHttpService _gitRepoService;
private readonly IGitRepository _gitRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly IProjectRepository _projectRepository;

public CreateGitRepoCommandHandler(IGitService gitService, IGitRepository gitRepository, IUnitOfWork unitOfWork, IProjectRepository projectRepository)
public CreateGitRepoCommandHandler(IGitHttpService gitService, IGitRepository gitRepository, IUnitOfWork unitOfWork, IProjectRepository projectRepository)
{
_gitRepoService = gitService;
_gitRepository = gitRepository;
Expand All @@ -28,7 +29,7 @@ public async Task<Result> Handle(CreateGitRepoCommand request, CancellationToken

if (project.IsFailure)
return Result.Failure(project.Error);
//_gitRepoService.CreateRepository(repo.Name);
//var repo = await _gitRepoService.CreateRepository(repo.Name);
await _gitRepository.Add(repo);
await _unitOfWork.SaveChangesAsync(cancellationToken);
return Result.Success();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using SearchBugs.Domain;
using SearchBugs.Domain.Repositories;
using SearchBugs.Domain.Git;
using Shared.Messaging;
using Shared.Results;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SearchBugs.Infrastructure.Services;
using MediatR;
using SearchBugs.Domain.Git;
using Shared.Messaging;
using Shared.Results;

Expand All @@ -13,13 +14,8 @@ public GetGitReposDetailsQueryHandler(IGitRepositoryService gitRepositoryService
_gitRepositoryService = gitRepositoryService;
}

public Task<Result<Dictionary<string, GitRepoItem>>> Handle(GetGitReposDetailsQuery request, CancellationToken cancellationToken)
Task<Result<Dictionary<string, GitRepoItem>>> IRequestHandler<GetGitReposDetailsQuery, Result<Dictionary<string, GitRepoItem>>>.Handle(GetGitReposDetailsQuery request, CancellationToken cancellationToken)
{
var result = _gitRepositoryService.GetFolderTree(request.RepoName, request.FolderName);
var mappedResult = result.ToDictionary(
x => x.Key,
x => new GitRepoItem(x.Value.Id, x.Value.Url, x.Value.Date, x.Value.ShortMessageHtmlLink)
);
return Task.FromResult(Result.Success(mappedResult));
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using SearchBugs.Domain.Repositories;
using SearchBugs.Domain.Git;
using Shared.Messaging;
using Shared.Results;

namespace SearchBugs.Application.Git.GitHttpServer;

internal sealed class GitHttpServerCommandHandler : ICommandHandler<GitHttpServerCommand>
{
private readonly IGitService _gitService;
private readonly IGitHttpService _gitService;

public GitHttpServerCommandHandler(IGitService gitService) => _gitService = gitService;
public GitHttpServerCommandHandler(IGitHttpService gitService) => _gitService = gitService;

public async Task<Result> Handle(GitHttpServerCommand request, CancellationToken cancellationToken)
{
Expand Down
9 changes: 9 additions & 0 deletions src/SearchBugs.Domain/Git/Contributor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SearchBugs.Infrastructure.Services;

public record Contributor
{
public string Name { get; init; }
public string Email { get; init; }
public int CommitCount { get; init; }
}

12 changes: 12 additions & 0 deletions src/SearchBugs.Domain/Git/FileBlame.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SearchBugs.Infrastructure.Services;

public record FileBlame
{
public int LineNumber { get; init; }
public string CommitSha { get; init; }
public string Author { get; init; }
public string Email { get; init; }
public DateTime Date { get; init; }
public int LineContent { get; init; }
}

17 changes: 17 additions & 0 deletions src/SearchBugs.Domain/Git/FileChange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace SearchBugs.Domain.Git;

public class FileChange
{
public string FileName { get; set; }
public string Status { get; set; }
public int Additions { get; set; }
public int Deletions { get; set; }

public FileChange(string fileName, string status, int additions, int deletions)
{
FileName = fileName;
Status = status;
Additions = additions;
Deletions = deletions;
}
}
10 changes: 10 additions & 0 deletions src/SearchBugs.Domain/Git/FileDiff.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SearchBugs.Infrastructure.Services;

public record FileDiff
{
public string FilePath { get; init; }
public string OldPath { get; init; }
public string Status { get; init; }
public string Patch { get; init; }
}

14 changes: 14 additions & 0 deletions src/SearchBugs.Domain/Git/GitErrors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Shared.Errors;

namespace SearchBugs.Domain.Git;

public static class GitErrors
{
public static Error InvalidCommitPath = new Error("Git.InvalidCommitPath", "Invalid path or commit.");

public static Error FileNotFound = new Error("Git.FileNotFound", "File not found.");

public static Error BranchNotFound = new Error("Git.BranchNotFound", "Branch not found.");

public static Error CommitNotFound = new Error("Git.CommitNotFound", "Commit not found.");
}
8 changes: 8 additions & 0 deletions src/SearchBugs.Domain/Git/GitTreeItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SearchBugs.Infrastructure.Services;

public record GitTreeItem
{
public string Path { get; init; }
public string Name { get; init; }
public string Type { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SearchBugs.Domain.Repositories;
namespace SearchBugs.Domain.Git;

public interface IGitService
public interface IGitHttpService
{
Task Handle(string repositoryName, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Shared.Results;
using SearchBugs.Domain.Repositories;
using Shared.Results;

namespace SearchBugs.Domain.Repositories;
namespace SearchBugs.Domain.Git;

public interface IGitRepository : IRepository<Repository, RepositoryId>
{
Expand Down
5 changes: 5 additions & 0 deletions src/SearchBugs.Domain/Git/IGitRepositoryService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace SearchBugs.Domain.Git;

public interface IGitRepositoryService
{
}
11 changes: 11 additions & 0 deletions src/SearchBugs.Domain/Git/MergeResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace SearchBugs.Infrastructure.Services;


public record MergeResult
{
public string Status { get; init; }

Check warning on line 6 in src/SearchBugs.Domain/Git/MergeResult.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Status' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string CommitSha { get; init; }

Check warning on line 7 in src/SearchBugs.Domain/Git/MergeResult.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'CommitSha' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}



30 changes: 0 additions & 30 deletions src/SearchBugs.Domain/Repositories/GitTreeItem.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/SearchBugs.Domain/Repositories/IGitRepositoryService.cs

This file was deleted.

Empty file.
4 changes: 2 additions & 2 deletions src/SearchBugs.Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using SearchBugs.Domain.Repositories;
using SearchBugs.Domain.Git;
using SearchBugs.Domain.Services;
using SearchBugs.Domain.Users;
using SearchBugs.Infrastructure.Authentication;
Expand Down Expand Up @@ -33,7 +33,7 @@ public static void AddInfrastructure(this IServiceCollection services)
services.ConfigureOptions<GitOptionsSetup>();
services.AddScoped<IPasswordHashingService, PasswordHashingService>();
services.AddScoped<IDataEncryptionService, DataEncryptionService>();
services.AddScoped<IGitService, GitService>();
services.AddScoped<IGitHttpService, GitHttpService>();
services.AddScoped<IGitRepositoryService, GitRepositoryService>();

services.AddCors(options =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using SearchBugs.Domain.Repositories;
using SearchBugs.Domain.Git;
using SearchBugs.Infrastructure.Options;
using System.Buffers;
using System.Diagnostics;
using System.IO.Pipelines;
using System.Text;
namespace SearchBugs.Infrastructure.Services;

internal class GitService : IGitService
internal class GitHttpService : IGitHttpService
{
private readonly GitOptions _gitOptions;
private readonly IHttpContextAccessor _httpContextAccessor;
private HttpContext _httpContext => _httpContextAccessor.HttpContext!;

public GitService(IOptions<GitOptions> gitOptions, IHttpContextAccessor httpContextAccessor)
public GitHttpService(IOptions<GitOptions> gitOptions, IHttpContextAccessor httpContextAccessor)
{
_gitOptions = gitOptions.Value;
_httpContextAccessor = httpContextAccessor;
Expand Down Expand Up @@ -102,6 +102,7 @@ private static (SequencePosition Position, bool IsFinished) ReadHeaders(

return (reader.Position, false);
}

}


Expand Down
Loading

0 comments on commit 355919a

Please sign in to comment.