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:
|
# Version consists of:
|
||||||
# Major.Enhancement.Minor.Patch.Test (Test is alphanumeric; doesn’t trigger auto update)
|
# 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 ----------
|
# ---------- 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):
|
def _auth_headers_from_cfg(r):
|
||||||
"""
|
"""
|
||||||
Build Authorization header using SHAI_REPO_AHTOKEN (cfg: repo_ahtoken).
|
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.
|
Also supports SHAI_GITEA_TOKEN / SHAI_GITEA_USER as secondary.
|
||||||
"""
|
"""
|
||||||
ahtoken = r.get('repo_ahtoken', '').strip() # SHAI_REPO_AHTOKEN
|
ahtoken = r.get('repo_ahtoken', '').strip() # SHAI_REPO_AHTOKEN
|
||||||
@ -91,7 +91,6 @@ def _auth_headers_from_cfg(r):
|
|||||||
ahtoken = f"token {ahtoken}"
|
ahtoken = f"token {ahtoken}"
|
||||||
return {"Authorization": ahtoken}
|
return {"Authorization": ahtoken}
|
||||||
|
|
||||||
# Optional secondary envs for future private usage
|
|
||||||
tok = os.getenv("SHAI_GITEA_TOKEN", "").strip()
|
tok = os.getenv("SHAI_GITEA_TOKEN", "").strip()
|
||||||
usr = os.getenv("SHAI_GITEA_USER", "").strip()
|
usr = os.getenv("SHAI_GITEA_USER", "").strip()
|
||||||
if tok and usr:
|
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,
|
async def _fetch_latest_commit(api_base: str, owner: str, repo: str, branch: str | None,
|
||||||
headers: dict) -> tuple[str | None, str | None, 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
|
/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 = {
|
params = {
|
||||||
"stat": "false",
|
"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):
|
async def post_boot_notice(bot):
|
||||||
"""
|
"""
|
||||||
Always posts a startup status + the latest commit message (Version + md body)
|
Always posts a startup status to the modlog channel.
|
||||||
to the modlog channel. Uses SHAI_REPO_URL and SHAI_REPO_AHTOKEN via cfg().
|
- 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:
|
try:
|
||||||
await bot.wait_until_ready()
|
await bot.wait_until_ready()
|
||||||
@ -198,9 +198,8 @@ async def post_boot_notice(bot):
|
|||||||
return
|
return
|
||||||
|
|
||||||
repo_url = r.get('repo_url', '') # SHAI_REPO_URL
|
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)
|
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)
|
headers = _auth_headers_from_cfg(r)
|
||||||
|
|
||||||
api_base = owner = repo = None
|
api_base = owner = repo = None
|
||||||
@ -248,8 +247,15 @@ async def post_boot_notice(bot):
|
|||||||
else:
|
else:
|
||||||
reason, ping_owner = ("scheduled" if _is_near_scheduled(now_utc, check_time_utc) else "manual"), False
|
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)
|
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:
|
try:
|
||||||
allowed = discord.AllowedMentions(
|
allowed = discord.AllowedMentions(
|
||||||
everyone=False,
|
everyone=False,
|
||||||
@ -264,14 +270,15 @@ async def post_boot_notice(bot):
|
|||||||
print(f"[boot_notice] failed to send status line: {e}")
|
print(f"[boot_notice] failed to send status line: {e}")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Post commit message (Version + md details)
|
# Only post commit message if version CHANGED (updated or rollback)
|
||||||
try:
|
if not append_version_only:
|
||||||
title = (curr_ver or subject or "Latest commit").strip()
|
try:
|
||||||
if title or body:
|
title = (curr_ver or subject or "Latest commit").strip()
|
||||||
commit_msg = f"**{title}**\n{body}" if body else f"**{title}**"
|
if title or body:
|
||||||
await ch.send(commit_msg, allowed_mentions=discord.AllowedMentions.none())
|
commit_msg = f"**{title}**\n{body}" if body else f"**{title}**"
|
||||||
except Exception as e:
|
await ch.send(commit_msg, allowed_mentions=discord.AllowedMentions.none())
|
||||||
print(f"[boot_notice] failed to send commit message: {e}")
|
except Exception as e:
|
||||||
|
print(f"[boot_notice] failed to send commit message: {e}")
|
||||||
|
|
||||||
# Persist state
|
# Persist state
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user