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:
2026-01-23 08:02:54 +00:00
3 changed files with 59 additions and 0 deletions

View 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;
}

View 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;
}
}

View 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);
}