Skip to content

Commit 01d3330

Browse files
committed
Made git_pat field mandatory only for private repo.
1 parent 8790d0d commit 01d3330

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

aidp_migration/git_download_and_extract_to_aidp.ipynb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"\n",
2929
"**Note:** \n",
3030
"\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",
31+
"- 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",
32+
"- GIT_PAT is mandatory only for private repository.\n",
3233
"- Use with caution: Notebook is designed for downloading all files from repo and unarchive to provided workspace path.\n",
3334
"- This notebook should be executed from AIDP.\n",
3435
"- 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 @@
4950
"source": [
5051
"# Username of Github\n",
5152
"git_username = \"<GIT_USERNAME>\"\n",
52-
"# Access Token of Github\n",
53+
"# Access Token of Github, needed for Private Repository.\n",
5354
"git_pat = \"<GIT_PAT>\"\n",
5455
"# AIDP Workspace path to download repository\n",
5556
"aidp_path = \"<AIDP_WORKSPACE_PATH>\"\n",
5657
"# Github Repository Name\n",
5758
"git_repo_name = \"<GIT_REPO_NAME>\"\n",
5859
"# Github Branch Name\n",
59-
"git_branch = \"<GIT_BRANCH>\""
60+
"git_branch = \"<GIT_BRANCH>\"\n",
61+
"# Field 'is_private_repo' should be provided as a boolean (True/False).\n",
62+
"is_private_repo = \"<IS_PRIVATE_REPO>\""
6063
]
6164
},
6265
{
@@ -76,18 +79,19 @@
7679
"import zipfile\n",
7780
"import io\n",
7881
"\n",
79-
"if not git_pat:\n",
80-
" raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n",
81-
"\n",
8282
"zip_url = f\"https://api.github.com/repos/{git_username}/{git_repo_name}/zipball/{git_branch}\"\n",
8383
"\n",
8484
"try:\n",
85-
" # Headers for PAT authentication\n",
8685
" headers = {\n",
87-
" \"Authorization\": f\"token {git_pat}\",\n",
8886
" \"Accept\": \"application/vnd.github.v3+json\"\n",
8987
" }\n",
9088
"\n",
89+
" #Authorization requires only for Private Repo.\n",
90+
" if is_private_repo:\n",
91+
" if not git_pat:\n",
92+
" raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n",
93+
" headers[\"Authorization\"] = f\"token {git_pat}\"\n",
94+
" \n",
9195
" print(f\"Downloading ZIP from {zip_url}...\")\n",
9296
" response = requests.get(zip_url, headers=headers, stream=True)\n",
9397
" response.raise_for_status()\n",
@@ -105,7 +109,7 @@
105109
"except zipfile.BadZipFile:\n",
106110
" print(\"Downloaded file is not a valid ZIP file.\")\n",
107111
"except Exception as e:\n",
108-
" print(f\"An unexpected error occurred: {e}\")\n"
112+
" print(f\"An unexpected error occurred: {e}\")"
109113
]
110114
}
111115
],

0 commit comments

Comments
 (0)