This is Forgejo API client library for .NET. (unofficial)
This library is a relatively simple wrapping of the Forgejo API.
The client class ForgejoClient
has properties grouped by API category as indicated in the Swagger documentation.
It should not be too difficult to find a correspondence to a method. However, in order to find the exact correspondence, the ForgejoEndpoint attribute is specified in the method.
The endpoints indicated by the attribute can be matched against the document.
Authentication supports only token authentication using HTTP headers.
Although the Forgejo API specification may change from version to version, this library targets only a single version.
If the version targeted by the library does not match the server version, there is a large possibility that it will not work properly.
The server and client versions must be combined correctly.
Package versions are in semantic versioning format, but are numbered according to the following arrangement.
The version number of this package always uses the pre-release versioning format.
The core version part represents the version of the target server.
The version (rev.XX) portion of the pre-release is used to indicate the version of the library, not as a pre-release.
Therefore, differences in pre-release version numbers are not necessarily trivial changes.
Some samples are shown below.
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");
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");
using var client = new ForgejoClient(apiBase, apiToken);
var org = await client.Organization.CreateAsync(new(username: "org-name"));
var team_units = new Dictionary<string, string> { ["repo.code"] = "write", };
var team = await client.Organization.CreateTeamAsync("org-name", new(name: "team-name", units_map: team_units));
await client.Organization.AddTeamMemberAsync(team.id!.Value, "user-name");
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);
}
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");
using var adminClient = new ForgejoClient(apiBase, apiToken);
var userClient = adminClient.Sudo("user-name");
await userClient.Repository.WatchAsync("owner-name", "repo-name");