Skip to content

Commit

Permalink
fix(quickie): reduceAmpBuildTimesCreateTests (#966)
Browse files Browse the repository at this point in the history
* chore(ghService): consistent naming + use import

* feat(envvar): add file path

* feat(commitService): add commit service

* feat(commit service): add in drop in replacement for path +

add in logic just for create

* fix(tests): rename vars in tests

* fix(repoService): make API not optional, set ...

default values instead

* fix(env var): reduce number of env vars being used

* chore(gitFileService): cleaner funcs

* feat(commit service): add in drop in replacement for path +

add in logic just for create

* fix(repoService): make API not optional, set ...

default values instead

* chore(githubService): refactor to ts

* refactor(constants): move out consts to constants file

* refactor(consts): update imports

* fix(auth service): type issues after refactor

* fix(sites.spec): add imports

* chore(tests): add deps

* fix(error handling): + inconsistent API calls

* fix(tests): fix failing tests

* fix(imports): tests are failing

* fix(githubCommitService): import issues

* chore(githubService): use existing util funcs
  • Loading branch information
kishore03109 authored Oct 18, 2023
1 parent cb70a89 commit 34335ad
Show file tree
Hide file tree
Showing 16 changed files with 569 additions and 230 deletions.
2 changes: 2 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ export const EFS_VOL_PATH_STAGING_LITE = path.join(
config.get("aws.efs.volPath"),
"repos-lite"
)
export const STAGING_BRANCH = "staging"
export const STAGING_LITE_BRANCH = "staging-lite"
12 changes: 9 additions & 3 deletions src/integration/Notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
} from "@root/fixtures/sessionData"
import { getAuthorizationMiddleware } from "@root/middleware"
import { NotificationsRouter as _NotificationsRouter } from "@root/routes/v2/authenticated/notifications"
import CommitServiceGitFile from "@root/services/db/CommitServiceGitFile"
import CommitServiceGitHub from "@root/services/db/CommitServiceGithub"
import { BaseDirectoryService } from "@root/services/directoryServices/BaseDirectoryService"
import { ResourceRoomDirectoryService } from "@root/services/directoryServices/ResourceRoomDirectoryService"
import { CollectionPageService } from "@root/services/fileServices/MdPageServices/CollectionPageService"
Expand Down Expand Up @@ -66,10 +68,14 @@ const MOCK_SITE_ID = "1"
const MOCK_SITE_MEMBER_ID = "1"

const gitFileSystemService = new GitFileSystemService(simpleGit())
const gitHubService = new RepoService(
const commitServiceGitFile = new CommitServiceGitFile(gitFileSystemService)
const commitServiceGitHub = new CommitServiceGitHub(isomerRepoAxiosInstance)
const gitHubService = new RepoService({
isomerRepoAxiosInstance,
gitFileSystemService
)
gitFileSystemService,
commitServiceGitFile,
commitServiceGitHub,
})
const identityAuthService = getIdentityAuthService(gitHubService)
const usersService = getUsersService(sequelize)
const configYmlService = new ConfigYmlService({ gitHubService })
Expand Down
12 changes: 9 additions & 3 deletions src/integration/Privatisation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import {
import { AuthorizationMiddleware } from "@root/middleware/authorization"
import { SettingsRouter as _SettingsRouter } from "@root/routes/v2/authenticatedSites/settings"
import { SettingsService } from "@root/services/configServices/SettingsService"
import CommitServiceGitFile from "@root/services/db/CommitServiceGitFile"
import CommitServiceGitHub from "@root/services/db/CommitServiceGithub"
import { BaseDirectoryService } from "@root/services/directoryServices/BaseDirectoryService"
import { ResourceRoomDirectoryService } from "@root/services/directoryServices/ResourceRoomDirectoryService"
import { CollectionPageService } from "@root/services/fileServices/MdPageServices/CollectionPageService"
Expand Down Expand Up @@ -97,10 +99,14 @@ jest.mock("../services/identity/DeploymentClient", () =>
}))
)
const gitFileSystemService = new GitFileSystemService(simpleGit())
const gitHubService = new RepoService(
const commitServiceGitFile = new CommitServiceGitFile(gitFileSystemService)
const commitServiceGitHub = new CommitServiceGitHub(isomerRepoAxiosInstance)
const gitHubService = new RepoService({
isomerRepoAxiosInstance,
gitFileSystemService
)
gitFileSystemService,
commitServiceGitFile,
commitServiceGitHub,
})
const configYmlService = new ConfigYmlService({ gitHubService })
const usersService = getUsersService(sequelize)
const isomerAdminsService = new IsomerAdminsService({ repository: IsomerAdmin })
Expand Down
12 changes: 9 additions & 3 deletions src/integration/Reviews.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ import {
MOCK_USER_ID_TWO,
} from "@fixtures/users"
import { ReviewRequestStatus } from "@root/constants"
import CommitServiceGitFile from "@root/services/db/CommitServiceGitFile"
import CommitServiceGitHub from "@root/services/db/CommitServiceGithub"
import { BaseDirectoryService } from "@root/services/directoryServices/BaseDirectoryService"
import { ResourceRoomDirectoryService } from "@root/services/directoryServices/ResourceRoomDirectoryService"
import { CollectionPageService } from "@root/services/fileServices/MdPageServices/CollectionPageService"
Expand Down Expand Up @@ -101,10 +103,14 @@ import ReviewRequestService from "@services/review/ReviewRequestService"
import { sequelize } from "@tests/database"

