Add state to Kojo display
This commit is contained in:
@@ -76,6 +76,7 @@ for org in GITEA_ORGS:
|
||||
"chat_url": os.getenv("GITEA_CHAT_URL")
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------
|
||||
# Logging configuration
|
||||
# ---------------------------
|
||||
@@ -223,14 +224,31 @@ def extract_koji_changelog(link, host):
|
||||
try:
|
||||
r = requests.get(link, headers={"Host": host}, timeout=10)
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
|
||||
# Extract changelog text
|
||||
td = soup.find("td", class_="changelog")
|
||||
if not td:
|
||||
return ""
|
||||
lines = [ln.strip() for ln in td.get_text().splitlines() if ln.strip()]
|
||||
return "\n".join(lines[:5])
|
||||
changelog_text = ""
|
||||
else:
|
||||
lines = [ln.strip() for ln in td.get_text().splitlines() if ln.strip()]
|
||||
changelog_text = "\n".join(lines[:5])
|
||||
|
||||
# Extract State message by checking <tr> rows
|
||||
state_message = ""
|
||||
for tr in soup.find_all("tr"):
|
||||
th = tr.find("th")
|
||||
if th and th.get_text(strip=True) == "State":
|
||||
td_state = tr.find("td")
|
||||
if td_state:
|
||||
# The message is the text in <td>, the class indicates the status
|
||||
state_message = td_state.get_text(strip=True)
|
||||
break
|
||||
|
||||
return changelog_text, state_message
|
||||
|
||||
except Exception as e:
|
||||
logging.warning("Koji changelog fetch failed: %s", e)
|
||||
return ""
|
||||
return "", ""
|
||||
|
||||
def process_koji(conf, one_shot, domain_cache):
|
||||
domain = conf["domain"]
|
||||
@@ -243,8 +261,8 @@ def process_koji(conf, one_shot, domain_cache):
|
||||
build_id = title.split(":")[1].split(",")[0].strip() if ":" in title else entry.id
|
||||
if not has_been_sent("koji", build_id):
|
||||
link = entry.link #.replace(domain, domain_cache[domain])
|
||||
changelog = extract_koji_changelog(link, domain)
|
||||
text = f"Build Notification - ID: {build_id}\n{changelog}"
|
||||
changelog,state = extract_koji_changelog(link, domain)
|
||||
text = f"*Build Notification - ID*: {build_id}\n*State*:{state}\n{changelog}"
|
||||
send_to_rocket_chat("Koji", text, [{"title": title, "title_link": entry.link, "color": "#764FA5"}], conf["chat_url"])
|
||||
mark_as_sent("koji", build_id)
|
||||
|
||||
@@ -1164,19 +1182,30 @@ def main():
|
||||
parser.add_argument("--log-level", type=str, default="INFO", help="Logging level")
|
||||
parser.add_argument("--selftest-gitea", action="store_true",
|
||||
help="Run built-in Gitea parser selftest using the embedded sample Atom (no network, no send)")
|
||||
parser.add_argument("--test-channel",action="store_false",help="Switch all the channels to post in brians test channel")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
log_path = init_logging(args.log_level)
|
||||
logging.info("FeedToRocket starting (log: %s)", log_path)
|
||||
|
||||
logging.debug("Loaded feeds: %s", FEED_CONFIG)
|
||||
|
||||
if args.selftest_gitea:
|
||||
logging.info("Running Gitea selftest against embedded sample Atom…")
|
||||
selftest_gitea_sample(org_name="smeserver", log_level=args.log_level)
|
||||
return
|
||||
|
||||
if args.test_channel:
|
||||
logging.info("Running all messages to test channels")
|
||||
test_url = os.getenv("TEST_CHAT_URL")
|
||||
if not test_url:
|
||||
raise RuntimeError("TEST_CHAT_URL is not set in the environment")
|
||||
|
||||
for cfg in FEED_CONFIG.values():
|
||||
if isinstance(cfg, dict) and "chat_url" in cfg:
|
||||
cfg["chat_url"] = test_url
|
||||
|
||||
logging.debug("Loaded feeds: %s", FEED_CONFIG)
|
||||
#quit(1)
|
||||
|
||||
setup_database()
|
||||
if args.empty_db:
|
||||
|
||||
Reference in New Issue
Block a user