ForgejoApiClient 13.0.0-rev.1
dotnet add package ForgejoApiClient --version 13.0.0-rev.1
NuGet\Install-Package ForgejoApiClient -Version 13.0.0-rev.1
<PackageReference Include="ForgejoApiClient" Version="13.0.0-rev.1" />
<PackageVersion Include="ForgejoApiClient" Version="13.0.0-rev.1" />
<PackageReference Include="ForgejoApiClient" />
paket add ForgejoApiClient --version 13.0.0-rev.1
#r "nuget: ForgejoApiClient, 13.0.0-rev.1"
#:package ForgejoApiClient@13.0.0-rev.1
#addin nuget:?package=ForgejoApiClient&version=13.0.0-rev.1&prerelease
#tool nuget:?package=ForgejoApiClient&version=13.0.0-rev.1&prerelease
ForgejoApiClient
This is Forgejo API client library for .NET. (unofficial)
This library provides a relatively simple wrapper around the Forgejo API.
The ForgejoClient class exposes properties grouped by API category, as defined in the Swagger documentation.
It is generally straightforward to find the corresponding method. However, to identify the exact mapping, each method is annotated with a ForgejoEndpoint attribute.
The endpoint specified in the attribute can be cross-referenced with the official documentation.
Authentication is supported only via token authentication using HTTP headers.
Package and API Version
Although the Forgejo API specification may change between versions, this library targets a single specific API version.
If the targeted API version does not match the server version, there is a high likelihood that it will not function correctly.
The server and client versions must be matched appropriately.
Package versions follow Semantic Versioning but with the following convention:
- The package version always uses the pre-release format.
- The core version number corresponds to the targeted Forgejo server version.
- The
rev.XXportion appears in the pre-release position, but here it represents the library’s own version and does not mean the library is a pre-release.
Therefore, differences in the rev.XX value may represent significant changes, not just minor updates.
Examples
Below are some usage examples.
Create a repository in your namespace and add topics
using ForgejoApiClient;
using ForgejoApiClient.Api;
var apiBase = new Uri(@"http://<your-hosting-server>/api/v1");
var apiToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
using var client = new ForgejoClient(apiBase, apiToken);
var me = await client.User.GetMeAsync();
if (me.login == null) throw new Exception("Unexpected user info");
var repoOptions = new CreateRepoOption(name: "repo-name", default_branch: "main", @private: true);
var repo = await client.Repository.CreateAsync(repoOptions);
await client.Repository.AddTopicAsync(me.login, "repo-name", topic: "sample");
await client.Repository.AddTopicAsync(me.login, "repo-name", topic: "test");
Create an organization and team, then add members
using var client = new ForgejoClient(apiBase, apiToken);
var org = await client.Organization.CreateAsync(new(username: "org-name"));
var teamUnits = new Dictionary<string, string> { ["repo.code"] = "write" };
var team = await client.Organization.CreateTeamAsync("org-name", new(name: "team-name", units_map: teamUnits));
await client.Organization.AddTeamMemberAsync(team.id!.Value, "user-name");
Save a content response
using var client = new ForgejoClient(apiBase, apiToken);
using (var archiveDownload = await client.Repository.GetArchiveAsync("owner-name", "repo-name", "main.zip"))
using (var fileStream = File.OpenWrite(archiveDownload.Result.FileName ?? "main.zip"))
{
await archiveDownload.Result.Stream.CopyToAsync(fileStream);
}
Create quota settings and assign users
using var client = new ForgejoClient(apiBase, apiToken);
var quotaGroup = await client.Admin.CreateQuotaGroupAsync(new(name: "package-quota"));
var quotaRule = await client.Admin.CreateQuotaRuleAsync(
new(name: "limit-packages-500M", limit: 500 * 1024 * 1024, subjects: ["size:assets:packages:all"])
);
await client.Admin.AddQuotaGroupRuleAsync("package-quota", "limit-packages-500M");
await client.Admin.AddQuotaGroupUserAsync("package-quota", "user-name");
Dispatch the workflow and wait for completion.
using var client = new ForgejoClient(apiBase, apiToken);
var options = new DispatchWorkflowOption(@ref: "main", return_run_info: true);
var run = await client.Repository.DispatchActionsWorkflowAsync("owner", "repo", "work.yml", options, cancelToken);
if (run?.id == null) throw new Exception("Failed to dispatch");
using var breaker = CancellationTokenSource.CreateLinkedTokenSource(cancelToken);
breaker.CancelAfter(TimeSpan.FromMinutes(5));
while (true)
{
await Task.Delay(TimeSpan.FromSeconds(5), breaker.Token);
var runInfo = await client.Repository.GetActionsRunAsync("owner", "repo", run.id.Value, breaker.Token);
if (DateTimeOffset.UnixEpoch < runInfo.stopped) break;
}
Run the API in a different user context using sudo
using var adminClient = new ForgejoClient(apiBase, apiToken);
var userClient = adminClient.Sudo("user-name");
await userClient.Repository.WatchAsync("owner-name", "repo-name");
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 13.0.0-rev.1 | 109 | 10/16/2025 | |
| 12.0.1-rev.4 | 310 | 8/21/2025 | |
| 12.0.1-rev.3 | 98 | 7/29/2025 | |
| 12.0.1-rev.2 | 115 | 7/28/2025 | |
| 11.0.0-rev.2 | 102 | 7/29/2025 | |
| 11.0.0-rev.1 | 246 | 4/20/2025 |