-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change to class
- Loading branch information
Showing
1 changed file
with
47 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,42 +13,52 @@ import GitFileSystemService from "../db/GitFileSystemService" | |
|
||
const LOCK_TIME_SECONDS = 15 * 60 // 15 minutes | ||
|
||
// TODO: Add class constructor and update these to be deps | ||
const gitFileSystemService: GitFileSystemService = (null as unknown) as GitFileSystemService | ||
const reposService: ReposService = (null as unknown) as ReposService | ||
|
||
export const lockRepo = ( | ||
repoName: string, | ||
lockDurationSeconds: number = LOCK_TIME_SECONDS | ||
) => | ||
ResultAsync.fromPromise( | ||
lock(repoName, lockDurationSeconds), | ||
(err) => new LockedError(`Unable to lock repo ${repoName}, ${err}`) | ||
).map(() => repoName) | ||
|
||
export const cloneRepo = (repoName: string) => { | ||
const repoUrl = `[email protected]:isomerpages/${repoName}.git` | ||
|
||
return ( | ||
gitFileSystemService | ||
.cloneBranch(repoName, true) | ||
// Repo does not exist in EFS, clone it | ||
.andThen(() => | ||
// repo exists in efs, but we need to pull for staging and reset staging lite | ||
gitFileSystemService | ||
.pull(repoName, "staging") | ||
.andThen(() => | ||
fromPromise( | ||
reposService.setUpStagingLite( | ||
path.join(EFS_VOL_PATH_STAGING_LITE, repoName), | ||
repoUrl | ||
), | ||
(error) => | ||
new GitFileSystemError( | ||
`Error setting up staging lite for repo ${repoName}: ${error}` | ||
) | ||
interface RepairServiceProps { | ||
gitFileSystemService: GitFileSystemService | ||
reposService: ReposService | ||
} | ||
|
||
export class RepairService { | ||
gitFileSystemService: GitFileSystemService | ||
|
||
reposService: ReposService | ||
|
||
constructor({ gitFileSystemService, reposService }: RepairServiceProps) { | ||
this.reposService = reposService | ||
this.gitFileSystemService = gitFileSystemService | ||
} | ||
|
||
lockRepo(repoName: string, lockDurationSeconds: number = LOCK_TIME_SECONDS) { | ||
return ResultAsync.fromPromise( | ||
lock(repoName, lockDurationSeconds), | ||
(err) => new LockedError(`Unable to lock repo ${repoName}, ${err}`) | ||
).map(() => repoName) | ||
} | ||
|
||
cloneRepo(repoName: string) { | ||
const repoUrl = `[email protected]:isomerpages/${repoName}.git` | ||
|
||
return ( | ||
this.gitFileSystemService | ||
.cloneBranch(repoName, true) | ||
// Repo does not exist in EFS, clone it | ||
.andThen(() => | ||
// repo exists in efs, but we need to pull for staging and reset staging lite | ||
this.gitFileSystemService | ||
.pull(repoName, "staging") | ||
.andThen(() => | ||
fromPromise( | ||
this.reposService.setUpStagingLite( | ||
path.join(EFS_VOL_PATH_STAGING_LITE, repoName), | ||
repoUrl | ||
), | ||
(error) => | ||
new GitFileSystemError( | ||
`Error setting up staging lite for repo ${repoName}: ${error}` | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
} | ||
} |