diff --git a/api/controllers/v1/jobs.ts b/api/controllers/v1/jobs.ts index ab29be272..4b116e19c 100644 --- a/api/controllers/v1/jobs.ts +++ b/api/controllers/v1/jobs.ts @@ -261,7 +261,7 @@ async function SubmitArchiveJob(jobId: string) { repoBranches: new DocsetsRepository(db, c, consoleLogger), }; const job = await models.jobs.getJobById(jobId); - const repo = await models.repoBranches.getRepo(job.payload.repoName, job?.payload.monorepoDir); + const repo = await models.repoBranches.getRepo(job.payload.repoName, job?.payload.directory); /* NOTE * we don't archive landing for two reasons: diff --git a/api/controllers/v1/slack.ts b/api/controllers/v1/slack.ts index 73875255b..72ed41755 100644 --- a/api/controllers/v1/slack.ts +++ b/api/controllers/v1/slack.ts @@ -72,7 +72,7 @@ export const getDeployableJobs = async ( const deployable = []; for (let i = 0; i < values.repo_option.length; i++) { - let repoOwner: string, repoName: string, branchName: string, monorepoDir: string | undefined; + let repoOwner: string, repoName: string, branchName: string, directory: string | undefined; const splitValues = values.repo_option[i].value.split('/'); if (splitValues.length === 3) { @@ -80,7 +80,7 @@ export const getDeployableJobs = async ( [repoOwner, repoName, branchName] = splitValues; } else if (splitValues.length === 4 && process.env.FEATURE_FLAG_MONOREPO_PATH === 'true') { // e.g. 10gen/docs-monorepo/cloud-docs/master => (owner/monorepo/repoDirectory/branch) - [repoOwner, repoName, monorepoDir, branchName] = splitValues; + [repoOwner, repoName, directory, branchName] = splitValues; } else { throw Error('Selected entitlement value is configured incorrectly. Check user entitlements!'); } @@ -90,7 +90,7 @@ export const getDeployableJobs = async ( const jobUserName = entitlement.github_username; const jobUserEmail = entitlement?.email ?? ''; - const repoInfo = await docsetsRepository.getRepo(repoName, monorepoDir); + const repoInfo = await docsetsRepository.getRepo(repoName, directory); const non_versioned = repoInfo.branches.length === 1; const branchObject = await repoBranchesRepository.getRepoBranchAliases(repoName, branchName, repoInfo.project); @@ -118,7 +118,7 @@ export const getDeployableJobs = async ( false, false, false, - monorepoDir + directory ); newPayload.stable = !!isStableBranch; @@ -211,7 +211,7 @@ function createPayload( aliased = false, primaryAlias = false, stable = false, - monorepoDir?: string + directory?: string ) { return { jobType, @@ -230,7 +230,7 @@ function createPayload( newHead, primaryAlias, stable, - monorepoDir, + directory, }; } diff --git a/api/controllers/v2/slack.ts b/api/controllers/v2/slack.ts index f040d286e..c47fe5c30 100644 --- a/api/controllers/v2/slack.ts +++ b/api/controllers/v2/slack.ts @@ -89,7 +89,7 @@ export const getDeployableJobs = async ( const deployable = []; for (let i = 0; i < values.repo_option.length; i++) { - let repoOwner: string, repoName: string, branchName: string, monorepoDir: string | undefined; + let repoOwner: string, repoName: string, branchName: string, directory: string | undefined; const splitValues = values.repo_option[i].value.split('/'); if (splitValues.length === 3) { @@ -97,7 +97,7 @@ export const getDeployableJobs = async ( [repoOwner, repoName, branchName] = splitValues; } else if (splitValues.length === 4) { // e.g. 10gen/docs-monorepo/cloud-docs/master => (owner/monorepo/repoDirectory/branch) - [repoOwner, repoName, monorepoDir, branchName] = splitValues; + [repoOwner, repoName, directory, branchName] = splitValues; } else { throw Error('Selected entitlement value is configured incorrectly. Check user entitlements!'); } @@ -107,7 +107,7 @@ export const getDeployableJobs = async ( const jobUserName = entitlement.github_username; const jobUserEmail = entitlement?.email ?? ''; - const repoInfo = await docsetsRepository.getRepo(repoName, monorepoDir); + const repoInfo = await docsetsRepository.getRepo(repoName, directory); const non_versioned = repoInfo.branches.length === 1; const branchObject = await repoBranchesRepository.getRepoBranchAliases(repoName, branchName, repoInfo.project); @@ -135,7 +135,7 @@ export const getDeployableJobs = async ( false, false, false, - monorepoDir + directory ); newPayload.stable = !!isStableBranch; @@ -236,7 +236,7 @@ function createPayload( aliased = false, primaryAlias = false, stable = false, - monorepoDir?: string + directory?: string ) { return { jobType, @@ -254,7 +254,7 @@ function createPayload( newHead, primaryAlias, stable, - monorepoDir, + directory, }; } diff --git a/api/handlers/slack.ts b/api/handlers/slack.ts index 2604e0b30..a13df5e4c 100644 --- a/api/handlers/slack.ts +++ b/api/handlers/slack.ts @@ -21,8 +21,8 @@ export function prepResponse(statusCode, contentType, body) { export async function buildEntitledBranchList(entitlement: any, repoBranchesRepository: RepoBranchesRepository) { const entitledBranches: string[] = []; for (const repo of entitlement.repos) { - const [repoOwner, repoName, monorepoDirPath] = repo.split('/'); - const branches = await repoBranchesRepository.getRepoBranches(repoName, monorepoDirPath); + const [repoOwner, repoName, directoryPath] = repo.split('/'); + const branches = await repoBranchesRepository.getRepoBranches(repoName, directoryPath); for (const branch of branches) { let buildWithSnooty = true; if ('buildsWithSnooty' in branch) { @@ -30,7 +30,7 @@ export async function buildEntitledBranchList(entitlement: any, repoBranchesRepo } if (buildWithSnooty) { entitledBranches.push( - `${repoOwner}/${repoName}${monorepoDirPath ? '/' + monorepoDirPath : ''}/${branch['gitBranchName']}` + `${repoOwner}/${repoName}${directoryPath ? '/' + directoryPath : ''}/${branch['gitBranchName']}` ); } } diff --git a/src/entities/job.ts b/src/entities/job.ts index e38c19d89..d09ca1c96 100644 --- a/src/entities/job.ts +++ b/src/entities/job.ts @@ -43,7 +43,7 @@ export type Payload = { prefix: string; project: string; includeInGlobalSearch: boolean; - monorepoDir?: string; + directory?: string; }; export type EnhancedPayload = { diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index 9d9823037..390521d3f 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -207,7 +207,7 @@ export abstract class JobHandler { try { const makefileFileName = this.currJob.payload.repoName === MONOREPO_NAME - ? this.currJob.payload.monorepoDir + ? this.currJob.payload.directory : this.currJob.payload.repoName; await this._fileSystemServices.saveUrlAsFile( `https://raw.githubusercontent.com/mongodb/docs-worker-pool/monorepo-pub-branches/makefiles/Makefile.${makefileFileName}`, @@ -740,6 +740,6 @@ function throwIfJobInterupted() { export function getDirectory(job: Job) { const { payload } = job; let directory = payload.repoName; - if (payload.repoName === MONOREPO_NAME && !!payload.monorepoDir) directory += `/${payload.monorepoDir}`; + if (payload.repoName === MONOREPO_NAME && !!payload.directory) directory += `/${payload.directory}`; return directory; } diff --git a/src/job/jobValidator.ts b/src/job/jobValidator.ts index 7d6a6492d..9434bdb48 100644 --- a/src/job/jobValidator.ts +++ b/src/job/jobValidator.ts @@ -33,14 +33,11 @@ export class JobValidator implements IJobValidator { async throwIfUserNotEntitled(job: Job): Promise { const entitlementsObject = await this._repoEntitlementRepository.getRepoEntitlementsByGithubUsername(job.user); - // TODO: Ensure that the user is entitled for this specific monorepo project - if ( - job.payload.repoName === MONOREPO_NAME && - entitlementsObject?.repos?.some((r) => r.match(/10gen\/docs-monorepo\//g)) - ) { - return; - } else if (!entitlementsObject?.repos?.includes(`${job.payload.repoOwner}/${job.payload.repoName}`)) { - throw new AuthorizationError(`${job.user} is not entitled for repo ${job.payload.repoName}`); + const entitlementToFind = `${job.payload.repoOwner}/${job.payload.repoName}${ + job.payload.repoName === MONOREPO_NAME ? `/${job.payload.directory}` : `` + }`; + if (!entitlementsObject?.repos?.includes(entitlementToFind)) { + throw new AuthorizationError(`${job.user} is not entitled for repo ${entitlementToFind}`); } } diff --git a/src/repositories/docsetsRepository.ts b/src/repositories/docsetsRepository.ts index d93926216..cd13aeea7 100644 --- a/src/repositories/docsetsRepository.ts +++ b/src/repositories/docsetsRepository.ts @@ -64,9 +64,9 @@ export class DocsetsRepository extends BaseRepository { return res[0]?.project; } - async getRepo(repoName: string, monorepoDir?: string): Promise { + async getRepo(repoName: string, directory?: string): Promise { const matchConditions = { repoName }; - if (monorepoDir) matchConditions['directories.snooty_toml'] = `/${monorepoDir}`; + if (directory) matchConditions['directories.snooty_toml'] = `/${directory}`; const aggregationPipeline = this.getAggregationPipeline(matchConditions); const cursor = await this.aggregate(aggregationPipeline, `Error while fetching repo by repo name ${repoName}`); diff --git a/src/repositories/repoBranchesRepository.ts b/src/repositories/repoBranchesRepository.ts index 7e52b576c..dbd811fa6 100644 --- a/src/repositories/repoBranchesRepository.ts +++ b/src/repositories/repoBranchesRepository.ts @@ -8,13 +8,13 @@ export class RepoBranchesRepository extends BaseRepository { super(config, logger, 'RepoBranchesRepository', db.collection(config.get('repoBranchesCollection'))); } - async getRepoBranches(repoName: string, monorepoDirPath?: string): Promise { + async getRepoBranches(repoName: string, directoryPath?: string): Promise { const query = { repoName: repoName }; - if (monorepoDirPath) query['directories.snooty_toml'] = `/${monorepoDirPath}`; + if (directoryPath) query['directories.snooty_toml'] = `/${directoryPath}`; const repo = await this.findOne( query, `Mongo Timeout Error: Timedout while retrieving branches for ${repoName}${ - monorepoDirPath ? `/${monorepoDirPath}` : '' + directoryPath ? `/${directoryPath}` : '' }` ); // if user has specific entitlements