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

feat: add_query_param_get_file #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@
{
new()
{
Content = null,

Check warning on line 58 in Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs

View workflow job for this annotation

GitHub Actions / build-test-deploy

Cannot convert null literal to non-nullable reference type.

Check warning on line 58 in Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs

View workflow job for this annotation

GitHub Actions / build-test-deploy

Cannot convert null literal to non-nullable reference type.

Check warning on line 58 in Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs

View workflow job for this annotation

GitHub Actions / build-test-deploy

Cannot convert null literal to non-nullable reference type.

Check warning on line 58 in Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs

View workflow job for this annotation

GitHub Actions / build-test-deploy

Cannot convert null literal to non-nullable reference type.
FileName = "README.md",
FilePath = "README.md",
FileHash = readmeFileMetadata.FileHash
FileHash = readmeFileMetadata.FileHash,
LastCommitHash = readmeFileMetadata.LastCommitHash
},
new()
{
Content = null,

Check warning on line 66 in Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs

View workflow job for this annotation

GitHub Actions / build-test-deploy

Cannot convert null literal to non-nullable reference type.

Check warning on line 66 in Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs

View workflow job for this annotation

GitHub Actions / build-test-deploy

Cannot convert null literal to non-nullable reference type.

Check warning on line 66 in Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs

View workflow job for this annotation

GitHub Actions / build-test-deploy

Cannot convert null literal to non-nullable reference type.

Check warning on line 66 in Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFilesMetadata/GetFilesMetadataTests.cs

View workflow job for this annotation

GitHub Actions / build-test-deploy

Cannot convert null literal to non-nullable reference type.
FileName = filePath,
FilePath = filePath,
FileHash = newFileMetadata.Content!.Content.FileHash
FileHash = newFileMetadata.Content!.Content.FileHash,
LastCommitHash = newFileMetadata.Content!.Content.LastCommitHash
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task Handle_ShouldCallGetFileAsync_AndInputsAreValid()
_fileRestClient.GetFileAsync(owner,
repositoryName,
filePath,
Arg.Any<GetFileRequest>(),
referenceName,
Arg.Any<CancellationToken>())
.Returns(mockedResponse);

Expand All @@ -87,8 +87,7 @@ public async Task Handle_ShouldCallGetFileAsync_AndInputsAreValid()
await _fileRestClient.Received(1).GetFileAsync(owner,
repositoryName,
filePath,
Arg.Is<GetFileRequest>(x =>
x.ReferenceName == referenceName),
referenceName,
default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ Task<ApiResponse<List<GetFileResponseDto>>> GetFilesMetadataAsync(string owner,
[AliasAs("ref")] string branchName,
CancellationToken cancellationToken);

[Get("/repos/{owner}/{repo}/contents/{filepath}")]
[Get("/repos/{owner}/{repo}/contents/{filepath}?ref={ref}")]
Task<ApiResponse<GetFileResponseDto>> 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}")]
Expand Down
3 changes: 3 additions & 0 deletions Mohaymen.GiteaClient/Gitea/File/CreateFile/Models/Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class GetFileMetadataQuery : IRequest<ApiResponse<GetFileResponseDto>>
{
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<GetFileMetadataQuery, ApiResponse<GetFileResponseDto>>
Expand All @@ -41,9 +41,9 @@ public GetFileMetadataQueryHandler(IFileRestClient fileRestClient,
public async Task<ApiResponse<GetFileResponseDto>> 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)
Expand All @@ -53,5 +53,4 @@ public async Task<ApiResponse<GetFileResponseDto>> Handle(GetFileMetadataQuery m

return apiResponse;
}
}

}
Loading