From 6e65cc71162bde1473220c597481ebfe524a9e8d Mon Sep 17 00:00:00 2001 From: anabellabuckvar <41971124+anabellabuckvar@users.noreply.github.com> Date: Tue, 2 Apr 2024 20:29:10 -0400 Subject: [PATCH] DOP-4490-b adding back in --- api/controllers/v1/slack.ts | 64 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/api/controllers/v1/slack.ts b/api/controllers/v1/slack.ts index 69bfc110f..933021c41 100644 --- a/api/controllers/v1/slack.ts +++ b/api/controllers/v1/slack.ts @@ -78,29 +78,40 @@ const deployHelper = (deployable, payload, jobTitle, jobUserName, jobUserEmail) // For every repo/branch selected to be deployed, return an array of jobs with the payload data // needed for a successful build. export const getDeployableJobs = async ( - values, - entitlement, + values: any, + entitlement: any, repoBranchesRepository: RepoBranchesRepository, docsetsRepository: DocsetsRepository ) => { const deployable = []; for (let i = 0; i < values?.repo_option?.length; i++) { - let repoOwner: string, repoName: string, branchName: string, directory: string | undefined; - const splitValues = values.repo_option[i].value.split('/'); - - if (splitValues.length === 3) { - // e.g. mongodb/docs-realm/master => (owner/repo/branch) - [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, directory, branchName] = splitValues; + let jobTitle: string, repoOwner: string, repoName: string, branchName: string, directory: string | undefined; + if (values.deploy_option == 'deploy_all') { + repoOwner = 'mongodb'; + branchName = 'master'; + repoName = values.repo_option[i].repoName; + jobTitle = `Slack deploy: ${repoName}, by ${entitlement.github_username}`; } else { - throw Error('Selected entitlement value is configured incorrectly. Check user entitlements!'); + const splitValues = values.repo_option[i].value.split('/'); + jobTitle = `Slack deploy: ${values.repo_option[i].value}, by ${entitlement.github_username}`; + + if (splitValues.length === 1) { + [repoName] = splitValues; + // get and set repoOwner, branchName here + } + if (splitValues.length === 3) { + // e.g. mongodb/docs-realm/master => (owner/repo/branch) + [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, directory, branchName] = splitValues; + } else { + throw Error('Selected entitlement value is configured incorrectly. Check user entitlements!'); + } } const hashOption = values?.hash_option ?? null; - const jobTitle = `Slack deploy: ${values.repo_option[i].value}, by ${entitlement.github_username}`; const jobUserName = entitlement.github_username; const jobUserEmail = entitlement?.email ?? ''; @@ -111,11 +122,11 @@ export const getDeployableJobs = async ( if (!branchObject?.aliasObject) continue; // TODO: Create strong typing for these rather than comments - const publishOriginalBranchName = branchObject.aliasObject.publishOriginalBranchName; // bool + const publishOriginalBranchName = branchObject.aliasObject.publishOriginalBranchName; let aliases = branchObject.aliasObject.urlAliases; // array or null - let urlSlug = branchObject.aliasObject.urlSlug; // string or null, string must match value in urlAliases or gitBranchName - const isStableBranch = branchObject.aliasObject.isStableBranch; // bool or Falsey - aliases = aliases?.filter((a) => a); + let urlSlug: string = branchObject.aliasObject.urlSlug; // string or null, string must match value in urlAliases or gitBranchName + const isStableBranch = !!branchObject.aliasObject.isStableBranch; // bool or Falsey + if (!urlSlug || !urlSlug.trim()) { urlSlug = branchName; } @@ -132,12 +143,11 @@ export const getDeployableJobs = async ( urlSlug, false, false, - false, + isStableBranch, directory ); - newPayload.stable = !!isStableBranch; - + aliases = aliases?.filter((a) => a); if (!aliases || aliases.length === 0) { if (non_versioned) { newPayload.urlSlug = ''; @@ -178,7 +188,7 @@ export const getDeployableJobs = async ( return deployable; }; -export const DeployRepo = async (event: any = {}, context: any = {}): Promise => { +export const DeployRepo = async (event: any = {}): Promise => { const consoleLogger = new ConsoleLogger(); const slackConnector = new SlackConnector(consoleLogger, c); if (!slackConnector.validateSlackRequest(event)) { @@ -188,15 +198,11 @@ export const DeployRepo = async (event: any = {}, context: any = {}): Promise 0) {