in src/lambda_codebase/initial_commit/initial_commit.py [0:0]
def create_(event: Mapping[str, Any], _context: Any) -> Tuple[Union[None, PhysicalResourceId], Data]:
create_event = CreateEvent(**event)
repo_name = repo_arn_to_name(create_event.ResourceProperties.RepositoryArn)
directory = create_event.ResourceProperties.DirectoryName
try:
commit_id = CC_CLIENT.get_branch(
repositoryName=repo_name,
branchName="master",
)["branch"]["commitId"]
CC_CLIENT.create_branch(
repositoryName=repo_name,
branchName=create_event.ResourceProperties.Version,
commitId=commit_id
)
# CodeCommit only allows 100 files per commit, so we chunk them up here
for index, files in enumerate(chunks([f.as_dict() for f in get_files_to_commit(directory)], 99)):
if index == 0:
commit_id = CC_CLIENT.create_commit(
**generate_commit_input(repo_name, index, puts=files)
)["commitId"]
else:
commit_id = CC_CLIENT.create_commit(
**generate_commit_input(repo_name, index, puts=files, parent_commit_id=commit_id)
)["commitId"]
CC_CLIENT.create_pull_request(
**generate_pull_request_input(create_event, repo_name)
)
return event.get("PhysicalResourceId"), {}
except (CC_CLIENT.exceptions.FileEntryRequiredException, CC_CLIENT.exceptions.NoChangeException):
CC_CLIENT.delete_branch(**generate_delete_branch_input(create_event, repo_name))
return event.get("PhysicalResourceId"), {}
except CC_CLIENT.exceptions.BranchDoesNotExistException:
files_to_commit = get_files_to_commit(directory)
if directory == "bootstrap_repository":
adf_config = create_adf_config_file(create_event.ResourceProperties, "adfconfig.yml.j2", "/tmp/adfconfig.yml")
initial_sample_global_iam = create_adf_config_file(create_event.ResourceProperties, "bootstrap_repository/adf-bootstrap/example-global-iam.yml", "/tmp/global-iam.yml")
if create_event.ResourceProperties.DeploymentAccountFullName and create_event.ResourceProperties.DeploymentAccountEmailAddress:
adf_deployment_account_yml = create_adf_config_file(create_event.ResourceProperties, "adf.yml.j2", "/tmp/adf.yml")
files_to_commit.append(adf_deployment_account_yml)
files_to_commit.append(adf_config)
files_to_commit.append(initial_sample_global_iam)
for index, files in enumerate(chunks([f.as_dict() for f in files_to_commit], 99)):
if index == 0:
commit_id = CC_CLIENT.create_commit(
**generate_commit_input(repo_name, index, puts=files)
)["commitId"]
else:
commit_id = CC_CLIENT.create_commit(
**generate_commit_input(repo_name, index, puts=files, parent_commit_id=commit_id)
)["commitId"]
return commit_id, {}