Clean all uncommitted changes. If base_commit is provided, reset to that commit. Then apply the patch to the codebase.
(self, patch: str, *, base_commit: str = "", filter_patch: bool = True)
| 145 | def post_run_hook(self, *, round: int) -> None: |
| 146 | """Should be called after we called the run method.""" |
| 147 | self._commit() |
| 148 | |
| 149 | # Write all changes to separate JSON file |
| 150 | self._write_changes_to_file(round=round) |
| 151 | |
| 152 | if self.push: |
| 153 | token = os.getenv("GITHUB_TOKEN") |
| 154 | force = " --force" if self._force_push else "" |
| 155 | # origin is absent during the agent's turn (see _isolate_git); re-add it only to push, |
| 156 | # then remove it again so the next round's agent still can't reach opponent code. |
| 157 | for cmd in [ |
| 158 | f"git remote add origin https://x-access-token:{token}@github.com/{GH_ORG}/{self.game_context.name}.git", |
| 159 | f"git push{force} -u origin {self._branch_name}", |
| 160 | "git push origin --tags", |
| 161 | "git remote remove origin", |
| 162 | ]: |
| 163 | assert_zero_exit_code(self.environment.execute(cmd), logger=self.logger) |
| 164 | self.logger.info(f"Pushed {self.name} commit history to remote repository (branch {self._branch_name})") |
| 165 | |
| 166 | @abstractmethod |
| 167 | def run(self) -> None: |
| 168 | """Given the observation / recap, update the codebase""" |
| 169 | |
| 170 | def get_metadata(self) -> dict: |
| 171 | """Get metadata for the agent.""" |
| 172 | return self._metadata |
| 173 | |
| 174 | def reset_and_apply_patch(self, patch: str, *, base_commit: str = "", filter_patch: bool = True) -> None: |
no test coverage detected