You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/"
15
+
]
24
16
},
25
17
{
26
-
"id": "f2356308-64bd-4fcb-ae88-5869a227eb2a",
27
18
"cell_type": "markdown",
28
-
"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., `<GIT_USERNAME>`, `<GIT_PAT>`, `<AIDP_WORKSPACE_PATH>`, `<GIT_REPO_NAME>`, `<GIT_BRANCH>` 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.",
19
+
"id": "f2356308-64bd-4fcb-ae88-5869a227eb2a",
29
20
"metadata": {
30
21
"type": "markdown"
31
-
}
22
+
},
23
+
"source": [
24
+
"### Sample Code: Downloading Notebooks/Files from Git.\n",
25
+
"\n",
26
+
"This example demonstrates how to download notebook/files from Git as ZIP and extract them to AIDP Workspace. It uses requests python library.\n",
27
+
"\n",
28
+
"\n",
29
+
"**Note:** \n",
30
+
"\n",
31
+
"- Replace all placeholders (e.g., `<GIT_USERNAME>`, `<GIT_PAT>`, `<AIDP_WORKSPACE_PATH>`, `<GIT_REPO_NAME>`, `<GIT_BRANCH>` etc.) with values specific to your environment before running the notebook. \n",
32
+
"- Use with caution: Notebook is designed for downloading all files from repo and unarchive to provided workspace path.\n",
"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",
63
+
"execution_count": null,
64
+
"id": "d730a44f-6582-40eb-8c72-f88519b01e23",
51
65
"metadata": {
52
66
"execution": {
53
67
"iopub.status.busy": "2025-11-04T14:37:29.146Z"
54
68
},
55
-
"type": "python",
56
-
"trusted": true
69
+
"trusted": true,
70
+
"type": "python"
57
71
},
58
-
"outputs": [
59
-
{
60
-
"data": {
61
-
"text/plain": "Downloading ZIP from https://api.github.com/repos/nishgit/git-sdk-test/zipball/main...\n"
62
-
},
63
-
"metadata": {},
64
-
"output_type": "display_data"
65
-
},
66
-
{
67
-
"data": {
68
-
"text/plain": "Repository downloaded and extracted successfully.\n"
69
-
},
70
-
"metadata": {},
71
-
"output_type": "display_data"
72
-
}
73
-
],
74
-
"execution_count": 1
72
+
"outputs": [],
73
+
"source": [
74
+
"import requests\n",
75
+
"import zipfile\n",
76
+
"import io\n",
77
+
"\n",
78
+
"if not git_pat:\n",
79
+
" raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n",
0 commit comments