@@ -10,10 +10,7 @@ import { ProjectsRepository } from '../../../src/repositories/projectsRepository
1010import { EnhancedJob , EnhancedPayload , JobStatus } from '../../../src/entities/job' ;
1111import { markBuildArtifactsForDeletion , validateJsonWebhook } from '../../handlers/github' ;
1212import { DocsetsRepository } from '../../../src/repositories/docsetsRepository' ;
13- import { getMonorepoPaths } from '../../../src/monorepo' ;
14- import { getUpdatedFilePaths } from '../../../src/monorepo/utils/path-utils' ;
1513import { ReposBranchesDocsetsDocument } from '../../../modules/persistence/src/services/metadata/repos_branches' ;
16- import { MONOREPO_NAME } from '../../../src/monorepo/utils/monorepo-constants' ;
1714
1815const SMOKETEST_SITES = [
1916 'docs-landing' ,
@@ -241,129 +238,11 @@ export const triggerSmokeTestAutomatedBuild = async (event: APIGatewayEvent): Pr
241238 }
242239} ;
243240
244- export const TriggerBuild = async ( event : APIGatewayEvent ) : Promise < APIGatewayProxyResult > => {
245- const client = new mongodb . MongoClient ( c . get ( 'dbUrl' ) ) ;
246- await client . connect ( ) ;
247- const db = client . db ( c . get ( 'dbName' ) ) ;
248- const consoleLogger = new ConsoleLogger ( ) ;
249- const jobRepository = new JobRepository ( db , c , consoleLogger ) ;
250- const repoBranchesRepository = new RepoBranchesRepository ( db , c , consoleLogger ) ;
251- const docsetsRepository = new DocsetsRepository ( db , c , consoleLogger ) ;
252-
253- if ( ! event . body ) {
254- const err = 'Trigger build does not have a body in event payload' ;
255- return {
256- statusCode : 400 ,
257- headers : { 'Content-Type' : 'text/plain' } ,
258- body : err ,
259- } ;
260- }
261-
262- if ( ! validateJsonWebhook ( event , c . get < string > ( 'githubSecret' ) ) ) {
263- const errMsg = "X-Hub-Signature incorrect. Github webhook token doesn't match" ;
264- return {
265- statusCode : 401 ,
266- headers : { 'Content-Type' : 'text/plain' } ,
267- body : errMsg ,
268- } ;
269- }
270- let body : PushEvent ;
271- try {
272- body = JSON . parse ( event . body ) as PushEvent ;
273- } catch ( e ) {
274- console . log ( '[TriggerBuild]: ERROR! Could not parse event.body' , e ) ;
275- return {
276- statusCode : 502 ,
277- headers : { 'Content-Type' : 'text/plain' } ,
278- body : ' ERROR! Could not parse event.body' ,
279- } ;
280- }
281-
282- if ( body . deleted ) {
283- return {
284- statusCode : 200 ,
285- headers : { 'Content-Type' : 'text/plain' } ,
286- body : 'Job Ignored (Deletion)' ,
287- } ;
288- }
289-
290- const env = c . get < string > ( 'env' ) ;
291-
292- async function createAndInsertJob ( path ?: string ) {
293- const repo = body . repository ;
294- const repoInfo = await docsetsRepository . getRepo ( repo . name , path ) ;
295- const jobPrefix = repoInfo ?. prefix ? repoInfo [ 'prefix' ] [ env ] : '' ;
296- const jobTitle = repo . full_name ;
297- const payload = await createPayload ( {
298- repoName : repo . name ,
299- prefix : jobPrefix ,
300- repoBranchesRepository,
301- repoInfo,
302- githubEvent : body ,
303- } ) ;
304-
305- const job = await prepGithubPushPayload ( body , payload , jobTitle ) ;
306-
307- consoleLogger . info ( job . title , 'Creating Job' ) ;
308- const jobId = await jobRepository . insertJob ( job , c . get ( 'jobsQueueUrl' ) ) ;
309- jobRepository . notify ( jobId , c . get ( 'jobUpdatesQueueUrl' ) , JobStatus . inQueue , 0 ) ;
310- consoleLogger . info ( job . title , `Created Job ${ jobId } ` ) ;
311- }
312-
313- if ( process . env . FEATURE_FLAG_MONOREPO_PATH === 'true' && body . repository . name === MONOREPO_NAME ) {
314- let monorepoPaths : string [ ] = [ ] ;
315- try {
316- if ( body . head_commit && body . repository . owner . name ) {
317- monorepoPaths = await getMonorepoPaths ( {
318- commitSha : body . head_commit . id ,
319- repoName : body . repository . name ,
320- ownerName : body . repository . owner . name ,
321- updatedFilePaths : getUpdatedFilePaths ( body . head_commit ) ,
322- } ) ;
323- consoleLogger . info ( body . repository . full_name , `Monorepo Paths with new changes: ${ monorepoPaths } ` ) ;
324- }
325- } catch ( error ) {
326- consoleLogger . warn ( 'Warning, attempting to get monorepo paths caused an error' , error ) ;
327- }
328-
329- /* Create and insert Job for each monorepo project that has changes */
330- for ( const path of monorepoPaths ) {
331- consoleLogger . info ( body . repository . full_name , `Create Job for Monorepo directory: /${ path } ` ) ;
332- // TODO: Deal with nested monorepo projects
333- /* For now, we will ignore nested monorepo projects until necessary */
334- if ( path . split ( '/' ) . length > 1 ) continue ;
335-
336- try {
337- await createAndInsertJob ( path ) ;
338- } catch ( err ) {
339- return {
340- statusCode : 500 ,
341- headers : { 'Content-Type' : 'text/plain' } ,
342- body : err ,
343- } ;
344- }
345- }
346-
347- return {
348- statusCode : 202 ,
349- headers : { 'Content-Type' : 'text/plain' } ,
350- body : 'Jobs Queued' ,
351- } ;
352- }
353-
354- try {
355- await createAndInsertJob ( ) ;
356- } catch ( err ) {
357- return {
358- statusCode : 500 ,
359- headers : { 'Content-Type' : 'text/plain' } ,
360- body : err ,
361- } ;
362- }
241+ export const TriggerBuild = async ( ) : Promise < APIGatewayProxyResult > => {
363242 return {
364- statusCode : 202 ,
243+ statusCode : 404 ,
365244 headers : { 'Content-Type' : 'text/plain' } ,
366- body : 'Job Queued ' ,
245+ body : 'The Autobuilder is currently disabled for staging. Please use Netlify instead. ' ,
367246 } ;
368247} ;
369248
0 commit comments