Skip to content

Commit 2ad526c

Browse files
committed
Push to branch working
1 parent 16ce391 commit 2ad526c

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

codeclash/agents/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def get_agent(config: dict, game: CodeGame) -> Player:
1313
raise ValueError(f"Unknown agent type: {config['agent']}")
1414
environment = game.get_environment(f"{game.game_id}_{config['name']}")
1515
format_vars = {
16+
"game_name": game.name,
1617
"game_id": game.game_id,
1718
"rounds": game.rounds,
18-
"round": game.round,
1919
}
2020
return agents(config, environment, format_vars)

codeclash/agents/abstract.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def __init__(
2020
self.config = config
2121
self.name = f"{format_vars['game_id']}_{config['name']}"
2222
self.environment = environment
23-
self.round = format_vars["round"]
2423
self.format_vars = format_vars
24+
self.round = 1 # TODO: This is disconnected from game.round right now
2525

2626
def commit(self):
2727
"""Commit changes to the agent's codebase."""
@@ -32,6 +32,7 @@ def commit(self):
3232
]:
3333
assert_zero_exit_code(self.environment.execute(cmd))
3434
print(f"Committed changes for {self.name} for round {self.round}/{rounds}")
35+
self.round += 1 # TODO: This is disconnected from game.round right now
3536

3637
def push(self):
3738
"""Push codebase to a branch on the game's remote repository."""
@@ -40,10 +41,14 @@ def push(self):
4041
raise ValueError("GITHUB_TOKEN environment variable is required")
4142

4243
for cmd in [
43-
f"git remote add origin https://x-access-token:{token}@github.com/{GH_ORG}/{self.name}.git",
44-
"git push -u origin main",
44+
f"git remote remove origin",
45+
f"git remote add origin https://x-access-token:{token}@github.com/{GH_ORG}/{self.format_vars['game_name']}.git",
46+
f"git push origin {self.name}",
4547
]:
4648
assert_zero_exit_code(self.environment.execute(cmd))
49+
print(
50+
f"Pushed {self.name} commit history to remote repository (branch {self.name})"
51+
)
4752

4853
@abstractmethod
4954
def run(self):

codeclash/games/abstract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def get_environment(self, branch_name: str | None = None) -> DockerEnvironment:
7878
cwd=str(DIR_WORK),
7979
env={"GITHUB_TOKEN": os.getenv("GITHUB_TOKEN", "")},
8080
)
81-
# Reinitialize git
81+
# Ensure all future branches occur against branch
8282
branch_name = self.game_id if branch_name is None else branch_name
8383
for cmd in [
8484
f"git branch {branch_name}",

0 commit comments

Comments
 (0)