Merge pull request '* Extended GiteaSerive' (#62) from DelforSender into master
Reviewed-on: #62
This commit was merged in pull request #62.
This commit is contained in:
8
Services/Gitea/GiteaConfiguration.cs
Normal file
8
Services/Gitea/GiteaConfiguration.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Services.Gitea;
|
||||
|
||||
public class GiteaConfiguration
|
||||
{
|
||||
public string Owner { get; set; } = string.Empty;
|
||||
public string Repo { get; set; } = string.Empty;
|
||||
public string Branch { get; set; } = string.Empty;
|
||||
}
|
||||
38
Services/Gitea/GiteaService.cs
Normal file
38
Services/Gitea/GiteaService.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Gitea.Net.Api;
|
||||
using Gitea.Net.Client;
|
||||
using Gitea.Net.Model;
|
||||
|
||||
namespace Services.Gitea;
|
||||
|
||||
public class GiteaService
|
||||
{
|
||||
public RepositoryApi CreateGiteaClient(string basePath, string giteaApiToken)
|
||||
{
|
||||
var config = new Configuration
|
||||
{
|
||||
BasePath = basePath,
|
||||
ApiKey =
|
||||
{
|
||||
["token"] = giteaApiToken
|
||||
}
|
||||
};
|
||||
|
||||
return new RepositoryApi(config);
|
||||
}
|
||||
|
||||
public async Task<List<Commit>> GetLastCommits(RepositoryApi repositoryApi, GiteaConfiguration configuration,
|
||||
int limit)
|
||||
{
|
||||
var lastCommits = await repositoryApi.RepoGetAllCommitsAsync(configuration.Owner, configuration.Repo,
|
||||
configuration.Branch, limit: limit);
|
||||
return lastCommits;
|
||||
}
|
||||
|
||||
public async Task<ContentsResponse> GetFileContent(RepositoryApi repositoryApi, GiteaConfiguration configuration,
|
||||
string filename)
|
||||
{
|
||||
var repoGetContentsAsync =
|
||||
await repositoryApi.RepoGetContentsAsync(configuration.Owner, configuration.Repo, filename);
|
||||
return repoGetContentsAsync;
|
||||
}
|
||||
}
|
||||
13
Services/Gitea/IGiteaService.cs
Normal file
13
Services/Gitea/IGiteaService.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Gitea.Net.Api;
|
||||
using Gitea.Net.Model;
|
||||
|
||||
namespace Services.Gitea;
|
||||
|
||||
public interface IGiteaService
|
||||
{
|
||||
RepositoryApi CreateGiteaClient(string basePath, string giteaApiToken);
|
||||
Task<List<Commit>> GetLastCommits(RepositoryApi repositoryApi, GiteaConfiguration configuration, int limit);
|
||||
|
||||
Task<ContentsResponse> GetFileContent(RepositoryApi repositoryApi, GiteaConfiguration configuration,
|
||||
string filename);
|
||||
}
|
||||
Reference in New Issue
Block a user