Skip to content

Commit 3e1e4b8

Browse files
committed
Refactor /gh status implementation, change colour if deployment info missing, add version to footer
1 parent 0d091f7 commit 3e1e4b8

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

bot/src/ghutils/cogs/app_commands/github.py

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
from githubkit import GitHub
1616
from githubkit.exception import GitHubException
1717
from githubkit.rest import Issue, PullRequest, SimpleUser
18-
from more_itertools import consecutive_groups
18+
from more_itertools import consecutive_groups, ilen
1919
from yarl import URL
2020

21+
from ghutils.common.__version__ import VERSION
2122
from ghutils.core.cog import GHUtilsCog, SubGroup
2223
from ghutils.core.types import LoginState, NotLoggedInError
2324
from ghutils.db.models import (
@@ -215,38 +216,54 @@ async def status(
215216
):
216217
"""Show information about GitHub Utils."""
217218

218-
embed = Embed(
219-
title="Bot Status",
220-
color=Color.green(),
221-
)
222-
223-
commands = list(self.bot.tree.walk_commands())
224-
225-
if deployment := self.env.deployment:
226-
commit_url = f"https://github.com/object-Object/discord-github-utils/commit/{deployment.commit_sha}"
227-
embed.add_field(
228-
name="Commit",
229-
value=textwrap.dedent(
230-
f"""\
231-
[{shorten_sha(deployment.commit_sha)}]({commit_url}): {deployment.commit_message}
232-
{_discord_date(deployment.commit_timestamp)}"""
233-
),
219+
if info := self.env.deployment:
220+
color = Color.green()
221+
commit_url = f"https://github.com/object-Object/discord-github-utils/commit/{info.commit_sha}"
222+
commit_info = textwrap.dedent(
223+
f"""\
224+
[{info.short_commit_sha}]({commit_url}): {info.commit_message}
225+
{_discord_date(info.commit_timestamp)}"""
226+
)
227+
deployment_time_info = _discord_date(info.timestamp)
228+
else:
229+
color = Color.orange()
230+
commit_info = "Unknown"
231+
deployment_time_info = "Unknown"
232+
233+
embed = (
234+
Embed(
235+
title="Bot Status",
236+
color=color,
237+
)
238+
.set_footer(text=f"v{VERSION}")
239+
.add_field(
240+
name="Deployed commit",
241+
value=commit_info,
234242
inline=False,
235243
)
236-
embed.add_field(
237-
name="Latest deployment",
238-
value=_discord_date(deployment.timestamp),
244+
.add_field(
245+
name="Deployment time",
246+
value=deployment_time_info,
239247
inline=False,
240248
)
241-
242-
embed.add_field(
243-
name="Latest restart",
244-
value=_discord_date(self.bot.start_time),
245-
inline=False,
249+
.add_field(
250+
name="Uptime",
251+
value=_discord_date(self.bot.start_time),
252+
inline=False,
253+
)
254+
.add_field(
255+
name="Servers",
256+
value=f"{len(self.bot.guilds)}",
257+
)
258+
.add_field(
259+
name="Cogs",
260+
value=f"{len(self.bot.cogs)}",
261+
)
262+
.add_field(
263+
name="Commands",
264+
value=f"{ilen(self.bot.tree.walk_commands())}",
265+
)
246266
)
247-
embed.add_field(name="Servers", value=f"{len(self.bot.guilds)}")
248-
embed.add_field(name="Cogs", value=f"{len(self.bot.cogs)}")
249-
embed.add_field(name="Commands", value=f"{len(commands)}")
250267

251268
await respond_with_visibility(interaction, visibility, embed=embed)
252269

bot/src/ghutils/core/env.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from yarl import URL
1111

1212
from ghutils.db.models import UserGitHubTokens
13+
from ghutils.utils.github import shorten_sha
1314

1415
logger = logging.getLogger(__name__)
1516

@@ -81,6 +82,10 @@ class DeploymentSettings(BaseSettings, env_prefix="deployment__"):
8182
commit_timestamp: datetime
8283
commit_message: str
8384

85+
@property
86+
def short_commit_sha(self):
87+
return shorten_sha(self.commit_sha)
88+
8489

8590
class GHUtilsEnv(BaseSettings):
8691
token: SecretStr

0 commit comments

Comments
 (0)