From 702dce105e6e10922a977168d7b3894756364630 Mon Sep 17 00:00:00 2001 From: Nishant Patel Date: Tue, 4 Nov 2025 20:17:50 +0530 Subject: [PATCH 1/4] Utility for Downloading repository as zip and extracting them to AIDP workspace. --- .../git_download_and_extract_to_aidp.ipynb | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 aidp_migration/git_download_and_extract_to_aidp.ipynb diff --git a/aidp_migration/git_download_and_extract_to_aidp.ipynb b/aidp_migration/git_download_and_extract_to_aidp.ipynb new file mode 100644 index 0000000..2a2d268 --- /dev/null +++ b/aidp_migration/git_download_and_extract_to_aidp.ipynb @@ -0,0 +1,77 @@ +{ + "metadata": { + "kernelspec": { + "display_name": "python3", + "name": "notebook" + }, + "language_info": { + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python" + }, + "Last_Active_Cell_Index": 2 + }, + "nbformat_minor": 5, + "nbformat": 4, + "cells": [ + { + "id": "80e69eae-cd44-4046-9f24-4cde652dbc0f", + "cell_type": "markdown", + "source": "Oracle AI Data Platform v1.0\n\nCopyright © 2025, Oracle and/or its affiliates.\n\nLicensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/", + "metadata": { + "type": "markdown" + } + }, + { + "id": "f2356308-64bd-4fcb-ae88-5869a227eb2a", + "cell_type": "markdown", + "source": "### Sample Code: Downloading Notebooks/Files from Git.\n\nThis example demonstrates how to download notebook/files from Git as ZIP and extract them to AIDP Workspace. It uses requests python library.\n\n\n**Note:** \n\n- Replace all placeholders (e.g., ``, ``, ``, ``, `` etc.) with values specific to your environment before running the notebook. \n- Use with caution: Notebook is designed for downloading all files from repo and unarchive to provided workspace path.\n- This notebook should be executed from AIDP.", + "metadata": { + "type": "markdown" + } + }, + { + "id": "065a7b5a-727d-4297-a502-e92c074f626f", + "cell_type": "code", + "source": "# Username of Github\ngit_username = \"\"\n# Access Token of Github\ngit_pat = \"\"\n# AIDP Workspace path to download repository\naidp_path = \"\"\n# Github Repository Name\ngit_repo_name = \"\"\n# Github Branch Name\ngit_branch = \"\"", + "metadata": { + "execution": { + "iopub.status.busy": "2025-11-04T14:37:15.709Z" + }, + "type": "python", + "trusted": true + }, + "outputs": [], + "execution_count": 1 + }, + { + "id": "d730a44f-6582-40eb-8c72-f88519b01e23", + "cell_type": "code", + "source": "import requests\nimport zipfile\nimport io\nimport os\n\nif not git_pat:\n raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n\nzip_url = f\"https://api.github.com/repos/{git_username}/{git_repo_name}/zipball/{git_branch}\"\n\ntry:\n # Headers for PAT authentication\n headers = {\n \"Authorization\": f\"token {git_pat}\",\n \"Accept\": \"application/vnd.github.v3+json\"\n }\n\n print(f\"Downloading ZIP from {zip_url}...\")\n response = requests.get(zip_url, headers=headers, stream=True)\n response.raise_for_status()\n\n # Extract the ZIP content\n with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:\n \n top_level_folder = os.path.commonprefix(zip_ref.namelist())\n # Extract all files\n zip_ref.extractall(aidp_path)\n print(\"Repository downloaded and extracted successfully.\")\n\nexcept requests.exceptions.RequestException as e:\n print(f\"Error downloading repository: {e}\")\nexcept zipfile.BadZipFile:\n print(\"Downloaded file is not a valid ZIP file.\")\nexcept Exception as e:\n print(f\"An unexpected error occurred: {e}\")\n", + "metadata": { + "execution": { + "iopub.status.busy": "2025-11-04T14:37:29.146Z" + }, + "type": "python", + "trusted": true + }, + "outputs": [ + { + "data": { + "text/plain": "Downloading ZIP from https://api.github.com/repos/nishgit/git-sdk-test/zipball/main...\n" + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": "Repository downloaded and extracted successfully.\n" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "execution_count": 1 + } + ] +} \ No newline at end of file From 43bc62c5f4de60de1d9ec340e10af432bbf4f4f0 Mon Sep 17 00:00:00 2001 From: Nishant Patel Date: Tue, 4 Nov 2025 22:39:14 +0530 Subject: [PATCH 2/4] unused import removed. --- .../git_download_and_extract_to_aidp.ipynb | 144 ++++++++++++------ 1 file changed, 96 insertions(+), 48 deletions(-) diff --git a/aidp_migration/git_download_and_extract_to_aidp.ipynb b/aidp_migration/git_download_and_extract_to_aidp.ipynb index 2a2d268..368462d 100644 --- a/aidp_migration/git_download_and_extract_to_aidp.ipynb +++ b/aidp_migration/git_download_and_extract_to_aidp.ipynb @@ -1,77 +1,125 @@ { - "metadata": { - "kernelspec": { - "display_name": "python3", - "name": "notebook" - }, - "language_info": { - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python" - }, - "Last_Active_Cell_Index": 2 - }, - "nbformat_minor": 5, - "nbformat": 4, "cells": [ { - "id": "80e69eae-cd44-4046-9f24-4cde652dbc0f", "cell_type": "markdown", - "source": "Oracle AI Data Platform v1.0\n\nCopyright © 2025, Oracle and/or its affiliates.\n\nLicensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/", + "id": "80e69eae-cd44-4046-9f24-4cde652dbc0f", "metadata": { "type": "markdown" - } + }, + "source": [ + "Oracle AI Data Platform v1.0\n", + "\n", + "Copyright © 2025, Oracle and/or its affiliates.\n", + "\n", + "Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/" + ] }, { - "id": "f2356308-64bd-4fcb-ae88-5869a227eb2a", "cell_type": "markdown", - "source": "### Sample Code: Downloading Notebooks/Files from Git.\n\nThis example demonstrates how to download notebook/files from Git as ZIP and extract them to AIDP Workspace. It uses requests python library.\n\n\n**Note:** \n\n- Replace all placeholders (e.g., ``, ``, ``, ``, `` etc.) with values specific to your environment before running the notebook. \n- Use with caution: Notebook is designed for downloading all files from repo and unarchive to provided workspace path.\n- This notebook should be executed from AIDP.", + "id": "f2356308-64bd-4fcb-ae88-5869a227eb2a", "metadata": { "type": "markdown" - } + }, + "source": [ + "### Sample Code: Downloading Notebooks/Files from Git.\n", + "\n", + "This example demonstrates how to download notebook/files from Git as ZIP and extract them to AIDP Workspace. It uses requests python library.\n", + "\n", + "\n", + "**Note:** \n", + "\n", + "- Replace all placeholders (e.g., ``, ``, ``, ``, `` etc.) with values specific to your environment before running the notebook. \n", + "- Use with caution: Notebook is designed for downloading all files from repo and unarchive to provided workspace path.\n", + "- This notebook should be executed from AIDP." + ] }, { - "id": "065a7b5a-727d-4297-a502-e92c074f626f", "cell_type": "code", - "source": "# Username of Github\ngit_username = \"\"\n# Access Token of Github\ngit_pat = \"\"\n# AIDP Workspace path to download repository\naidp_path = \"\"\n# Github Repository Name\ngit_repo_name = \"\"\n# Github Branch Name\ngit_branch = \"\"", + "execution_count": null, + "id": "065a7b5a-727d-4297-a502-e92c074f626f", "metadata": { "execution": { "iopub.status.busy": "2025-11-04T14:37:15.709Z" }, - "type": "python", - "trusted": true + "trusted": true, + "type": "python" }, "outputs": [], - "execution_count": 1 + "source": [ + "# Username of Github\n", + "git_username = \"\"\n", + "# Access Token of Github\n", + "git_pat = \"\"\n", + "# AIDP Workspace path to download repository\n", + "aidp_path = \"\"\n", + "# Github Repository Name\n", + "git_repo_name = \"\"\n", + "# Github Branch Name\n", + "git_branch = \"\"" + ] }, { - "id": "d730a44f-6582-40eb-8c72-f88519b01e23", "cell_type": "code", - "source": "import requests\nimport zipfile\nimport io\nimport os\n\nif not git_pat:\n raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n\nzip_url = f\"https://api.github.com/repos/{git_username}/{git_repo_name}/zipball/{git_branch}\"\n\ntry:\n # Headers for PAT authentication\n headers = {\n \"Authorization\": f\"token {git_pat}\",\n \"Accept\": \"application/vnd.github.v3+json\"\n }\n\n print(f\"Downloading ZIP from {zip_url}...\")\n response = requests.get(zip_url, headers=headers, stream=True)\n response.raise_for_status()\n\n # Extract the ZIP content\n with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:\n \n top_level_folder = os.path.commonprefix(zip_ref.namelist())\n # Extract all files\n zip_ref.extractall(aidp_path)\n print(\"Repository downloaded and extracted successfully.\")\n\nexcept requests.exceptions.RequestException as e:\n print(f\"Error downloading repository: {e}\")\nexcept zipfile.BadZipFile:\n print(\"Downloaded file is not a valid ZIP file.\")\nexcept Exception as e:\n print(f\"An unexpected error occurred: {e}\")\n", + "execution_count": null, + "id": "d730a44f-6582-40eb-8c72-f88519b01e23", "metadata": { "execution": { "iopub.status.busy": "2025-11-04T14:37:29.146Z" }, - "type": "python", - "trusted": true + "trusted": true, + "type": "python" }, - "outputs": [ - { - "data": { - "text/plain": "Downloading ZIP from https://api.github.com/repos/nishgit/git-sdk-test/zipball/main...\n" - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": "Repository downloaded and extracted successfully.\n" - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "execution_count": 1 + "outputs": [], + "source": [ + "import requests\n", + "import zipfile\n", + "import io\n", + "\n", + "if not git_pat:\n", + " raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n", + "\n", + "zip_url = f\"https://api.github.com/repos/{git_username}/{git_repo_name}/zipball/{git_branch}\"\n", + "\n", + "try:\n", + " # Headers for PAT authentication\n", + " headers = {\n", + " \"Authorization\": f\"token {git_pat}\",\n", + " \"Accept\": \"application/vnd.github.v3+json\"\n", + " }\n", + "\n", + " print(f\"Downloading ZIP from {zip_url}...\")\n", + " response = requests.get(zip_url, headers=headers, stream=True)\n", + " response.raise_for_status()\n", + "\n", + " # Extract the ZIP content\n", + " with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:\n", + " \n", + " top_level_folder = os.path.commonprefix(zip_ref.namelist())\n", + " # Extract all files\n", + " zip_ref.extractall(aidp_path)\n", + " print(\"Repository downloaded and extracted successfully.\")\n", + "\n", + "except requests.exceptions.RequestException as e:\n", + " print(f\"Error downloading repository: {e}\")\n", + "except zipfile.BadZipFile:\n", + " print(\"Downloaded file is not a valid ZIP file.\")\n", + "except Exception as e:\n", + " print(f\"An unexpected error occurred: {e}\")\n" + ] + } + ], + "metadata": { + "Last_Active_Cell_Index": 2, + "kernelspec": { + "display_name": "python3", + "name": "notebook" + }, + "language_info": { + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python" } - ] -} \ No newline at end of file + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 8790d0d88b4fa280a46e37786d7e77168f3972cd Mon Sep 17 00:00:00 2001 From: Nishant Patel Date: Thu, 6 Nov 2025 22:08:40 +0530 Subject: [PATCH 3/4] Updated doc comment to keep token secret. --- aidp_migration/git_download_and_extract_to_aidp.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aidp_migration/git_download_and_extract_to_aidp.ipynb b/aidp_migration/git_download_and_extract_to_aidp.ipynb index 368462d..548e453 100644 --- a/aidp_migration/git_download_and_extract_to_aidp.ipynb +++ b/aidp_migration/git_download_and_extract_to_aidp.ipynb @@ -30,7 +30,8 @@ "\n", "- Replace all placeholders (e.g., ``, ``, ``, ``, `` etc.) with values specific to your environment before running the notebook. \n", "- Use with caution: Notebook is designed for downloading all files from repo and unarchive to provided workspace path.\n", - "- This notebook should be executed from AIDP." + "- This notebook should be executed from AIDP.\n", + "- Hardcoding Git token into the notebook leaves credentials vulnerable. It is strongly advised to manage the token securely by loading it dynamically from an environment variable, a secure configuration file, or a OCI Vault." ] }, { From 01d333050c71efe8e52b2c25a3dd7c2ce984ab0b Mon Sep 17 00:00:00 2001 From: Nishant Patel Date: Fri, 7 Nov 2025 11:44:18 +0530 Subject: [PATCH 4/4] Made git_pat field mandatory only for private repo. --- .../git_download_and_extract_to_aidp.ipynb | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/aidp_migration/git_download_and_extract_to_aidp.ipynb b/aidp_migration/git_download_and_extract_to_aidp.ipynb index 548e453..9aed3b8 100644 --- a/aidp_migration/git_download_and_extract_to_aidp.ipynb +++ b/aidp_migration/git_download_and_extract_to_aidp.ipynb @@ -28,7 +28,8 @@ "\n", "**Note:** \n", "\n", - "- Replace all placeholders (e.g., ``, ``, ``, ``, `` etc.) with values specific to your environment before running the notebook. \n", + "- Replace all placeholders (e.g., ``, ``, ``, ``, ``, `` etc.) with values specific to your environment before running the notebook. \n", + "- GIT_PAT is mandatory only for private repository.\n", "- Use with caution: Notebook is designed for downloading all files from repo and unarchive to provided workspace path.\n", "- This notebook should be executed from AIDP.\n", "- Hardcoding Git token into the notebook leaves credentials vulnerable. It is strongly advised to manage the token securely by loading it dynamically from an environment variable, a secure configuration file, or a OCI Vault." @@ -49,14 +50,16 @@ "source": [ "# Username of Github\n", "git_username = \"\"\n", - "# Access Token of Github\n", + "# Access Token of Github, needed for Private Repository.\n", "git_pat = \"\"\n", "# AIDP Workspace path to download repository\n", "aidp_path = \"\"\n", "# Github Repository Name\n", "git_repo_name = \"\"\n", "# Github Branch Name\n", - "git_branch = \"\"" + "git_branch = \"\"\n", + "# Field 'is_private_repo' should be provided as a boolean (True/False).\n", + "is_private_repo = \"\"" ] }, { @@ -76,18 +79,19 @@ "import zipfile\n", "import io\n", "\n", - "if not git_pat:\n", - " raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n", - "\n", "zip_url = f\"https://api.github.com/repos/{git_username}/{git_repo_name}/zipball/{git_branch}\"\n", "\n", "try:\n", - " # Headers for PAT authentication\n", " headers = {\n", - " \"Authorization\": f\"token {git_pat}\",\n", " \"Accept\": \"application/vnd.github.v3+json\"\n", " }\n", "\n", + " #Authorization requires only for Private Repo.\n", + " if is_private_repo:\n", + " if not git_pat:\n", + " raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n", + " headers[\"Authorization\"] = f\"token {git_pat}\"\n", + " \n", " print(f\"Downloading ZIP from {zip_url}...\")\n", " response = requests.get(zip_url, headers=headers, stream=True)\n", " response.raise_for_status()\n", @@ -105,7 +109,7 @@ "except zipfile.BadZipFile:\n", " print(\"Downloaded file is not a valid ZIP file.\")\n", "except Exception as e:\n", - " print(f\"An unexpected error occurred: {e}\")\n" + " print(f\"An unexpected error occurred: {e}\")" ] } ],