Skip to content

Commit

Permalink
feat: git push force to github on second retry (#1313)
Browse files Browse the repository at this point in the history
  • Loading branch information
harishv7 authored and kishore03109 committed May 9, 2024
1 parent 214b078 commit de3b512
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/services/db/GitFileSystemService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,28 +739,30 @@ export default class GitFileSystemService {
.orElse(() =>
// Retry push twice
// TODO: To eliminate duplicate code by using a backoff or retry package
ResultAsync.fromPromise(
isForce
? this.git
.cwd({ path: `${efsVolPath}/${repoName}`, root: false })
.push([...gitOptions, "--force"])
: this.git
.cwd({ path: `${efsVolPath}/${repoName}`, root: false })
.push(gitOptions),
(error) => {
logger.error(
`Both retries for git push have failed. Error when pushing ${repoName}: ${error}`
)

if (error instanceof GitError) {
return new GitFileSystemError(
"Unable to push latest changes of repo"
// As a last resort, we do a force push to GitHub as EFS is the source of truth
{
logger.info(
`Performing a force push to GitHub as earlier retries have failed for ${repoName}`
)
return ResultAsync.fromPromise(
this.git
.cwd({ path: `${efsVolPath}/${repoName}`, root: false })
.push([...gitOptions, "--force"]),
(error) => {
logger.error(
`Both retries for git push have failed. Error when pushing ${repoName}: ${error}`
)
}

return new GitFileSystemError("An unknown error occurred")
}
)
if (error instanceof GitError) {
return new GitFileSystemError(
"Unable to push latest changes of repo"
)
}

return new GitFileSystemError("An unknown error occurred")
}
)
}
)
.map(() => `${efsVolPath}/${repoName}`)
})
Expand Down

0 comments on commit de3b512

Please sign in to comment.