0.3.9.6.a4
Minor fix to redundant commit messages being posted when no version change it performed
This commit is contained in:
parent
40ef32c530
commit
7c9ec713b7
2
bot.py
2
bot.py
@ -9,7 +9,7 @@ from modules.common.boot_notice import post_boot_notice
|
||||
|
||||
# Version consists of:
|
||||
# Major.Enhancement.Minor.Patch.Test (Test is alphanumeric; doesn’t trigger auto update)
|
||||
VERSION = "0.3.9.6.a3"
|
||||
VERSION = "0.3.9.6.a4"
|
||||
|
||||
# ---------- Env loading ----------
|
||||
|
||||
|
@ -82,7 +82,7 @@ def _parse_repo_url(repo_url: str) -> tuple[str | None, str | None, str | None]:
|
||||
def _auth_headers_from_cfg(r):
|
||||
"""
|
||||
Build Authorization header using SHAI_REPO_AHTOKEN (cfg: repo_ahtoken).
|
||||
The value may be raw; we prefix 'token ' if needed.
|
||||
Value may be raw; we prefix 'token ' if needed.
|
||||
Also supports SHAI_GITEA_TOKEN / SHAI_GITEA_USER as secondary.
|
||||
"""
|
||||
ahtoken = r.get('repo_ahtoken', '').strip() # SHAI_REPO_AHTOKEN
|
||||
@ -91,7 +91,6 @@ def _auth_headers_from_cfg(r):
|
||||
ahtoken = f"token {ahtoken}"
|
||||
return {"Authorization": ahtoken}
|
||||
|
||||
# Optional secondary envs for future private usage
|
||||
tok = os.getenv("SHAI_GITEA_TOKEN", "").strip()
|
||||
usr = os.getenv("SHAI_GITEA_USER", "").strip()
|
||||
if tok and usr:
|
||||
@ -118,9 +117,9 @@ async def _http_json(url: str, headers: dict, timeout_sec: int = 10):
|
||||
async def _fetch_latest_commit(api_base: str, owner: str, repo: str, branch: str | None,
|
||||
headers: dict) -> tuple[str | None, str | None, str | None]:
|
||||
"""
|
||||
Returns (sha, subject, body) for the latest commit using the list-commits endpoint:
|
||||
Returns (sha, subject, body) for latest commit using list-commits:
|
||||
/api/v1/repos/{owner}/{repo}/commits?sha=main&stat=false&verification=false&files=false&limit=1
|
||||
If branch is falsy, omits 'sha' and lets server default.
|
||||
If branch is falsy, omit 'sha' to use server default.
|
||||
"""
|
||||
params = {
|
||||
"stat": "false",
|
||||
@ -173,8 +172,9 @@ def _format_status_line(kind: str, old_ver: str | None, new_ver: str | None) ->
|
||||
|
||||
async def post_boot_notice(bot):
|
||||
"""
|
||||
Always posts a startup status + the latest commit message (Version + md body)
|
||||
to the modlog channel. Uses SHAI_REPO_URL and SHAI_REPO_AHTOKEN via cfg().
|
||||
Always posts a startup status to the modlog channel.
|
||||
- If version changed (update or rollback): post status + full commit message.
|
||||
- If NO version change (manual/scheduled): post status ONLY, but append the running version to that status.
|
||||
"""
|
||||
try:
|
||||
await bot.wait_until_ready()
|
||||
@ -198,9 +198,8 @@ async def post_boot_notice(bot):
|
||||
return
|
||||
|
||||
repo_url = r.get('repo_url', '') # SHAI_REPO_URL
|
||||
# Branch optional; if empty, we omit 'sha='
|
||||
branch = r.get('repo_branch', 'main') or None # SHAI_REPO_BRANCH (optional)
|
||||
check_time_utc = r.get('check_time_utc', '') # SHAI_CHECK_TIME_UTC (optional, e.g. "03:00")
|
||||
check_time_utc = r.get('check_time_utc', '') # SHAI_CHECK_TIME_UTC (optional)
|
||||
headers = _auth_headers_from_cfg(r)
|
||||
|
||||
api_base = owner = repo = None
|
||||
@ -248,8 +247,15 @@ async def post_boot_notice(bot):
|
||||
else:
|
||||
reason, ping_owner = ("scheduled" if _is_near_scheduled(now_utc, check_time_utc) else "manual"), False
|
||||
|
||||
# Post status
|
||||
# Build + post status line
|
||||
status_line = _format_status_line(reason, prev_ver, curr_ver)
|
||||
|
||||
# NEW: If no version change (manual/scheduled), append the running version to the status line,
|
||||
# and DO NOT post the commit message separately.
|
||||
append_version_only = reason in ("manual", "scheduled")
|
||||
if append_version_only and curr_ver:
|
||||
status_line = f"{status_line} — running **{curr_ver}**"
|
||||
|
||||
try:
|
||||
allowed = discord.AllowedMentions(
|
||||
everyone=False,
|
||||
@ -264,14 +270,15 @@ async def post_boot_notice(bot):
|
||||
print(f"[boot_notice] failed to send status line: {e}")
|
||||
return
|
||||
|
||||
# Post commit message (Version + md details)
|
||||
try:
|
||||
title = (curr_ver or subject or "Latest commit").strip()
|
||||
if title or body:
|
||||
commit_msg = f"**{title}**\n{body}" if body else f"**{title}**"
|
||||
await ch.send(commit_msg, allowed_mentions=discord.AllowedMentions.none())
|
||||
except Exception as e:
|
||||
print(f"[boot_notice] failed to send commit message: {e}")
|
||||
# Only post commit message if version CHANGED (updated or rollback)
|
||||
if not append_version_only:
|
||||
try:
|
||||
title = (curr_ver or subject or "Latest commit").strip()
|
||||
if title or body:
|
||||
commit_msg = f"**{title}**\n{body}" if body else f"**{title}**"
|
||||
await ch.send(commit_msg, allowed_mentions=discord.AllowedMentions.none())
|
||||
except Exception as e:
|
||||
print(f"[boot_notice] failed to send commit message: {e}")
|
||||
|
||||
# Persist state
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user