some work

This commit is contained in:
2024-09-07 09:45:38 +02:00
parent f6219c0aa8
commit 043b14e9a9
32 changed files with 356 additions and 163 deletions

View File

@@ -21,7 +21,7 @@ internal class GitLabRepoWorkspace(GitLabRepoWorkspaceConfig config) : IWorkspac
{
InstallInfos = InstallInfos.Parse(await GetContent(ConfigX.FileLocationInstallJson));
UpdateInfos = UpdateInfos.Parse(await GetContent(ConfigX.FileLocationUpdateJson));
ConfigX.InstanceUrl = (await Gitlab.Projects.GetByIdAsync((int)ConfigX.RepoId, new())).NameWithNamespace;
ConfigX.RepoName = (await Gitlab.Projects.GetByIdAsync((int)ConfigX.RepoId, new())).Name;
return InstallInfos != null && UpdateInfos != null;
}
@@ -38,27 +38,25 @@ internal class GitLabRepoWorkspace(GitLabRepoWorkspaceConfig config) : IWorkspac
private async Task<string> GetContent(string path)
{
var pathUrl = UrlEncoder.Default.Encode(path);
var repoId = new ProjectId(ConfigX.RepoId);
var repo = Gitlab.GetRepository(repoId);
var data = await repo.Files.GetAsync(pathUrl, ConfigX.RepoBranche);
var data = await repo.Files.GetAsync(path, ConfigX.RepoBranche);
return data.DecodedContent;
}
private Task<bool> SaveContent(string path, string content)
{
var pathUrl = UrlEncoder.Default.Encode(path);
var repoId = new ProjectId(ConfigX.RepoId);
var repo = Gitlab.GetRepository(repoId);
var update = new FileUpsert
{
Branch = ConfigX.RepoBranche,
CommitMessage = "update " + Path.GetFileName(pathUrl),
CommitMessage = "update " + Path.GetFileName(path),
RawContent = content,
Path = pathUrl,
Path = path,
};
if (repo.Files.FileExists(pathUrl, ConfigX.RepoBranche))
if (repo.Files.FileExists(path, ConfigX.RepoBranche))
repo.Files.Update(update);
else
repo.Files.Create(update);

View File

@@ -4,7 +4,7 @@ namespace ModpackUpdater.Apps.Manager.Features.Workspaces.GitLabRepo;
internal class GitLabRepoWorkspaceConfig : WorkspaceConfig
{
public override string DisplayText => $"{RepoName ?? "?"} at {RepoBranche} on {InstanceUrl}";
public override string DisplayText => $"{RepoName ?? "?"} | {RepoBranche} | {InstanceUrl}";
public string? RepoName { get; set; }
@@ -18,5 +18,5 @@ internal class GitLabRepoWorkspaceConfig : WorkspaceConfig
public string FileLocationInstallJson { get; set; } = "install.json";
public string FileLocationUpdateJson { get; set; } = "update.json";
public string FileLocationUpdateJson { get; set; } = "updates.json";
}

View File

@@ -36,7 +36,7 @@ internal partial class GitLabRepoWorkspaceConfigEditor : RadFlyoutBase, ILoadCon
settings.ApiToken = radTextBox_ApiToken.Text.Trim();
settings.RepoId = (long)radSpinEditor_RepoId.Value;
settings.RepoBranche = radTextBox_RepoBranche.Text.Trim();
settings.InstanceUrl = radTextBox_FileLocInstallJson.Text.Trim();
settings.FileLocationInstallJson = radTextBox_FileLocInstallJson.Text.Trim();
settings.FileLocationUpdateJson = radTextBox_FileLocUpdateJson.Text.Trim();
return base.ValidateOK();
}