Skip to content

Commit 11317d4

Browse files
authored
Fix initial commit on fresh install (#544)
**Why?** When the repository is created, there are no commits in the repo yet. The process tried to create a branch where the parent commit id was empty. This is not allowed. **What?** Instead, it should only create the branch when there is a commit to branch off from. Otherwise it should only create the new commits on the main branch directly.
1 parent 43d6d85 commit 11317d4

File tree

2 files changed

+52
-44
lines changed

2 files changed

+52
-44
lines changed

src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/deployment/lambda_codebase/initial_commit/initial_commit.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,14 @@ def generate_commits(event, repo_name, directory, parent_commit_id=None):
251251
version = event.ResourceProperties.Version
252252
default_branch_name = event.ResourceProperties.DefaultBranchName
253253
branch_name = version
254-
CC_CLIENT.create_branch(
255-
repositoryName=repo_name,
256-
branchName=branch_name,
257-
commitId=parent_commit_id
258-
)
254+
if parent_commit_id:
255+
CC_CLIENT.create_branch(
256+
repositoryName=repo_name,
257+
branchName=branch_name,
258+
commitId=parent_commit_id,
259+
)
260+
else:
261+
branch_name = default_branch_name
259262

260263
# CodeCommit only allows 100 files per commit, so we chunk them up here
261264
files_to_commit = get_files_to_commit(directory_path)
@@ -310,23 +313,24 @@ def generate_commits(event, repo_name, directory, parent_commit_id=None):
310313
):
311314
pass
312315

313-
if commits_created:
314-
CC_CLIENT.create_pull_request(
315-
title=f'ADF {version} Automated Update PR',
316-
description=PR_DESCRIPTION.format(version),
317-
targets=[
318-
{
319-
'repositoryName': repo_name,
320-
'sourceReference': branch_name,
321-
'destinationReference': default_branch_name,
322-
},
323-
],
324-
)
325-
else:
326-
CC_CLIENT.delete_branch(
327-
repositoryName=repo_name,
328-
branchName=branch_name,
329-
)
316+
if branch_name != default_branch_name:
317+
if commits_created:
318+
CC_CLIENT.create_pull_request(
319+
title=f'ADF {version} Automated Update PR',
320+
description=PR_DESCRIPTION.format(version),
321+
targets=[
322+
{
323+
'repositoryName': repo_name,
324+
'sourceReference': branch_name,
325+
'destinationReference': default_branch_name,
326+
},
327+
],
328+
)
329+
else:
330+
CC_CLIENT.delete_branch(
331+
repositoryName=repo_name,
332+
branchName=branch_name,
333+
)
330334

331335
return commits_created
332336

src/lambda_codebase/initial_commit/initial_commit.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,14 @@ def generate_commits(event, repo_name, directory, parent_commit_id=None):
269269
version = event.ResourceProperties.Version
270270
default_branch_name = event.ResourceProperties.DefaultBranchName
271271
branch_name = version
272-
CC_CLIENT.create_branch(
273-
repositoryName=repo_name,
274-
branchName=branch_name,
275-
commitId=parent_commit_id
276-
)
272+
if parent_commit_id:
273+
CC_CLIENT.create_branch(
274+
repositoryName=repo_name,
275+
branchName=branch_name,
276+
commitId=parent_commit_id,
277+
)
278+
else:
279+
branch_name = default_branch_name
277280

278281
# CodeCommit only allows 100 files per commit, so we chunk them up here
279282
files_to_commit = get_files_to_commit(directory_path)
@@ -350,23 +353,24 @@ def generate_commits(event, repo_name, directory, parent_commit_id=None):
350353
):
351354
pass
352355

353-
if commits_created:
354-
CC_CLIENT.create_pull_request(
355-
title=f'ADF {version} Automated Update PR',
356-
description=PR_DESCRIPTION.format(version),
357-
targets=[
358-
{
359-
'repositoryName': repo_name,
360-
'sourceReference': branch_name,
361-
'destinationReference': default_branch_name,
362-
},
363-
],
364-
)
365-
else:
366-
CC_CLIENT.delete_branch(
367-
repositoryName=repo_name,
368-
branchName=branch_name,
369-
)
356+
if branch_name != default_branch_name:
357+
if commits_created:
358+
CC_CLIENT.create_pull_request(
359+
title=f'ADF {version} Automated Update PR',
360+
description=PR_DESCRIPTION.format(version),
361+
targets=[
362+
{
363+
'repositoryName': repo_name,
364+
'sourceReference': branch_name,
365+
'destinationReference': default_branch_name,
366+
},
367+
],
368+
)
369+
else:
370+
CC_CLIENT.delete_branch(
371+
repositoryName=repo_name,
372+
branchName=branch_name,
373+
)
370374

371375
return commits_created
372376

0 commit comments

Comments
 (0)