-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from vicheanath/git-repo
Add Test
- Loading branch information
Showing
28 changed files
with
357 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/SearchBugs.Application/Git/CommitChanges/CommitChangeCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Shared.Messaging; | ||
|
||
namespace SearchBugs.Application.Git.CommitChanges; | ||
|
||
public record CommitChangeCommand(string Url, string AuthorName, string AuthorEmail, string CommitMessage, string FileContent) : ICommand; |
18 changes: 18 additions & 0 deletions
18
src/SearchBugs.Application/Git/CommitChanges/CommitChangeCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using SearchBugs.Domain.Git; | ||
using Shared.Messaging; | ||
using Shared.Results; | ||
|
||
namespace SearchBugs.Application.Git.CommitChanges; | ||
|
||
internal sealed class CommitChangeCommandHandler : ICommandHandler<CommitChangeCommand> | ||
{ | ||
private readonly IGitRepositoryService _gitRepositoryService; | ||
public CommitChangeCommandHandler(IGitRepositoryService gitRepositoryService) | ||
{ | ||
_gitRepositoryService = gitRepositoryService; | ||
} | ||
public Task<Result> Handle(CommitChangeCommand request, CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult(_gitRepositoryService.CommitChanges(request.Url, request.AuthorName, request.AuthorEmail, request.CommitMessage)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/SearchBugs.Application/Git/CommitChanges/CommitChangeCommandValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using FluentValidation; | ||
|
||
namespace SearchBugs.Application.Git.CommitChanges; | ||
|
||
internal sealed class CommitChangeCommandValidator : AbstractValidator<CommitChangeCommand> | ||
{ | ||
public CommitChangeCommandValidator() | ||
{ | ||
RuleFor(x => x.Url).NotEmpty(); | ||
RuleFor(x => x.AuthorName).NotEmpty(); | ||
RuleFor(x => x.AuthorEmail).NotEmpty(); | ||
RuleFor(x => x.CommitMessage).NotEmpty(); | ||
RuleFor(x => x.FileContent).NotEmpty(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/SearchBugs.Application/Git/GetCommitDiff/CommitDiffResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Shared.Messaging; | ||
|
||
namespace SearchBugs.Application.Git.GetCommitDiff; | ||
|
||
public record CommitDiffResult(string FilePath, string OldPath, string Status, string Patch) : IQuery<IEnumerable<CommitDiffResult>>; |
7 changes: 7 additions & 0 deletions
7
src/SearchBugs.Application/Git/GetCommitDiff/GetCommitDiffQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
| ||
|
||
using Shared.Messaging; | ||
|
||
namespace SearchBugs.Application.Git.GetCommitDiff; | ||
|
||
public record GetCommitDiffQuery(string Url, string CommitSha) : IQuery<IEnumerable<CommitDiffResult>>; |
34 changes: 34 additions & 0 deletions
34
src/SearchBugs.Application/Git/GetCommitDiff/GetCommitDiffQueryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using SearchBugs.Domain.Git; | ||
using Shared.Messaging; | ||
using Shared.Results; | ||
|
||
namespace SearchBugs.Application.Git.GetCommitDiff; | ||
|
||
internal sealed class GetCommitDiffQueryHandler : IQueryHandler<GetCommitDiffQuery, IEnumerable<CommitDiffResult>> | ||
{ | ||
private readonly IGitRepositoryService _gitRepositoryService; | ||
|
||
public GetCommitDiffQueryHandler(IGitRepositoryService gitRepositoryService) | ||
{ | ||
_gitRepositoryService = gitRepositoryService; | ||
} | ||
|
||
public Task<Result<IEnumerable<CommitDiffResult>>> Handle(GetCommitDiffQuery request, CancellationToken cancellationToken) | ||
{ | ||
var commitDiffResult = _gitRepositoryService.GetCommitDiff(request.Url, request.CommitSha); | ||
if (commitDiffResult.IsFailure) | ||
{ | ||
return Task.FromResult(Result.Failure<IEnumerable<CommitDiffResult>>(commitDiffResult.Error)); | ||
} | ||
|
||
var commitDiffs = commitDiffResult.Value.Select(fileDiff => new CommitDiffResult | ||
( | ||
FilePath: fileDiff.FilePath, | ||
OldPath: fileDiff.OldPath, | ||
Status: fileDiff.Status, | ||
Patch: fileDiff.Patch | ||
)); | ||
|
||
return Task.FromResult(Result.Success(commitDiffs)); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/SearchBugs.Application/Git/GetFileContents/GetFileContentQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Shared.Messaging; | ||
|
||
namespace SearchBugs.Application.Git.GetFileContents; | ||
|
||
public record GetFileContentQuery(string Url, string CommitSha, string FilePath) : IQuery<string>; |
20 changes: 20 additions & 0 deletions
20
src/SearchBugs.Application/Git/GetFileContents/GetFileContentQueryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using SearchBugs.Domain.Git; | ||
using Shared.Messaging; | ||
using Shared.Results; | ||
|
||
namespace SearchBugs.Application.Git.GetFileContents; | ||
|
||
internal sealed class GetFileContentQueryHandler : IQueryHandler<GetFileContentQuery, string> | ||
{ | ||
private readonly IGitRepositoryService _gitRepositoryService; | ||
|
||
public GetFileContentQueryHandler(IGitRepositoryService gitRepositoryService) | ||
{ | ||
_gitRepositoryService = gitRepositoryService; | ||
} | ||
|
||
public Task<Result<string>> Handle(GetFileContentQuery request, CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult(_gitRepositoryService.GetFileContent(request.Url, request.CommitSha, request.FilePath)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/SearchBugs.Application/Git/GetFileContents/GetFileContentQueryValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using FluentValidation; | ||
|
||
namespace SearchBugs.Application.Git.GetFileContents; | ||
|
||
internal sealed class GetFileContentQueryValidator : AbstractValidator<GetFileContentQuery> | ||
{ | ||
public GetFileContentQueryValidator() | ||
{ | ||
RuleFor(x => x.Url).NotEmpty(); | ||
RuleFor(x => x.CommitSha).NotEmpty(); | ||
RuleFor(x => x.FilePath).NotEmpty(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/SearchBugs.Application/Git/GetListTree/GetListTreeQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Shared.Messaging; | ||
|
||
namespace SearchBugs.Application.Git.GetListTree; | ||
|
||
public record GetListTreeQuery(string Url, string CommitSha) : IQuery<IEnumerable<GitTreeItemResult>>; |
22 changes: 22 additions & 0 deletions
22
src/SearchBugs.Application/Git/GetListTree/GetListTreeQueryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
| ||
using SearchBugs.Domain.Git; | ||
using Shared.Messaging; | ||
using Shared.Results; | ||
|
||
namespace SearchBugs.Application.Git.GetListTree; | ||
|
||
internal sealed class GetListTreeQueryHandler : IQueryHandler<GetListTreeQuery, IEnumerable<GitTreeItemResult>> | ||
{ | ||
private readonly IGitRepositoryService _gitRepositoryService; | ||
|
||
public GetListTreeQueryHandler(IGitRepositoryService gitRepositoryService) | ||
{ | ||
_gitRepositoryService = gitRepositoryService; | ||
} | ||
public Task<Result<IEnumerable<GitTreeItemResult>>> Handle(GetListTreeQuery request, CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult(_gitRepositoryService.ListTree(request.CommitSha, request.Url) | ||
.Map(tree => | ||
tree.Select(item => new GitTreeItemResult(item.Path, item.Name, item.Type, "")))); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/SearchBugs.Application/Git/GetListTree/GitListTreeQueryValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using FluentValidation; | ||
|
||
namespace SearchBugs.Application.Git.GetListTree; | ||
|
||
internal sealed class GitListTreeQueryValidator : AbstractValidator<GetListTreeQuery> | ||
{ | ||
public GitListTreeQueryValidator() | ||
{ | ||
RuleFor(x => x.Url).NotEmpty(); | ||
RuleFor(x => x.CommitSha).NotEmpty(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/SearchBugs.Application/Git/GetListTree/GitTreeItemResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace SearchBugs.Application.Git.GetListTree; | ||
|
||
public record GitTreeItemResult(string Path, string Name, string Type, string Url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
namespace SearchBugs.Domain.Git; | ||
using SearchBugs.Infrastructure.Services; | ||
using Shared.Results; | ||
|
||
namespace SearchBugs.Domain.Git; | ||
|
||
public interface IGitRepositoryService | ||
{ | ||
Result CheckoutBranch(string repoPath, string branchName); | ||
Result CommitChanges(string repoPath, string authorName, string authorEmail, string commitMessage); | ||
Result<IEnumerable<FileDiff>> CompareCommits(string repoPath, string baseCommitSha, string compareCommitSha); | ||
Result<IEnumerable<FileDiff>> GetCommitDiff(string repoPath, string commitSha); | ||
Result<IEnumerable<Contributor>> GetContributors(string repoPath); | ||
Result<IEnumerable<FileBlame>> GetFileBlame(string repoPath, string filePath); | ||
Result<string> GetFileContent(string repoPath, string commitSha, string filePath); | ||
Result<IEnumerable<GitTreeItem>> ListTree(string commitSha, string repoPath); | ||
Result<MergeResult> MergeBranches(string repoPath, string sourceBranchName, string targetBranchName, string mergerName, string mergerEmail); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.