const gitFileSystemService = new GitFileSystemService(simpleGit())
const gitHubService = new RepoService(
const commitServiceGitFile = new CommitServiceGitFile(gitFileSystemService)
const commitServiceGitHub = new CommitServiceGitHub(isomerRepoAxiosInstance)
const gitHubService = new RepoService({
isomerRepoAxiosInstance,
gitFileSystemService
)
gitFileSystemService,
commitServiceGitFile,
commitServiceGitHub,
})
const configYmlService = new ConfigYmlService({ gitHubService })
const usersService = getUsersService(sequelize)
const isomerAdminsService = new IsomerAdminsService({ repository: IsomerAdmin })
Expand Down
12 changes: 9 additions & 3 deletions src/integration/Sites.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { getAuthorizationMiddleware } from "@root/middleware"
import { statsMiddleware } from "@root/middleware/stats"
import { SitesRouter as _SitesRouter } from "@root/routes/v2/authenticated/sites"
import { isomerRepoAxiosInstance } from "@root/services/api/AxiosInstance"
import CommitServiceGitFile from "@root/services/db/CommitServiceGitFile"
import CommitServiceGitHub from "@root/services/db/CommitServiceGithub"
import { BaseDirectoryService } from "@root/services/directoryServices/BaseDirectoryService"
import { ResourceRoomDirectoryService } from "@root/services/directoryServices/ResourceRoomDirectoryService"
import { CollectionPageService } from "@root/services/fileServices/MdPageServices/CollectionPageService"
Expand Down Expand Up @@ -65,10 +67,14 @@ const mockPermissions = { push: true }
const mockPrivate = true

const gitFileSystemService = new GitFileSystemService(simpleGit())
const gitHubService = new RepoService(
const commitServiceGitHub = new CommitServiceGitHub(isomerRepoAxiosInstance)
const commitServiceGitFile = new CommitServiceGitFile(gitFileSystemService)
const gitHubService = new RepoService({
isomerRepoAxiosInstance,
gitFileSystemService
)
gitFileSystemService,
commitServiceGitHub,
commitServiceGitFile,
})
const configYmlService = new ConfigYmlService({ gitHubService })
const usersService = getUsersService(sequelize)
const isomerAdminsService = new IsomerAdminsService({ repository: IsomerAdmin })
Expand Down
2 changes: 1 addition & 1 deletion src/routes/v2/authenticated/__tests__/review.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { mockUserId } from "@fixtures/identity"
import { MOCK_USER_EMAIL_ONE, MOCK_USER_EMAIL_TWO } from "@fixtures/users"
import { CollaboratorRoles, ReviewRequestStatus } from "@root/constants"
import MissingSiteError from "@root/errors/MissingSiteError"
import { GitHubService } from "@root/services/db/GitHubService"
import GitHubService from "@root/services/db/GitHubService"
import CollaboratorsService from "@services/identity/CollaboratorsService"
import NotificationsService from "@services/identity/NotificationsService"
import SitesService from "@services/identity/SitesService"
Expand Down
11 changes: 3 additions & 8 deletions src/services/db/CommitServiceGitFile.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import UserWithSiteSessionData from "@root/classes/UserWithSiteSessionData"
import { STAGING_BRANCH, STAGING_LITE_BRANCH } from "@root/constants"
import isFileAsset from "@root/utils/commit-utils"
import { isReduceBuildTimesWhitelistedRepo } from "@root/utils/growthbook-utils"

