({
type,
id,
}: PatchRepoConfig)
| 20 | * Returns path to the repo |
| 21 | */ |
| 22 | export const ensurePatchRepo = async ({ |
| 23 | type, |
| 24 | id, |
| 25 | }: PatchRepoConfig): Promise<string> => { |
| 26 | let serverId: string | null = null; |
| 27 | |
| 28 | if (type === "application") { |
| 29 | const application = await findApplicationById(id); |
| 30 | serverId = application.buildServerId || application.serverId; |
| 31 | } else { |
| 32 | const compose = await findComposeById(id); |
| 33 | serverId = compose.serverId; |
| 34 | } |
| 35 | |
| 36 | const application = |
| 37 | type === "application" |
| 38 | ? await findApplicationById(id) |
| 39 | : await findComposeById(id); |
| 40 | |
| 41 | const { PATCH_REPOS_PATH } = paths(!!serverId); |
| 42 | const repoPath = join(PATCH_REPOS_PATH, type, application.appName); |
| 43 | |
| 44 | const applicationEntity = { |
| 45 | ...application, |
| 46 | type, |
| 47 | serverId: serverId, |
| 48 | outputPathOverride: repoPath, |
| 49 | }; |
| 50 | |
| 51 | let command = "set -e;"; |
| 52 | if (application.sourceType === "github") { |
| 53 | command += await cloneGithubRepository(applicationEntity); |
| 54 | } else if (application.sourceType === "gitlab") { |
| 55 | command += await cloneGitlabRepository(applicationEntity); |
| 56 | } else if (application.sourceType === "gitea") { |
| 57 | command += await cloneGiteaRepository(applicationEntity); |
| 58 | } else if (application.sourceType === "bitbucket") { |
| 59 | command += await cloneBitbucketRepository(applicationEntity); |
| 60 | } else if (application.sourceType === "git") { |
| 61 | command += await cloneGitRepository(applicationEntity); |
| 62 | } |
| 63 | |
| 64 | if (serverId) { |
| 65 | await execAsyncRemote(serverId, command); |
| 66 | } else { |
| 67 | await execAsync(command); |
| 68 | } |
| 69 | |
| 70 | return repoPath; |
| 71 | }; |
| 72 | |
| 73 | interface DirectoryEntry { |
| 74 | name: string; |
no test coverage detected