Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add creation for the helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 15, 2024
1 parent c8de04e commit c3a8b50
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions RotationSolver.Basic/Helpers/GithubRecourcesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,41 @@ internal static async Task ModifyFile<T>(string path, ModifyValueDelegate<T?> mo
return;
}

if (content.Count == 0)
{
Svc.Log.Error($"Failed to find the file {path} in {RepoName}!");
return;
}
var shouldCreate = content.Count == 0;

T? value;
try
if (shouldCreate)
{
value = JsonConvert.DeserializeObject<T>(content[0].Content);
value = default;
}
catch
else
{
value = default;
try
{
value = JsonConvert.DeserializeObject<T>(content[0].Content);
}
catch
{
value = default;
}
}


if (!modifyFile(ref value, out var commit))
{
return;
}

try
{
await GitHubClient.Repository.Content.UpdateFile(XIVConfigUIMain.UserName, RepoName, path, new(commit, JsonConvert.SerializeObject(value, Formatting.Indented), content[0].Sha));
if (shouldCreate)
{
await GitHubClient.Repository.Content.CreateFile(XIVConfigUIMain.UserName, RepoName, path, new(commit, JsonConvert.SerializeObject(value, Formatting.Indented)));
}
else
{
await GitHubClient.Repository.Content.UpdateFile(XIVConfigUIMain.UserName, RepoName, path, new(commit, JsonConvert.SerializeObject(value, Formatting.Indented), content[0].Sha));
}
}
catch(Exception ex)
{
Expand Down

0 comments on commit c3a8b50

Please sign in to comment.