github_action: Mention PR where the endpoints were added.

Updates "API Documentation Update Check" tool to  add PR
information in the message to chat.zulip.org when the
new endpoints are added.
This commit is contained in:
Vector73
2025-10-09 14:15:31 +00:00
committed by Tim Abbott
parent b8f8056f56
commit a5d25826bd
2 changed files with 25 additions and 9 deletions

View File

@@ -66,6 +66,8 @@ jobs:
- name: Run tools/notify-if-api-docs-changed
id: run_check
run: ./tools/notify-if-api-docs-changed >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Report status to CZO
if: ${{github.repository == 'zulip/zulip'}}

View File

@@ -1,8 +1,10 @@
#!/usr/bin/env python3
import json
import os
import re
import sys
from pathlib import Path
from urllib.request import Request, urlopen
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
os.chdir(os.path.dirname(TOOLS_DIR))
@@ -11,11 +13,26 @@ sys.path.insert(0, os.path.dirname(TOOLS_DIR))
from zerver.openapi.merge_api_changelogs import get_feature_level
def get_build_url_from_environment() -> str:
server = os.environ["GITHUB_SERVER_URL"]
def get_pull_request_number_or_commit_hash() -> str:
github_token = os.environ["GITHUB_TOKEN"]
repo = os.environ["GITHUB_REPOSITORY"]
run_id = os.environ["GITHUB_RUN_ID"]
return f"{server}/{repo}/actions/runs/{run_id}"
commit_hash = os.environ["GITHUB_SHA"]
url = f"https://api.github.com/repos/{repo}/commits/{commit_hash}/pulls"
headers = {
"Accept": "application/vnd.github.groot-preview+json",
"Authorization": f"token {github_token}",
}
try:
req = Request(url, headers=headers)
with urlopen(req) as response:
pull_requests = json.load(response)
if len(pull_requests) > 0:
return f"#{pull_requests[0]['number']}"
return commit_hash
except Exception:
return commit_hash
def get_changed_api_endpoints() -> list[str]:
@@ -41,15 +58,12 @@ def get_changed_api_endpoints() -> list[str]:
if __name__ == "__main__":
branch = os.environ.get("GITHUB_REF", "unknown branch").split("/")[-1]
topic = f"{branch} failing"
build_url = get_build_url_from_environment()
github_actor = os.environ.get("GITHUB_ACTOR", "unknown user")
pull_request = get_pull_request_number_or_commit_hash()
feature_level = get_feature_level(update_feature_level=False)
endpoints = get_changed_api_endpoints()
topic = f"new feature level: {feature_level}"
endpoints_string = ", ".join(endpoints)
content = f"[Build]({build_url}) triggered by {github_actor} on branch `{branch}` has updated the API documentation for the following endpoints: {endpoints_string}."
content = f"{pull_request} has updated the API documentation for the following endpoints: {endpoints_string}."
print(f"topic={topic}\ncontent={content}")