Skip to content

Commit 1bf1fc2

Browse files
committed
Forgejo Migration
1 parent a4ee350 commit 1bf1fc2

24 files changed

Lines changed: 152 additions & 766 deletions

src/Bot/Commands/Interactions/Modules/GitLab/CreateUserCommand.cs renamed to src/Bot/Commands/Interactions/Modules/Forgejo/CreateUserCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
namespace RyuBot.Commands.Interactions.Modules;
44

5-
public partial class GitLabModule
5+
public partial class ForgejoModule
66
{
7-
[SlashCommand("create-user", "Create a user on the Ryubing GitLab. Bot owner only.")]
7+
[SlashCommand("create-user", "Create a user on the Ryubing Forgejo. Bot owner only.")]
88
[RequireBotOwnerPrecondition]
99
public async Task<RuntimeResult> CreateUserAsync(string username, string email, string name = null)
1010
{
1111
await DeferAsync(true);
1212

13-
var error = await GitLab.CreateUserAsync(username, email, name);
13+
var error = await Forgejo.CreateUserAsync(username, email, name);
1414

1515
if (error != null)
1616
{
1717
Error(error);
1818
return BadRequest(String(sb =>
1919
{
20-
sb.AppendLine("Failed to create user. Likely reason is the configured GitLab access token does not have administrator rights.");
20+
sb.AppendLine("Failed to create user. Likely reason is the configured Forgejo access token does not have administrator rights.");
2121
sb.AppendLine(Format.Code(error.Message, string.Empty));
2222
}));
2323
}

src/Bot/Commands/Interactions/Modules/GitLab/WikiCommand.cs renamed to src/Bot/Commands/Interactions/Modules/Forgejo/WikiCommand.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
using Discord.Interactions;
2-
using NGitLab.Models;
32

43
namespace RyuBot.Commands.Interactions.Modules;
54

6-
public partial class GitLabModule
5+
public partial class ForgejoModule
76
{
8-
[SlashCommand("wiki", "Find a wiki page on the Ryubing project page on the Ryubing GitLab.")]
7+
[SlashCommand("wiki", "Find a wiki page on the Ryubing project page on the Ryubing Forgejo.")]
98
public Task<RuntimeResult> WikiAsync(
109
[Summary("page", "The slug or title of the wiki page to lookup.")] [Autocomplete(typeof(WikiPageAutocompleter))]
1110
string page,
1211
[Summary("public", "Post the wiki page result publicly.")]
1312
bool publicResult = false)
1413
{
15-
if (!GitLab.SearchWikiPages(page).FindFirst().TryGet(out var wikiPage))
14+
if (!Forgejo.SearchWikiPages(page).FindFirst().TryGet(out var wikiPage))
1615
return BadRequest(
1716
new StringBuilder()
1817
.AppendLine($"Could not find a wiki page entry for `{page}`.")
@@ -22,7 +21,7 @@ public Task<RuntimeResult> WikiAsync(
2221
);
2322

2423
return Ok(CreateReplyBuilder(!publicResult)
25-
.WithContent($"View the `{wikiPage.Title}` wiki page {Format.Url("here", GitLabService.GetWikiPageUrl(wikiPage))}.")
24+
.WithContent($"View the `{wikiPage.title}` wiki page {Format.Url("here", wikiPage.html_url)}.")
2625
);
2726
}
2827
}

src/Bot/Commands/Interactions/Modules/GitLabModule.cs renamed to src/Bot/Commands/Interactions/Modules/ForgejoModule.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
namespace RyuBot.Commands.Interactions.Modules;
55

6-
[Group("gitlab", "Gitlab access & administration commands.")]
7-
public partial class GitLabModule : RyujinxBotSlashCommandModule
6+
[Group("forgejo", "Forgejo access & administration commands.")]
7+
public partial class ForgejoModule : RyujinxBotSlashCommandModule
88
{
9-
public GitLabService GitLab { get; set; }
9+
public ForgejoService Forgejo { get; set; }
1010

1111
// :Angryreaction:
1212
public GitHubService GitHub { get; set; }

src/Bot/Commands/Interactions/Modules/GitHub/LatestReleaseCommand.cs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Discord.Interactions;
22
using Octokit;
3+
using Release = ForgejoApiClient.Api.Release;
34

45
namespace RyuBot.Commands.Interactions.Modules;
56

@@ -28,32 +29,32 @@ public Task<RuntimeResult> LatestReleaseAsync(
2829
private async Task<RuntimeResult> LatestRyubingReleaseAsync(string rc)
2930
{
3031
var latest = rc.EqualsIgnoreCase("Canary")
31-
? await GitLab.GetLatestCanaryAsync()
32+
? await ForgejoService.GetLatestCanaryAsync()
3233
: rc.EqualsIgnoreCase("Stable")
33-
? await GitLab.GetLatestStableAsync()
34+
? await ForgejoService.GetLatestStableAsync()
3435
: null;
3536

3637
if (latest is null)
3738
return BadRequest(
3839
$"Unknown release channel {rc}. Please wait for the autocomplete suggestions to fill in if you aren't sure what to put!");
3940

40-
var windowsX64 = latest.Assets.Links
41-
.FirstOrDefault(x => x.AssetName.ContainsIgnoreCase("win_x64"));
42-
var windowsArm64 = latest.Assets.Links
43-
.FirstOrDefault(x => x.AssetName.ContainsIgnoreCase("win_arm64"));
44-
var linuxX64 = latest.Assets.Links
45-
.FirstOrDefault(x => x.AssetName.ContainsIgnoreCase("linux_x64"));
46-
var linuxX64AppImage = latest.Assets.Links
47-
.FirstOrDefault(x => x.AssetName.EndsWithIgnoreCase("x64.AppImage"));
48-
var macOs = latest.Assets.Links
49-
.FirstOrDefault(x => x.AssetName.ContainsIgnoreCase("macos_universal"));
50-
var linuxArm64 = latest.Assets.Links
51-
.FirstOrDefault(x => x.AssetName.ContainsIgnoreCase("linux_arm64"));
52-
var linuxArm64AppImage = latest.Assets.Links
53-
.FirstOrDefault(x => x.AssetName.EndsWithIgnoreCase("arm64.AppImage"));
41+
var windowsX64 = latest.assets?
42+
.FirstOrDefault(x => x.name.ContainsIgnoreCase("win_x64"));
43+
var windowsArm64 = latest.assets?
44+
.FirstOrDefault(x => x.name.ContainsIgnoreCase("win_arm64"));
45+
var linuxX64 = latest.assets?
46+
.FirstOrDefault(x => x.name.ContainsIgnoreCase("linux_x64"));
47+
var linuxX64AppImage = latest.assets?
48+
.FirstOrDefault(x => x.name.EndsWithIgnoreCase("x64.AppImage"));
49+
var macOs = latest.assets?
50+
.FirstOrDefault(x => x.name.ContainsIgnoreCase("macos_universal"));
51+
var linuxArm64 = latest.assets?
52+
.FirstOrDefault(x => x.name.ContainsIgnoreCase("linux_arm64"));
53+
var linuxArm64AppImage = latest.assets?
54+
.FirstOrDefault(x => x.name.EndsWithIgnoreCase("arm64.AppImage"));
5455

5556
StringBuilder releaseBody = new();
56-
releaseBody.AppendLine(DiscordHelper.Zws).AppendLine("### Downloads");
57+
releaseBody.Append($"Total downloads: {latest.assets?.Sum(x => x.download_count ?? 0) ?? 0}").AppendLine(DiscordHelper.Zws).AppendLine("### Links");
5758

5859
applyArtifact(windowsX64, "Windows x64");
5960
applyArtifacts((linuxX64, linuxX64AppImage), "Linux x64");
@@ -64,32 +65,32 @@ private async Task<RuntimeResult> LatestRyubingReleaseAsync(string rc)
6465
return Ok(CreateReplyBuilder()
6566
.WithEmbed(embed =>
6667
{
67-
embed.WithTitle($"Ryujinx {latest.Name}".Trim()).WithUrl(latest.Links.Self);
68-
embed.WithAuthor(latest.Author.Name, latest.Author.AvatarUrl);
68+
embed.WithTitle($"Ryujinx {latest.name}".Trim()).WithUrl(latest.html_url);
69+
embed.WithAuthor(latest.author!.login_name, latest.author.avatar_url);
6970
embed.WithDescription(releaseBody);
70-
embed.WithTimestamp(latest.CreatedAt);
71+
embed.WithTimestamp(latest.created_at ?? DateTimeOffset.Now);
7172
}));
7273

73-
void applyArtifact(GitLabReleaseJsonResponse.AssetLink asset, string friendlyName)
74+
void applyArtifact(ForgejoApiClient.Api.Attachment asset, string friendlyName)
7475
{
7576
if (asset is null)
7677
return;
7778

78-
releaseBody.AppendLine($"{Format.Url(friendlyName, asset.Url)}");
79+
releaseBody.AppendLine($"{Format.Url(friendlyName, asset.browser_download_url)}");
7980
}
8081

8182
void applyArtifacts(
82-
(GitLabReleaseJsonResponse.AssetLink Normal, GitLabReleaseJsonResponse.AssetLink AppImage) asset,
83+
(ForgejoApiClient.Api.Attachment Normal, ForgejoApiClient.Api.Attachment AppImage) asset,
8384
string friendlyName)
8485
{
8586
if (asset.Normal != null)
8687
{
87-
releaseBody.Append($"{Format.Url(friendlyName, asset.Normal.Url)} ");
88+
releaseBody.Append($"{Format.Url(friendlyName, asset.Normal.browser_download_url)} ");
8889
}
8990

9091
if (asset.AppImage != null)
9192
{
92-
releaseBody.AppendLine($"({Format.Url("AppImage", asset.AppImage.Url)})");
93+
releaseBody.AppendLine($"({Format.Url("AppImage", asset.AppImage.browser_download_url)})");
9394
}
9495
else if (asset.Normal != null)
9596
releaseBody.AppendLine();

src/Bot/Commands/Interactions/Modules/GitHubModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public partial class GitHubModule : RyujinxBotSlashCommandModule
1010
public static readonly Color ClosedColor = new(0xDA3633);
1111

1212
// :Angryreaction:
13-
public GitLabService GitLab { get; set; }
13+
public ForgejoService ForgejoService { get; set; }
1414

1515
public GitHubService GitHub { get; set; }
1616

src/Bot/Commands/Interactions/Modules/GitLab/MirrorReleaseCommand.cs

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/Bot/Commands/Interactions/Modules/GitLab/NukeVersionCommand.cs

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/Bot/Commands/Interactions/Modules/autocompleters.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ public override Task<AutocompletionResult> GenerateSuggestionsAsync(
141141

142142
if (!option.Focused || string.Empty.Equals(userValue)) continue;
143143

144-
var results = services.Get<GitLabService>()
144+
var results = services.Get<ForgejoService>()
145145
.SearchWikiPages(userValue).Take(5).ToArray();
146146

147147
if (results.Length > 0)
148148
return Task.FromResult(AutocompletionResult.FromSuccess(
149-
results.Select(it => new AutocompleteResult(it.Title, it.Slug))
149+
results.Select(it => new AutocompleteResult(it.title, it.sub_url))
150150
));
151151
}
152152

153153
return Task.FromResult(AutocompletionResult.FromSuccess(
154-
services.Get<GitLabService>().WikiPages.Select(it => new AutocompleteResult(it.Title, it.Slug))
154+
services.Get<ForgejoService>().WikiPages.Select(it => new AutocompleteResult(it.title, it.sub_url))
155155
));
156156
}
157157
}

0 commit comments

Comments
 (0)