Skip to content

Commit 6ae7316

Browse files
committed
Added more validation checks
1 parent 82ee4e3 commit 6ae7316

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

management_instance/runbooks/shared_scripts/fork_repo_github.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,31 @@ def ensure_git_exists():
273273
git_executable = ensure_git_exists()
274274
parser, _ = init_argparse()
275275

276+
if not parser.github_access_token.strip() and not (parser.github_app_id.strip() and parser.github_app_private_key.strip() and parser.github_app_installation_id.strip()):
277+
print("You must supply the GitHub token, or the GitHub App ID and private key and installation ID")
278+
sys.exit(1)
279+
280+
if not parser.template_repo_name.strip():
281+
print("You must supply the upstream (or template) repo")
282+
sys.exit(1)
283+
284+
if not parser.tenant_name.strip() and not parser.new_repo_name_prefix.strip():
285+
print("You must define the new repo prefix or run this script against a tenant")
286+
sys.exit(1)
287+
276288
# The access token is generated from a github app or supplied directly as an access token
277289
token = generate_github_token(parser.github_app_id, parser.github_app_private_key,
278290
parser.github_app_installation_id) if len(
279291
parser.github_access_token.strip()) == 0 else parser.github_access_token.strip()
292+
293+
# The process followed here is:
294+
# 1. Verify the manually supplied upstream repo exists
295+
# 2. Build the name of the new downstream repo with a prefix and the new project name.
296+
# a. The prefix is either specified or assumed to be the name of a tenant
297+
# b. The new project name is either specified or assumed to be the same as the upstream project name
298+
# 3. Create a new downstream repo if it doesn't exist
299+
# 4. Fork the upstream repo into the downstream repo with a hard git reset
300+
280301
cac_org = parser.git_organization.strip()
281302
template_repo = parser.template_repo_name.strip()
282303
new_repo_custom_prefix = re.sub('[^a-zA-Z0-9]', '_', parser.new_repo_name_prefix.strip())

0 commit comments

Comments
 (0)