From 786a02a240eca8e4da286e5418ca522b3551a823 Mon Sep 17 00:00:00 2001 From: branberry Date: Thu, 12 Sep 2024 12:37:28 -0500 Subject: [PATCH 1/2] Disable autobuilder for staging --- api/controllers/v2/github.ts | 127 +---------------------------------- 1 file changed, 3 insertions(+), 124 deletions(-) diff --git a/api/controllers/v2/github.ts b/api/controllers/v2/github.ts index c97823694..52a5f44b1 100644 --- a/api/controllers/v2/github.ts +++ b/api/controllers/v2/github.ts @@ -10,10 +10,7 @@ import { ProjectsRepository } from '../../../src/repositories/projectsRepository import { EnhancedJob, EnhancedPayload, JobStatus } from '../../../src/entities/job'; import { markBuildArtifactsForDeletion, validateJsonWebhook } from '../../handlers/github'; import { DocsetsRepository } from '../../../src/repositories/docsetsRepository'; -import { getMonorepoPaths } from '../../../src/monorepo'; -import { getUpdatedFilePaths } from '../../../src/monorepo/utils/path-utils'; import { ReposBranchesDocsetsDocument } from '../../../modules/persistence/src/services/metadata/repos_branches'; -import { MONOREPO_NAME } from '../../../src/monorepo/utils/monorepo-constants'; const SMOKETEST_SITES = [ 'docs-landing', @@ -241,129 +238,11 @@ export const triggerSmokeTestAutomatedBuild = async (event: APIGatewayEvent): Pr } }; -export const TriggerBuild = async (event: APIGatewayEvent): Promise => { - const client = new mongodb.MongoClient(c.get('dbUrl')); - await client.connect(); - const db = client.db(c.get('dbName')); - const consoleLogger = new ConsoleLogger(); - const jobRepository = new JobRepository(db, c, consoleLogger); - const repoBranchesRepository = new RepoBranchesRepository(db, c, consoleLogger); - const docsetsRepository = new DocsetsRepository(db, c, consoleLogger); - - if (!event.body) { - const err = 'Trigger build does not have a body in event payload'; - return { - statusCode: 400, - headers: { 'Content-Type': 'text/plain' }, - body: err, - }; - } - - if (!validateJsonWebhook(event, c.get('githubSecret'))) { - const errMsg = "X-Hub-Signature incorrect. Github webhook token doesn't match"; - return { - statusCode: 401, - headers: { 'Content-Type': 'text/plain' }, - body: errMsg, - }; - } - let body: PushEvent; - try { - body = JSON.parse(event.body) as PushEvent; - } catch (e) { - console.log('[TriggerBuild]: ERROR! Could not parse event.body', e); - return { - statusCode: 502, - headers: { 'Content-Type': 'text/plain' }, - body: ' ERROR! Could not parse event.body', - }; - } - - if (body.deleted) { - return { - statusCode: 200, - headers: { 'Content-Type': 'text/plain' }, - body: 'Job Ignored (Deletion)', - }; - } - - const env = c.get('env'); - - async function createAndInsertJob(path?: string) { - const repo = body.repository; - const repoInfo = await docsetsRepository.getRepo(repo.name, path); - const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : ''; - const jobTitle = repo.full_name; - const payload = await createPayload({ - repoName: repo.name, - prefix: jobPrefix, - repoBranchesRepository, - repoInfo, - githubEvent: body, - }); - - const job = await prepGithubPushPayload(body, payload, jobTitle); - - 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}`); - } - - if (process.env.FEATURE_FLAG_MONOREPO_PATH === 'true' && body.repository.name === MONOREPO_NAME) { - let monorepoPaths: string[] = []; - try { - if (body.head_commit && body.repository.owner.name) { - monorepoPaths = await getMonorepoPaths({ - commitSha: body.head_commit.id, - repoName: body.repository.name, - ownerName: body.repository.owner.name, - updatedFilePaths: getUpdatedFilePaths(body.head_commit), - }); - consoleLogger.info(body.repository.full_name, `Monorepo Paths with new changes: ${monorepoPaths}`); - } - } catch (error) { - consoleLogger.warn('Warning, attempting to get monorepo paths caused an error', error); - } - - /* Create and insert Job for each monorepo project that has changes */ - for (const path of monorepoPaths) { - consoleLogger.info(body.repository.full_name, `Create Job for Monorepo directory: /${path}`); - // TODO: Deal with nested monorepo projects - /* For now, we will ignore nested monorepo projects until necessary */ - if (path.split('/').length > 1) continue; - - try { - await createAndInsertJob(path); - } catch (err) { - return { - statusCode: 500, - headers: { 'Content-Type': 'text/plain' }, - body: err, - }; - } - } - - return { - statusCode: 202, - headers: { 'Content-Type': 'text/plain' }, - body: 'Jobs Queued', - }; - } - - try { - await createAndInsertJob(); - } catch (err) { - return { - statusCode: 500, - headers: { 'Content-Type': 'text/plain' }, - body: err, - }; - } +export const TriggerBuild = async (): Promise => { return { - statusCode: 202, + statusCode: 404, headers: { 'Content-Type': 'text/plain' }, - body: 'Job Queued', + body: 'The Autobuilder is currently disabled for staging. Please use Netlify instead.', }; }; From 1d92b66625560e7990e551d34b87bbd143f73b9e Mon Sep 17 00:00:00 2001 From: branberry Date: Thu, 12 Sep 2024 15:21:30 -0500 Subject: [PATCH 2/2] Remove trigger build from v1 as well --- api/controllers/v1/github.ts | 71 ++---------------------------------- 1 file changed, 4 insertions(+), 67 deletions(-) diff --git a/api/controllers/v1/github.ts b/api/controllers/v1/github.ts index f743e65b8..ae821b23a 100644 --- a/api/controllers/v1/github.ts +++ b/api/controllers/v1/github.ts @@ -7,6 +7,7 @@ import { markBuildArtifactsForDeletion, validateJsonWebhook } from '../../handle import { DocsetsRepository } from '../../../src/repositories/docsetsRepository'; import { ReposBranchesDocsetsDocument } from '../../../modules/persistence/src/services/metadata/repos_branches'; import { PushEvent } from '@octokit/webhooks-types'; +import { APIGatewayProxyResult } from 'aws-lambda'; async function prepGithubPushPayload( githubEvent: any, @@ -61,75 +62,11 @@ async function prepGithubPushPayload( }; } -export const TriggerBuild = async (event: any = {}, context: any = {}): Promise => { - const client = new mongodb.MongoClient(c.get('dbUrl')); - await client.connect(); - const db = client.db(c.get('dbName')); - const consoleLogger = new ConsoleLogger(); - const jobRepository = new JobRepository(db, c, consoleLogger); - const repoBranchesRepository = new RepoBranchesRepository(db, c, consoleLogger); - const docsetsRepository = new DocsetsRepository(db, c, consoleLogger); - - if (!validateJsonWebhook(event, c.get('githubSecret'))) { - const errMsg = "X-Hub-Signature incorrect. Github webhook token doesn't match"; - return { - statusCode: 401, - headers: { 'Content-Type': 'text/plain' }, - body: errMsg, - }; - } - if (!event.body) { - const err = 'Trigger build does not have a body in event payload'; - consoleLogger.error('TriggerBuildError', err); - return { - statusCode: 400, - headers: { 'Content-Type': 'text/plain' }, - body: err, - }; - } - - let body: PushEvent; - try { - body = JSON.parse(event.body) as PushEvent; - } catch (e) { - consoleLogger.error('[TriggerBuild]', `ERROR! Could not parse event.body ${e}`); - console.log(`event: ${event} and event body: ${event.body}`); - return { - statusCode: 502, - headers: { 'Content-Type': 'text/plain' }, - body: ' ERROR! Could not parse event.body', - }; - } - - if (body.deleted) { - return { - statusCode: 200, - headers: { 'Content-Type': 'text/plain' }, - body: 'Job Ignored (Deletion)', - }; - } - - const env = c.get('env'); - const repoInfo = await docsetsRepository.getRepo(body.repository.name); - const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : ''; - // TODO: Make job be of type Job - const job = await prepGithubPushPayload(body, repoBranchesRepository, jobPrefix, repoInfo); - try { - consoleLogger.info(job.title, 'Creating Job'); - const jobId = await jobRepository.insertJob(job, c.get('jobsQueueUrl')); - consoleLogger.info(job.title, `Created Job ${jobId}`); - } catch (err) { - return { - statusCode: 500, - headers: { 'Content-Type': 'text/plain' }, - body: err, - }; - } +export const TriggerBuild = async (): Promise => { return { - statusCode: 202, + statusCode: 404, headers: { 'Content-Type': 'text/plain' }, - body: 'Job Queued', + body: 'The Autobuilder is currently disabled for staging. Please use Netlify instead.', }; }; - export const MarkBuildArtifactsForDeletion = markBuildArtifactsForDeletion;