Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions aidp_migration/git_download_and_extract_to_aidp.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"cells": [
{
"cell_type": "markdown",
"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/"
]
},
{
"cell_type": "markdown",
"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., `<GIT_USERNAME>`, `<GIT_PAT>`, `<AIDP_WORKSPACE_PATH>`, `<GIT_REPO_NAME>`, `<GIT_BRANCH>`, `<IS_PRIVATE_REPO>` 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."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "065a7b5a-727d-4297-a502-e92c074f626f",
"metadata": {
"execution": {
"iopub.status.busy": "2025-11-04T14:37:15.709Z"
},
"trusted": true,
"type": "python"
},
"outputs": [],
"source": [
"# Username of Github\n",
"git_username = \"<GIT_USERNAME>\"\n",
"# Access Token of Github, needed for Private Repository.\n",
"git_pat = \"<GIT_PAT>\"\n",
"# AIDP Workspace path to download repository\n",
"aidp_path = \"<AIDP_WORKSPACE_PATH>\"\n",
"# Github Repository Name\n",
"git_repo_name = \"<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 = \"<IS_PRIVATE_REPO>\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d730a44f-6582-40eb-8c72-f88519b01e23",
"metadata": {
"execution": {
"iopub.status.busy": "2025-11-04T14:37:29.146Z"
},
"trusted": true,
"type": "python"
},
"outputs": [],
"source": [
"import requests\n",
"import zipfile\n",
"import io\n",
"\n",
"zip_url = f\"https://api.github.com/repos/{git_username}/{git_repo_name}/zipball/{git_branch}\"\n",
"\n",
"try:\n",
" headers = {\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",
"\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}\")"
]
}
],
"metadata": {
"Last_Active_Cell_Index": 2,
"kernelspec": {
"display_name": "python3",
"name": "notebook"
},
"language_info": {
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}