Skip to content

Commit

Permalink
Add GitInfo NuGet package (#268)
Browse files Browse the repository at this point in the history
In this PR, I added a NuGet package called GitInfo. It can replace
Octobot.RepositoryUrl and display the bot version as the current branch
and commit.

---------

Signed-off-by: mctaylors <[email protected]>
Signed-off-by: Macintxsh <[email protected]>
  • Loading branch information
mctaylors authored Mar 19, 2024
1 parent 771750c commit 2342116
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Octobot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
<NeutralLanguage>en</NeutralLanguage>
<Description>A general-purpose Discord bot for moderation written in C#</Description>
<ApplicationIcon>docs/octobot.ico</ApplicationIcon>
<GitVersion>false</GitVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DiffPlex" Version="1.7.2" />
<PackageReference Include="GitInfo" Version="3.3.4" />
<PackageReference Include="Humanizer.Core.ru" Version="2.14.1" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
Expand Down
3 changes: 3 additions & 0 deletions locale/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@
<data name="TimeSpanExample" xml:space="preserve">
<value>Example of a valid input: `1h30m`</value>
</data>
<data name="Version" xml:space="preserve">
<value>Version: {0}</value>
</data>
<data name="SettingsWelcomeMessagesChannel" xml:space="preserve">
<value>Welcome messages channel</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions locale/Messages.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@
<data name="TimeSpanExample" xml:space="preserve">
<value>Пример правильного ввода: `1ч30м`</value>
</data>
<data name="Version" xml:space="preserve">
<value>Версия: {0}</value>
</data>
<data name="SettingsWelcomeMessagesChannel" xml:space="preserve">
<value>Канал для приветствий</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions locale/Messages.tt-ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@
<data name="TimeSpanExample" xml:space="preserve">
<value>правильно пишут так: `1h30m`</value>
</data>
<data name="Version" xml:space="preserve">
<value>{0}</value>
</data>
<data name="SettingsWelcomeMessagesChannel" xml:space="preserve">
<value>канал куда говорить здравствуйте</value>
</data>
Expand Down
52 changes: 52 additions & 0 deletions src/BuildInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Octobot;

public static class BuildInfo
{
public static string RepositoryUrl
{
get
{
return ThisAssembly.Git.RepositoryUrl;
}
}

public static string IssuesUrl
{
get
{
return $"{RepositoryUrl}/issues";
}
}

private static string Commit
{
get
{
return ThisAssembly.Git.Commit;
}
}

private static string Branch
{
get
{
return ThisAssembly.Git.Branch;
}
}

private static bool IsDirty
{
get
{
return ThisAssembly.Git.IsDirty;
}
}

public static string Version
{
get
{
return IsDirty ? $"{Branch}-{Commit}-dirty" : $"{Branch}-{Commit}";
}
}
}
5 changes: 3 additions & 2 deletions src/Commands/AboutCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,21 @@ private async Task<Result> SendAboutBotAsync(IUser bot, Snowflake guildId, Cance
.WithDescription(builder.ToString())
.WithColour(ColorsList.Cyan)
.WithImageUrl("https://i.ibb.co/fS6wZhh/octobot-banner.png")
.WithFooter(string.Format(Messages.Version, BuildInfo.Version))
.Build();

var repositoryButton = new ButtonComponent(
ButtonComponentStyle.Link,
Messages.ButtonOpenRepository,
new PartialEmoji(Name: "🌐"),
URL: Octobot.RepositoryUrl
URL: BuildInfo.RepositoryUrl
);

var issuesButton = new ButtonComponent(
ButtonComponentStyle.Link,
Messages.ButtonReportIssue,
new PartialEmoji(Name: "⚠️"),
URL: Octobot.IssuesUrl
URL: BuildInfo.IssuesUrl
);

return await _feedback.SendContextualEmbedResultAsync(embed,
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Events/ErrorLoggingPostExecutionEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task<Result> AfterExecutionAsync(
ButtonComponentStyle.Link,
Messages.ButtonReportIssue,
new PartialEmoji(Name: "⚠️"),
URL: Octobot.IssuesUrl
URL: BuildInfo.IssuesUrl
);

return await _feedback.SendContextualEmbedResultAsync(embed,
Expand Down
9 changes: 7 additions & 2 deletions src/Messages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/Octobot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ namespace Octobot;

public sealed class Octobot
{
public const string RepositoryUrl = "https://github.com/TeamOctolings/Octobot";
public const string IssuesUrl = $"{RepositoryUrl}/issues";

public static readonly AllowedMentions NoMentions = new(
Array.Empty<MentionType>(), Array.Empty<Snowflake>(), Array.Empty<Snowflake>());

Expand Down
2 changes: 1 addition & 1 deletion src/Responders/GuildLoadedResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private async Task<Result> SendDataLoadFailed(IGuild guild, GuildData data, IUse
ButtonComponentStyle.Link,
Messages.ButtonReportIssue,
new PartialEmoji(Name: "⚠️"),
URL: Octobot.IssuesUrl
URL: BuildInfo.IssuesUrl
);

return await _channelApi.CreateMessageWithEmbedResultAsync(channel, embedResult: errorEmbed,
Expand Down

0 comments on commit 2342116

Please sign in to comment.