Ai
4 Star 24 Fork 2

IoTSharp/Extensions.Configuration.GitRepository

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
GitLabRepositoryClient.cs 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
麦壳饼 提交于 2025-04-15 12:46 +08:00 . 调整未默认 hosturl
using NGitLab;
using NGitLab.Models;
namespace Extensions.Configuration.GitRepository.GitLabProvider
{
internal class GitLabRepositoryClient : IGitRepositoryClient
{
private NGitLab.GitLabClient client;
private readonly GitRepositoryConfigurationOptions _options;
private Project project;
private IRepositoryClient repo;
public GitLabRepositoryClient(GitRepositoryConfigurationOptions options)
{
_options = options;
}
private void check_connect()
{
if (client == null)
{
client = new NGitLab.GitLabClient(_options.HostUrl, _options.AuthenticationToken);
}
if (project == null || repo == null)
{
try
{
project = client.Projects.GetByNamespacedPathAsync(_options.RepositoryPath).GetAwaiter().GetResult();
repo = client.GetRepository(new ProjectId(project.Id));
}
catch (System.Exception ex)
{
Console.WriteLine($"GitLabRepositoryClient:{ex.ToString()}");
throw;
}
}
}
public bool FileExists(string filePath)
{
check_connect();
return repo.Files.FileExists(filePath, project.DefaultBranch);
}
public string GetFile(string fileName)
{
check_connect();
var context = repo.Files.Get(fileName, project.DefaultBranch).DecodedContent;
return context;
}
public void PutFile(string fileName, string content, string msg)
{
check_connect();
var fileUpsert = new FileUpsert
{
Branch = project.DefaultBranch,
CommitMessage = msg,
RawContent = content,
Encoding = "base64",
Path = fileName
};
repo.Files.Create(fileUpsert);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/IoTSharp/Extensions.Configuration.GitRepository.git
git@gitee.com:IoTSharp/Extensions.Configuration.GitRepository.git
IoTSharp
Extensions.Configuration.GitRepository
Extensions.Configuration.GitRepository
main

搜索帮助