Skip to content

Disable bot commit #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codegen/git/repo_operator/local_repo_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(
self,
repo_path: str, # full path to the repo
repo_config: BaseRepoConfig | None = None,
bot_commit: bool = True,
bot_commit: bool = False,
) -> None:
self._repo_path = repo_path
self._repo_name = os.path.basename(repo_path)
Expand Down
62 changes: 47 additions & 15 deletions src/codegen/git/repo_operator/repo_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,57 @@ def viz_path(self) -> str:
def viz_file_path(self) -> str:
return os.path.join(self.viz_path, "graph.json")

def _set_bot_email(self, git_cli: GitCLI) -> None:
with git_cli.config_writer("repository") as writer:
if not writer.has_section("user"):
writer.add_section("user")
writer.set("user", "email", CODEGEN_BOT_EMAIL)

def _set_bot_username(self, git_cli: GitCLI) -> None:
with git_cli.config_writer("repository") as writer:
if not writer.has_section("user"):
writer.add_section("user")
writer.set("user", "name", CODEGEN_BOT_NAME)

def _unset_bot_email(self, git_cli: GitCLI) -> None:
with git_cli.config_writer("repository") as writer:
if writer.has_option("user", "email"):
writer.remove_option("user", "email")

def _unset_bot_username(self, git_cli: GitCLI) -> None:
with git_cli.config_writer("repository") as writer:
if writer.has_option("user", "name"):
writer.remove_option("user", "name")

@cached_property
def git_cli(self) -> GitCLI:
"""Note: this is recursive, may want to look out"""
git_cli = GitCLI(self.repo_path)
has_username = False
has_email = False
with git_cli.config_reader(None) as reader:
if reader.has_option("user", "name"):
has_username = True
if reader.has_option("user", "email"):
has_email = True
with git_cli.config_writer("repository") as writer:
if not has_username or not has_email or self.bot_commit:
if not writer.has_section("user"):
writer.add_section("user")
if not has_username or self.bot_commit:
writer.set("user", "name", CODEGEN_BOT_NAME)
if not has_email or self.bot_commit:
writer.set("user", "email", CODEGEN_BOT_EMAIL)
username = None
user_level = None
email = None
email_level = None
levels = ["system", "global", "user", "repository"]
for level in levels:
with git_cli.config_reader(level) as reader:
if reader.has_option("user", "name") and not username:
username = reader.get("user", "name")
user_level = level
if reader.has_option("user", "email") and not email:
email = reader.get("user", "email")
email_level = level
if self.bot_commit:
self._set_bot_email(git_cli)
self._set_bot_username(git_cli)
else:
if not username:
self._unset_bot_username(git_cli)
if not email:
self._unset_bot_email(git_cli)
if username != CODEGEN_BOT_NAME:
self._unset_bot_username(git_cli)
if email != CODEGEN_BOT_EMAIL:
self._unset_bot_email(git_cli)
return git_cli

@property
Expand Down