From b9d9bae06ec8a1e4f32655299199d9272631a130 Mon Sep 17 00:00:00 2001 From: Sai Medhini Reddy Maryada <117196660+saimedhi@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:23:44 -0800 Subject: [PATCH] Adding changelog update in API generator (#669) * Update changelog with api generator Signed-off-by: saimedhi * Update changelog with api generator Signed-off-by: saimedhi --------- Signed-off-by: saimedhi --- .github/workflows/update_api.yml | 6 ------ CHANGELOG.md | 3 +-- utils/generate_api.py | 27 +++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/.github/workflows/update_api.yml b/.github/workflows/update_api.yml index 3b8b8d7f..d03b9eaa 100644 --- a/.github/workflows/update_api.yml +++ b/.github/workflows/update_api.yml @@ -26,12 +26,6 @@ jobs: python3.7 -m pip install nox - name: Generate API run: nox -s generate - - name: Update CHANGELOG - uses: jacobtomlinson/gha-find-replace@v3 - with: - find: "- Your contribution here." - replace: "- Updated opensearch-py to reflect the latest OpenSearch API spec.\n- Your contribution here." - include: "**CHANGELOG.md" - name: Get current date id: date run: echo "::set-output name=date::$(date +'%Y-%m-%d')" diff --git a/CHANGELOG.md b/CHANGELOG.md index a33fc503..d1aa1581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,8 +22,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - Fix KeyError when scroll return no hits ([#616](https://github.com/opensearch-project/opensearch-py/pull/616)) - Fix reuse of `OpenSearch` using `Urllib3HttpConnection` and `AsyncOpenSearch` after calling `close` ([#639](https://github.com/opensearch-project/opensearch-py/pull/639)) -### Automated API Update -- Your contribution here. +### Updated APIs ### Security ### Dependencies - Bumps `pytest-asyncio` from <=0.21.1 to <=0.23.4 diff --git a/utils/generate_api.py b/utils/generate_api.py index 475782e3..88a52028 100644 --- a/utils/generate_api.py +++ b/utils/generate_api.py @@ -764,6 +764,33 @@ def dump_modules(modules: Any) -> None: unasync.unasync_files(filepaths, rules) blacken(CODE_ROOT / "opensearchpy") + # Updating the CHANGELOG.md + response = requests.get( + "https://api.github.com/repos/opensearch-project/opensearch-api-specification/commits" + ) + if response.ok: + commit_info = response.json()[0] + commit_url = commit_info["html_url"] + latest_commit_sha = commit_info.get("sha") + else: + raise Exception( + f"Failed to fetch opensearch-api-specification commit information. Status code: {response.status_code}" + ) + + with open("CHANGELOG.md", "r+", encoding="utf-8") as file: + content = file.read() + if "### Updated APIs" in content: + file_content = content.replace( + "### Updated APIs", + f"### Updated APIs\n- Updated opensearch-py APIs to reflect [opensearch-api-specification@{latest_commit_sha[:7]}]({commit_url})", + 1, + ) + file.seek(0) + file.write(file_content) + file.truncate() + else: + raise Exception("'Updated APIs' section is not present in CHANGELOG.md") + if __name__ == "__main__": dump_modules(read_modules())