mirror of
https://git.stillkill.net/Stillkill/GiteaPublish.git
synced 2026-10-22 13:32:19 +01:00
Initial Commit
This commit is contained in:
commit
518159ea7f
7 files changed
+127
No files matched your search
@@ -0,0 +1,5 @@
|
||||
bin/
|
||||
obj/
|
||||
/packages/
|
||||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
||||
@@ -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
|
||||
@@ -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<bool> 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<bool> 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace GiteaPublish.Gitea;
|
||||
|
||||
public interface IPackageRepo
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repository">The name of the repository</param>
|
||||
/// <param name="filePath">The path to the package file</param>
|
||||
/// <returns>A bool representing whether the task was successful</returns>
|
||||
public Task<bool> PublishPackageAsync(string owner, string repository, string filePath);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a package from the specified repository. The method returns true if the package was deleted successfully, and false otherwise.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repositoty</param>
|
||||
/// <param name="repository">The name of the repository</param>
|
||||
/// <param name="architecture">The package architecture</param>
|
||||
/// <param name="packageName">The name of the package</param>
|
||||
/// <param name="packageVersion">The version of the package</param>
|
||||
/// <returns>A bool representing whether the task was successful</returns>
|
||||
public Task<bool> DeletePackageAsync(string owner, string repository, string architecture, string packageName, string packageVersion);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Spectre.Console.Cli" Version="0.53.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Commands\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user