Switch ATVM watcher status posts to MS Teams
This commit is contained in:
@@ -1627,16 +1627,37 @@ def build_status_markdown(
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def post_to_mattermost(text: str) -> str:
|
||||
webhook = os.environ["MATTERMOST_ATVM_WEBHOOK"]
|
||||
payload = {"text": text}
|
||||
channel = os.environ.get("MATTERMOST_ATVM_CHANNEL")
|
||||
def post_to_teams(text: str) -> str:
|
||||
webhook = os.environ["MS_TEAMS_ATVM_WEBHOOK"]
|
||||
payload = {
|
||||
"type": "message",
|
||||
"attachments": [
|
||||
{
|
||||
"contentType": "application/vnd.microsoft.card.adaptive",
|
||||
"contentUrl": None,
|
||||
"content": {
|
||||
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
|
||||
"type": "AdaptiveCard",
|
||||
"version": "1.4",
|
||||
"body": [
|
||||
{
|
||||
"type": "TextBlock",
|
||||
"text": text,
|
||||
"wrap": True,
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
channel = os.environ.get("MS_TEAMS_ATVM_CHANNEL")
|
||||
if channel:
|
||||
payload["channel"] = channel
|
||||
data = json.dumps(payload).encode()
|
||||
request = urllib.request.Request(webhook, data=data, headers={"Content-Type": "application/json"})
|
||||
with urllib.request.urlopen(request) as response:
|
||||
return response.read().decode().strip()
|
||||
body = response.read().decode().strip()
|
||||
return f"HTTP {response.status}" + (f": {body}" if body else "")
|
||||
|
||||
|
||||
def sanitize_key(raw: str) -> str:
|
||||
@@ -2334,13 +2355,11 @@ if __name__ == "__main__":
|
||||
log_text=current_log_text,
|
||||
)
|
||||
print(status_text)
|
||||
response = post_to_mattermost(status_text)
|
||||
if response != "ok":
|
||||
raise SystemExit(f"Mattermost webhook did not return ok for {subrun['display_name']}: {response!r}")
|
||||
subrun_posted_marker.write_text("ok\n", encoding="utf-8")
|
||||
subrun_state["mattermost_posted"] = True
|
||||
subrun_state["mattermost_response"] = response
|
||||
print(f"[watcher] Mattermost post confirmed for {subrun['display_name']}.")
|
||||
response = post_to_teams(status_text)
|
||||
subrun_posted_marker.write_text(f"{response}\n", encoding="utf-8")
|
||||
subrun_state["teams_posted"] = True
|
||||
subrun_state["teams_response"] = response
|
||||
print(f"[watcher] Teams post confirmed for {subrun['display_name']}: {response}.")
|
||||
write_state(subrun_state_file, subrun_state)
|
||||
|
||||
if run_state == "RUNNING":
|
||||
@@ -2363,14 +2382,12 @@ if __name__ == "__main__":
|
||||
print(status_text)
|
||||
|
||||
if not metadata.get("categorized") and run_state in {"COMPLETED", "FAILED"} and not posted_marker.exists():
|
||||
response = post_to_mattermost(status_text)
|
||||
if response != "ok":
|
||||
raise SystemExit(f"Mattermost webhook did not return ok: {response!r}")
|
||||
posted_marker.write_text("ok\n", encoding="utf-8")
|
||||
state["mattermost_posted"] = True
|
||||
state["mattermost_response"] = response
|
||||
response = post_to_teams(status_text)
|
||||
posted_marker.write_text(f"{response}\n", encoding="utf-8")
|
||||
state["teams_posted"] = True
|
||||
state["teams_response"] = response
|
||||
write_state(state_file, state)
|
||||
print(f"[watcher] Mattermost post confirmed for {build_name}.")
|
||||
print(f"[watcher] Teams post confirmed for {build_name}: {response}.")
|
||||
|
||||
state["closed_at"] = now_utc().isoformat()
|
||||
write_state(state_file, state)
|
||||
|
||||
Reference in New Issue
Block a user