Skip to content

Commit e3f8aa7

Browse files
authored
Automatically sign commits using GitHub API instead of GitPython and GPG (#44)
1 parent bfd879d commit e3f8aa7

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

src/config.py

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def __init__(self,
1616
go_getter_tool: str,
1717
dry_run: bool,
1818
affected_components_file: str = '',
19-
gpg_key_id: str = '',
2019
pr_title_template: str = '',
2120
pr_body_template: str = '',
2221
pr_labels: str = 'component-update'):
@@ -31,7 +30,6 @@ def __init__(self,
3130
self.dry_run: bool = dry_run
3231
self.components_download_dir: str = io.create_tmp_dir()
3332
self.skip_component_repo_fetching: bool = False
34-
self.gpg_key_id: str = gpg_key_id
3533
self.pr_title_template: str = pr_title_template
3634
self.pr_body_template: str = pr_body_template
3735
self.pr_labels: List[str] = utils.parse_comma_or_new_line_separated_list(pr_labels)

src/github_provider.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,23 @@ def get_branches(self, repo_dir: str):
8282

8383
return set(branches)
8484

85-
def create_branch_and_push_all_changes(self, repo_dir: str, branch_name: str, commit_message: str):
86-
repo = git.repo.Repo(repo_dir)
85+
def create_branch_and_push_all_changes(self, branch_name: str, commit_message: str):
86+
base_branch = self.__repo.get_branch(self.__repo.default_branch)
87+
base_tree = self.__repo.get_git_tree(base_branch.commit.sha)
8788

88-
new_branch = repo.create_head(branch_name)
89+
self.__repo.create_git_ref(ref=f"refs/heads/{branch_name}", sha=base_branch.commit.sha)
8990

90-
repo.git.checkout(new_branch)
91-
repo.git.add("-A")
91+
new_tree = self.__repo.create_git_tree([], base_tree.sha)
92+
commit = self.__repo.create_git_commit(
93+
message=commit_message,
94+
tree=new_tree.sha,
95+
parents=[base_branch.commit.sha]
96+
)
9297

93-
if self.__config.gpg_key_id:
94-
repo.git.commit('-S', f'--gpg-sign={self.__config.gpg_key_id}', '-m', commit_message)
95-
else:
96-
repo.index.commit(commit_message)
98+
self.__repo.update_git_ref(ref=f"heads/{branch_name}", sha=commit.sha)
9799

98100
if not self.__config.dry_run:
99-
repo.git.push("--set-upstream", "origin", branch_name)
101+
logging.info(f"Changes pushed to branch {branch_name}")
100102

101103
def branch_exists(self, branch_name: str):
102104
remote_branch_name = f'origin/{branch_name}'

src/main.py

-7
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ def main(github_api_token: str, config: Config):
6969
show_default=True,
7070
default="affected_components.json",
7171
help="Path to output file that will contain list of affected components in json format")
72-
@click.option('--gpg-key-id',
73-
required=False,
74-
show_default=True,
75-
default="",
76-
help="GPG key ID to sign commits")
7772
@click.option('--pr-title-template',
7873
required=False,
7974
show_default=True,
@@ -101,7 +96,6 @@ def cli_main(github_api_token,
10196
log_level,
10297
dry_run,
10398
affected_components_file,
104-
gpg_key_id,
10599
pr_title_template,
106100
pr_body_template,
107101
pr_labels):
@@ -119,7 +113,6 @@ def cli_main(github_api_token,
119113
go_getter_tool,
120114
dry_run,
121115
affected_components_file,
122-
gpg_key_id,
123116
pr_title_template,
124117
pr_body_template,
125118
pr_labels)

0 commit comments

Comments
 (0)