Skip to content

Commit 7d36348

Browse files
authored
Disable Autobuilder for Writer's Staging (#1068)
* Disable autobuilder for staging * Remove trigger build from v1 as well
1 parent 708cbfd commit 7d36348

File tree

2 files changed

+7
-191
lines changed

2 files changed

+7
-191
lines changed

api/controllers/v1/github.ts

+4-67
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { markBuildArtifactsForDeletion, validateJsonWebhook } from '../../handle
77
import { DocsetsRepository } from '../../../src/repositories/docsetsRepository';
88
import { ReposBranchesDocsetsDocument } from '../../../modules/persistence/src/services/metadata/repos_branches';
99
import { PushEvent } from '@octokit/webhooks-types';
10+
import { APIGatewayProxyResult } from 'aws-lambda';
1011

1112
async function prepGithubPushPayload(
1213
githubEvent: any,
@@ -61,75 +62,11 @@ async function prepGithubPushPayload(
6162
};
6263
}
6364

64-
export const TriggerBuild = async (event: any = {}, context: any = {}): Promise<any> => {
65-
const client = new mongodb.MongoClient(c.get('dbUrl'));
66-
await client.connect();
67-
const db = client.db(c.get('dbName'));
68-
const consoleLogger = new ConsoleLogger();
69-
const jobRepository = new JobRepository(db, c, consoleLogger);
70-
const repoBranchesRepository = new RepoBranchesRepository(db, c, consoleLogger);
71-
const docsetsRepository = new DocsetsRepository(db, c, consoleLogger);
72-
73-
if (!validateJsonWebhook(event, c.get<string>('githubSecret'))) {
74-
const errMsg = "X-Hub-Signature incorrect. Github webhook token doesn't match";
75-
return {
76-
statusCode: 401,
77-
headers: { 'Content-Type': 'text/plain' },
78-
body: errMsg,
79-
};
80-
}
81-
if (!event.body) {
82-
const err = 'Trigger build does not have a body in event payload';
83-
consoleLogger.error('TriggerBuildError', err);
84-
return {
85-
statusCode: 400,
86-
headers: { 'Content-Type': 'text/plain' },
87-
body: err,
88-
};
89-
}
90-
91-
let body: PushEvent;
92-
try {
93-
body = JSON.parse(event.body) as PushEvent;
94-
} catch (e) {
95-
consoleLogger.error('[TriggerBuild]', `ERROR! Could not parse event.body ${e}`);
96-
console.log(`event: ${event} and event body: ${event.body}`);
97-
return {
98-
statusCode: 502,
99-
headers: { 'Content-Type': 'text/plain' },
100-
body: ' ERROR! Could not parse event.body',
101-
};
102-
}
103-
104-
if (body.deleted) {
105-
return {
106-
statusCode: 200,
107-
headers: { 'Content-Type': 'text/plain' },
108-
body: 'Job Ignored (Deletion)',
109-
};
110-
}
111-
112-
const env = c.get<string>('env');
113-
const repoInfo = await docsetsRepository.getRepo(body.repository.name);
114-
const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : '';
115-
// TODO: Make job be of type Job
116-
const job = await prepGithubPushPayload(body, repoBranchesRepository, jobPrefix, repoInfo);
117-
try {
118-
consoleLogger.info(job.title, 'Creating Job');
119-
const jobId = await jobRepository.insertJob(job, c.get('jobsQueueUrl'));
120-
consoleLogger.info(job.title, `Created Job ${jobId}`);
121-
} catch (err) {
122-
return {
123-
statusCode: 500,
124-
headers: { 'Content-Type': 'text/plain' },
125-
body: err,
126-
};
127-
}
65+
export const TriggerBuild = async (): Promise<APIGatewayProxyResult> => {
12866
return {
129-
statusCode: 202,
67+
statusCode: 404,
13068
headers: { 'Content-Type': 'text/plain' },
131-
body: 'Job Queued',
69+
body: 'The Autobuilder is currently disabled for staging. Please use Netlify instead.',
13270
};
13371
};
134-
13572
export const MarkBuildArtifactsForDeletion = markBuildArtifactsForDeletion;

api/controllers/v2/github.ts

+3-124
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import { ProjectsRepository } from '../../../src/repositories/projectsRepository
1010
import { EnhancedJob, EnhancedPayload, JobStatus } from '../../../src/entities/job';
1111
import { markBuildArtifactsForDeletion, validateJsonWebhook } from '../../handlers/github';
1212
import { DocsetsRepository } from '../../../src/repositories/docsetsRepository';
13-
import { getMonorepoPaths } from '../../../src/monorepo';
14-
import { getUpdatedFilePaths } from '../../../src/monorepo/utils/path-utils';
1513
import { ReposBranchesDocsetsDocument } from '../../../modules/persistence/src/services/metadata/repos_branches';
16-
import { MONOREPO_NAME } from '../../../src/monorepo/utils/monorepo-constants';
1714

1815
const 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

Comments
 (0)