commit 518159ea7f6a393c4fa8eb211b389c7d905f0fe1 Author: stillkill Date: Mon Feb 9 20:14:49 2026 -0600 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add57be --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ \ No newline at end of file diff --git a/GiteaPublish.sln b/GiteaPublish.sln new file mode 100644 index 0000000..0742ef7 --- /dev/null +++ b/GiteaPublish.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GiteaPublish", "GiteaPublish\GiteaPublish.csproj", "{4455C9F0-62D7-49E9-8245-8C49EEE28DC4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4455C9F0-62D7-49E9-8245-8C49EEE28DC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4455C9F0-62D7-49E9-8245-8C49EEE28DC4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4455C9F0-62D7-49E9-8245-8C49EEE28DC4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4455C9F0-62D7-49E9-8245-8C49EEE28DC4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/GiteaPublish/Gitea/ArchPackageRepo.cs b/GiteaPublish/Gitea/ArchPackageRepo.cs new file mode 100644 index 0000000..614f6e3 --- /dev/null +++ b/GiteaPublish/Gitea/ArchPackageRepo.cs @@ -0,0 +1,34 @@ +using System.Net.Http.Headers; +using Spectre.Console; + +namespace GiteaPublish.Gitea; + +public class ArchPackageRepo(HttpClient httpClient, IAnsiConsole ansiConsole, BasicAuthModel basicAuth) + : IPackageRepo +{ + public async Task PublishPackageAsync(string owner, string repository, string filePath) + { + ansiConsole.MarkupLine($"[blue]Publishing package {filePath} to {owner}/{repository}...[/]"); + HttpRequestMessage request = new(HttpMethod.Put, $"api/packages/{owner}/arch/{repository}"); + request.Content = new ByteArrayContent(await File.ReadAllBytesAsync(filePath)); + request.Headers.Authorization = new AuthenticationHeaderValue("Basic", basicAuth.AuthHeader); + HttpResponseMessage response = await httpClient.SendAsync(request); + if (response.IsSuccessStatusCode) return true; + ansiConsole.MarkupLine($"[red]Failed to publish package: {response.StatusCode}[/]"); + ansiConsole.MarkupLine($"[red]{(await response.Content.ReadAsStringAsync()).EscapeMarkup()}[/]"); + return false; + } + + public async Task DeletePackageAsync(string owner, string repository, string architecture, string packageName, + string packageVersion) + { + HttpRequestMessage request = new(HttpMethod.Delete, + $"api/packages/{owner}/arch/{repository}/{architecture}/{packageName}/{packageVersion}"); + request.Headers.Authorization = new AuthenticationHeaderValue("Basic", basicAuth.AuthHeader); + HttpResponseMessage response = await httpClient.SendAsync(request); + if (response.IsSuccessStatusCode) return true; + ansiConsole.MarkupLine($"[red]Failed to delete package: {response.StatusCode}[/]"); + ansiConsole.MarkupLine($"[red]{(await response.Content.ReadAsStringAsync()).EscapeMarkup()}[/]"); + return false; + } +} \ No newline at end of file diff --git a/GiteaPublish/Gitea/BasicAuthModel.cs b/GiteaPublish/Gitea/BasicAuthModel.cs new file mode 100644 index 0000000..a25e11a --- /dev/null +++ b/GiteaPublish/Gitea/BasicAuthModel.cs @@ -0,0 +1,15 @@ +namespace GiteaPublish.Gitea; + +public class BasicAuthModel +{ + public string AuthHeader => Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{_username}:{_password}")); + + private readonly string _username; + private readonly string _password; + + public BasicAuthModel(string username, string password) + { + _username = username; + _password = password; + } +} \ No newline at end of file diff --git a/GiteaPublish/Gitea/IPackageRepo.cs b/GiteaPublish/Gitea/IPackageRepo.cs new file mode 100644 index 0000000..5069494 --- /dev/null +++ b/GiteaPublish/Gitea/IPackageRepo.cs @@ -0,0 +1,25 @@ +namespace GiteaPublish.Gitea; + +public interface IPackageRepo +{ + /// + /// Publishes a package to the specified repository. The filePath should point to the package file (e.g., .nupkg for NuGet). The method returns true if the package was published successfully, and false otherwise. + /// + /// The owner of the repository + /// The name of the repository + /// The path to the package file + /// A bool representing whether the task was successful + public Task PublishPackageAsync(string owner, string repository, string filePath); + + + /// + /// Deletes a package from the specified repository. The method returns true if the package was deleted successfully, and false otherwise. + /// + /// The owner of the repositoty + /// The name of the repository + /// The package architecture + /// The name of the package + /// The version of the package + /// A bool representing whether the task was successful + public Task DeletePackageAsync(string owner, string repository, string architecture, string packageName, string packageVersion); +} \ No newline at end of file diff --git a/GiteaPublish/GiteaPublish.csproj b/GiteaPublish/GiteaPublish.csproj new file mode 100644 index 0000000..eb906af --- /dev/null +++ b/GiteaPublish/GiteaPublish.csproj @@ -0,0 +1,18 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + + + diff --git a/GiteaPublish/Program.cs b/GiteaPublish/Program.cs new file mode 100644 index 0000000..545ab96 --- /dev/null +++ b/GiteaPublish/Program.cs @@ -0,0 +1,14 @@ +using GiteaPublish.Gitea; +using Spectre.Console; + +namespace GiteaPublish; + +class Program +{ + static async Task Main(string[] args) + { + var basicAuthModel = new BasicAuthModel("", ""); + ArchPackageRepo repo = new(new HttpClient { BaseAddress = new Uri("https://git.stillkill.net") }, AnsiConsole.Console, basicAuthModel); + await repo.PublishPackageAsync("Stillkill", "core", "/home/stillkill/CollectHorse.tar.gz"); + } +} \ No newline at end of file