diff --git a/Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs b/Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs index c4c14ff..318bb21 100644 --- a/Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs +++ b/Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs @@ -58,14 +58,16 @@ public async Task GetFile_ShouldGetFileWithOkStatusCode_WhenInputsAreProvidedPro Content = null, FileName = "README.md", FilePath = "README.md", - FileHash = readmeFileMetadata.FileHash + FileHash = readmeFileMetadata.FileHash, + LastCommitHash = readmeFileMetadata.LastCommitHash }, new() { Content = null, FileName = filePath, FilePath = filePath, - FileHash = newFileMetadata.Content!.Content.FileHash + FileHash = newFileMetadata.Content!.Content.FileHash, + LastCommitHash = newFileMetadata.Content!.Content.LastCommitHash } }; diff --git a/Mohaymen.GiteaClient.Tests/Gitea/File/GetFile/Commands/GetFileMetadataQueryHandlerTests.cs b/Mohaymen.GiteaClient.Tests/Gitea/File/GetFile/Commands/GetFileMetadataQueryHandlerTests.cs index 00e6e8c..2371305 100644 --- a/Mohaymen.GiteaClient.Tests/Gitea/File/GetFile/Commands/GetFileMetadataQueryHandlerTests.cs +++ b/Mohaymen.GiteaClient.Tests/Gitea/File/GetFile/Commands/GetFileMetadataQueryHandlerTests.cs @@ -76,7 +76,7 @@ public async Task Handle_ShouldCallGetFileAsync_AndInputsAreValid() _fileRestClient.GetFileAsync(owner, repositoryName, filePath, - Arg.Any(), + referenceName, Arg.Any()) .Returns(mockedResponse); @@ -87,8 +87,7 @@ public async Task Handle_ShouldCallGetFileAsync_AndInputsAreValid() await _fileRestClient.Received(1).GetFileAsync(owner, repositoryName, filePath, - Arg.Is(x => - x.ReferenceName == referenceName), + referenceName, default); } } \ No newline at end of file diff --git a/Mohaymen.GiteaClient/Gitea/File/Common/ApiCall/Abstractions/IFileRestClient.cs b/Mohaymen.GiteaClient/Gitea/File/Common/ApiCall/Abstractions/IFileRestClient.cs index 6d5b654..8b91231 100644 --- a/Mohaymen.GiteaClient/Gitea/File/Common/ApiCall/Abstractions/IFileRestClient.cs +++ b/Mohaymen.GiteaClient/Gitea/File/Common/ApiCall/Abstractions/IFileRestClient.cs @@ -18,12 +18,12 @@ Task>> GetFilesMetadataAsync(string owner, [AliasAs("ref")] string branchName, CancellationToken cancellationToken); - [Get("/repos/{owner}/{repo}/contents/{filepath}")] + [Get("/repos/{owner}/{repo}/contents/{filepath}?ref={ref}")] Task> GetFileAsync( [AliasAs("owner")] string owner, [AliasAs("repo")] string repositoryName, [AliasAs("filepath")] string filePath, - [Body] GetFileRequest getFileRequest, + [AliasAs("ref")] string refQuery, CancellationToken cancellationToken); [Post("/repos/{owner}/{repo}/contents/{filepath}")] diff --git a/Mohaymen.GiteaClient/Gitea/File/CreateFile/Models/Content.cs b/Mohaymen.GiteaClient/Gitea/File/CreateFile/Models/Content.cs index dd9097d..005a78d 100644 --- a/Mohaymen.GiteaClient/Gitea/File/CreateFile/Models/Content.cs +++ b/Mohaymen.GiteaClient/Gitea/File/CreateFile/Models/Content.cs @@ -15,4 +15,7 @@ public class Content [JsonProperty("sha")] public required string FileHash { get; init; } + + [JsonProperty("last_commit_sha")] + public required string LastCommitHash { get; init; } } \ No newline at end of file diff --git a/Mohaymen.GiteaClient/Gitea/File/GetFile/Dtos/GetFileResponseDto.cs b/Mohaymen.GiteaClient/Gitea/File/GetFile/Dtos/GetFileResponseDto.cs index 174295b..1a12fea 100644 --- a/Mohaymen.GiteaClient/Gitea/File/GetFile/Dtos/GetFileResponseDto.cs +++ b/Mohaymen.GiteaClient/Gitea/File/GetFile/Dtos/GetFileResponseDto.cs @@ -15,4 +15,8 @@ public class GetFileResponseDto [JsonProperty("sha")] public required string FileHash { get; init; } + + [JsonProperty("last_commit_sha")] + public required string LastCommitHash { get; init; } + } \ No newline at end of file diff --git a/Mohaymen.GiteaClient/Gitea/File/GetFile/Queries/GetFileMetadataQuery.cs b/Mohaymen.GiteaClient/Gitea/File/GetFile/Queries/GetFileMetadataQuery.cs index 141dc81..cfae585 100644 --- a/Mohaymen.GiteaClient/Gitea/File/GetFile/Queries/GetFileMetadataQuery.cs +++ b/Mohaymen.GiteaClient/Gitea/File/GetFile/Queries/GetFileMetadataQuery.cs @@ -17,7 +17,7 @@ public class GetFileMetadataQuery : IRequest> { public required string RepositoryName { get; init; } public required string FilePath { get; init; } - public string? ReferenceName { get; init; } + public string ReferenceName { get; init; } = "main"; } internal class GetFileMetadataQueryHandler : IRequestHandler> @@ -41,9 +41,9 @@ public GetFileMetadataQueryHandler(IFileRestClient fileRestClient, public async Task> Handle(GetFileMetadataQuery metadataQuery, CancellationToken cancellationToken) { _validator.ValidateAndThrow(metadataQuery); - var getFileRequest = metadataQuery.ToGetFileRequest(); var owner = _options.Value.RepositoriesOwner; - var apiResponse = await _fileRestClient.GetFileAsync(owner, metadataQuery.RepositoryName, metadataQuery.FilePath, getFileRequest, cancellationToken) + var apiResponse = await _fileRestClient.GetFileAsync(owner, metadataQuery.RepositoryName, metadataQuery.FilePath, + metadataQuery.ReferenceName, cancellationToken) .ConfigureAwait(false); await apiResponse.EnsureSuccessStatusCodeAsync(); if (apiResponse.Content is not null) @@ -53,5 +53,4 @@ public async Task> Handle(GetFileMetadataQuery m return apiResponse; } -} - +} \ No newline at end of file