import GitFileSystemService from "./GitFileSystemService"
import { STAGING_BRANCH } from "./GitHubService"

/**
* Responsibilities of this class
* 1. Creates all commits to staging
* 2. Creates non-asset related commits to staging-lite
*/
export default class CommitServiceGitFile {
private readonly STAGING_LITE_BRANCH = "staging-lite"

private readonly gitFileSystemService: GitFileSystemService

constructor(gitFileSystemService: GitFileSystemService) {
Expand Down Expand Up @@ -58,7 +56,7 @@ export default class CommitServiceGitFile {
directoryName,
fileName,
isMedia ? "base64" : "utf-8",
this.STAGING_LITE_BRANCH
STAGING_LITE_BRANCH
)
)
}
Expand All @@ -74,10 +72,7 @@ export default class CommitServiceGitFile {

this.gitFileSystemService.push(sessionData.siteName, STAGING_BRANCH)
if (shouldUpdateStagingLite) {
this.gitFileSystemService.push(
sessionData.siteName,
this.STAGING_LITE_BRANCH
)
this.gitFileSystemService.push(sessionData.siteName, STAGING_LITE_BRANCH)
}
return { sha: stagingCreateResult.value.newSha }
}
Expand Down
17 changes: 3 additions & 14 deletions src/services/db/CommitServiceGithub.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
import { AxiosCacheInstance } from "axios-cache-interceptor"

import UserWithSiteSessionData from "@root/classes/UserWithSiteSessionData"
import { STAGING_LITE_BRANCH } from "@root/constants"
import isFileAsset from "@root/utils/commit-utils"
import { isReduceBuildTimesWhitelistedRepo } from "@root/utils/growthbook-utils"
import GitHubService, { STAGING_LITE_BRANCH } from "@services/db/GitHubService"

import GitFileSystemService from "./GitFileSystemService"
import GitHubService from "@services/db/GitHubService"

/**
* Responsibilities of this class
* 1. Creates all commits to staging
* 2. Creates non-asset related commits to staging-lite
*/
export default class CommitServiceGitHub extends GitHubService {
private readonly STAGING_BRANCH = "staging"

private readonly STAGING_LITE_BRANCH = "staging-lite"

private readonly gitFileSystemService: GitFileSystemService

constructor(
gitFileSystemService: GitFileSystemService,
axiosInstance: AxiosCacheInstance
) {
constructor(axiosInstance: AxiosCacheInstance) {
super({ axiosInstance })
this.gitFileSystemService = gitFileSystemService
}

async create(
Expand Down
4 changes: 2 additions & 2 deletions src/services/db/GitFileSystemService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
EFS_VOL_PATH_STAGING,
EFS_VOL_PATH_STAGING_LITE,
ISOMER_GITHUB_ORG_NAME,
STAGING_BRANCH,
STAGING_LITE_BRANCH,
} from "@constants/constants"

import { SessionDataProps } from "@root/classes"
Expand All @@ -45,8 +47,6 @@ import type {
import type { IsomerCommitMessage } from "@root/types/github"
import { ALLOWED_FILE_EXTENSIONS } from "@root/utils/file-upload-utils"

const STAGING_BRANCH = "staging"
const STAGING_LITE_BRANCH = "staging-lite"
export default class GitFileSystemService {
private readonly git: SimpleGit

Expand Down
Loading

0 comments on commit 34335ad

Please sign in to comment.