From 6e5462b474bef564ef7545015470ebbda0b1b2f7 Mon Sep 17 00:00:00 2001 From: John Andersen Date: Tue, 2 Jan 2024 16:48:29 -0800 Subject: [PATCH] ci: alice async comms: Dump Engineering Log Entries --- .github/workflows/alice_async_comms.yml | 24 +++++++++++++++++++++++- scripts/discussion_dump_to_markdown.py | 2 -- scripts/dump_discussion.py | 6 ++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/alice_async_comms.yml b/.github/workflows/alice_async_comms.yml index 108dce0548..8d2169485a 100644 --- a/.github/workflows/alice_async_comms.yml +++ b/.github/workflows/alice_async_comms.yml @@ -7,6 +7,7 @@ name: "Alice: Async Comms" # - https://github.com/Textualize/rich/blob/84e628655a2981ee90413ca3f35001ec3954161d/.github/workflows/readmechanged.yml#L1-L24 (MIT) on: + workflow_dispatch: null schedule: - cron: '0 6 * * *' @@ -20,8 +21,29 @@ jobs: uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1 with: egress-policy: audit - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Dump engineering log entries + id: dump-logs + env: + GH_TOKEN: ${{ github.token }} + TITLE: "docs: discussions: Alice Engineering Comms" + DISCUSSION_NUMBER: 1406 + run: | + set -xeuo pipefail + + python -m pip install -U pip setuptools wheel + python -m pip install aiohttp + python -u scripts/dump_discussion.py --token "$GH_TOKEN" --owner $(echo $GITHUB_REPOSITORY | sed -e 's/\/.*//g') --repo $(echo $GITHUB_REPOSITORY | sed -e 's/.*\///g') --discussion-number $DISCUSSION_NUMBER | tee /dev/stderr | sed -e 's/\/tree\/alice/\/tree\/main/g' -e 's/\/blob\/alice/\/blob\/main/g' | python -u scripts/discussion_dump_to_markdown.py + echo "msg=$TITLE: $(date -Iseconds)" >> $GITHUB_OUTPUT + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5.0.2 + with: + commit-message: ${{ steps.dump-logs.outputs.msg }} + title: ${{ steps.dump-logs.outputs.msg }} + branch: chore-docs-alice-comms + delete-branch: true + author: 'Alice OA ' + add-paths: docs - name: Post engineering log entry env: GITHUB_TOKEN: ${{ github.token }} diff --git a/scripts/discussion_dump_to_markdown.py b/scripts/discussion_dump_to_markdown.py index 3a5d2ed70d..108c0a8dd3 100644 --- a/scripts/discussion_dump_to_markdown.py +++ b/scripts/discussion_dump_to_markdown.py @@ -107,8 +107,6 @@ import tempfile from typing import Callable, Type, Union, NewType, Dict -import dffml - sys.path.append(str(pathlib.Path(__file__).parent.resolve())) from dump_discussion import Reply, Comment, Discussion diff --git a/scripts/dump_discussion.py b/scripts/dump_discussion.py index 9a0a333082..98de3eb069 100644 --- a/scripts/dump_discussion.py +++ b/scripts/dump_discussion.py @@ -79,6 +79,9 @@ async def fetch_discussion_data(session, token, owner, repo, discussion_number): response = await session.post("https://api.github.com/graphql", headers=headers, json={"query": query, "variables": variables}) result = await response.json() + if "data" not in result: + raise Exception(json.dumps(result, indent=4, sort_keys=True)) + discussion_title = result["data"]["repository"]["discussion"]["title"] discussion_body = result["data"]["repository"]["discussion"]["body"] comments = result["data"]["repository"]["discussion"]["comments"]["nodes"] @@ -97,6 +100,9 @@ async def fetch_discussion_data(session, token, owner, repo, discussion_number): response = await session.post("https://api.github.com/graphql", headers=headers, json={"query": query, "variables": variables}) reply_result = await response.json() + if "replies" not in reply_result: + raise Exception(json.dumps(reply_result, indent=4, sort_keys=True)) + reply_nodes = comment["replies"]["nodes"] has_next_reply_page = comment["replies"]["pageInfo"]["hasNextPage"] replies_cursor = comment["replies"]["pageInfo"]["endCursor"]