Skip to content

Commit

Permalink
github and slack v2, split out jobs per monorepoDir
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs committed Oct 25, 2023
1 parent 83420ce commit 907f499
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 11 deletions.
44 changes: 38 additions & 6 deletions api/controllers/v2/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,59 @@ export const TriggerBuild = async (event: APIGatewayEvent): Promise<APIGatewayPr
}

const env = c.get<string>('env');
const repoInfo = await docsetsRepository.getRepo(body.repository.name);
const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : '';

const job = await prepGithubPushPayload(body, repoBranchesRepository, jobPrefix, repoInfo);

if (process.env.MONOREPO_PATH_FEATURE === 'true') {
let monorepoPaths: string[] = [];
try {
if (body.head_commit && body.repository.owner.name) {
const monorepoPaths = await getMonorepoPaths({
monorepoPaths = await getMonorepoPaths({
commitSha: body.head_commit.id,
repoName: body.repository.name,
ownerName: body.repository.owner.name,
updatedFilePaths: getUpdatedFilePaths(body.head_commit),
});
console.log('monorepoPaths: ', monorepoPaths);
consoleLogger.info('monoRepoPaths', `Monorepo Paths with new changes: ${monorepoPaths}`);
}
} catch (error) {
console.warn('Warning, attempting to get repo paths caused an error', error);
}

/* Create and insert Job for each monorepo project that has changes */
for (const path of monorepoPaths) {
// TODO: Deal with nested monorepo projects
/* For now, we will ignore nested monorepo projects until necessary */
if (path.split('/').length > 1) continue;

const repoInfo = await docsetsRepository.getRepo(body.repository.name, `/${path}`);
const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : '';
const job = await prepGithubPushPayload(body, repoBranchesRepository, jobPrefix, repoInfo);

try {
consoleLogger.info(job.title, 'Creating Job');
const jobId = await jobRepository.insertJob(job, c.get('jobsQueueUrl'));
jobRepository.notify(jobId, c.get('jobUpdatesQueueUrl'), JobStatus.inQueue, 0);
consoleLogger.info(job.title, `Created Job ${jobId}`);
} catch (err) {
return {
statusCode: 500,
headers: { 'Content-Type': 'text/plain' },
body: err,
};
}
}

return {
statusCode: 202,
headers: { 'Content-Type': 'text/plain' },
body: 'Job Queued',
};
}

const repoInfo = await docsetsRepository.getRepo(body.repository.name);
const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : '';

const job = await prepGithubPushPayload(body, repoBranchesRepository, jobPrefix, repoInfo);

try {
consoleLogger.info(job.title, 'Creating Job');
const jobId = await jobRepository.insertJob(job, c.get('jobsQueueUrl'));
Expand Down
24 changes: 19 additions & 5 deletions api/controllers/v2/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,25 @@ export const getDeployableJobs = async (
const deployable = [];

for (let i = 0; i < values.repo_option.length; i++) {
// e.g. mongodb/docs-realm/master => (site/repo/branch)
const [repoOwner, repoName, branchName] = values.repo_option[i].value.split('/');
let repoOwner: string, repoName: string, branchName: string, monorepoDir: 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) {
// e.g. 10gen/docs-monorepo/cloud-docs/master => (owner/monorepo/repoDirectory/branch)
[repoOwner, repoName, monorepoDir, 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 ?? '';

const repoInfo = await docsetsRepository.getRepo(repoName);
const repoInfo = await docsetsRepository.getRepo(repoName, monorepoDir);
const non_versioned = repoInfo.branches.length === 1;

const branchObject = await repoBranchesRepository.getRepoBranchAliases(repoName, branchName, repoInfo.project);
Expand All @@ -123,7 +134,8 @@ export const getDeployableJobs = async (
urlSlug,
false,
false,
false
false,
monorepoDir
);

newPayload.stable = !!isStableBranch;
Expand Down Expand Up @@ -223,7 +235,8 @@ function createPayload(
urlSlug,
aliased = false,
primaryAlias = false,
stable = false
stable = false,
monorepoDir?: string
) {
return {
jobType,
Expand All @@ -241,6 +254,7 @@ function createPayload(
newHead,
primaryAlias,
stable,
monorepoDir,
};
}

Expand Down

0 comments on commit 907f499

Please sign in to comment.