Skip to content

Commit

Permalink
Remove trigger build from v1 as well
Browse files Browse the repository at this point in the history
  • Loading branch information
branberry committed Sep 12, 2024
1 parent 786a02a commit 1d92b66
Showing 1 changed file with 4 additions and 67 deletions.
71 changes: 4 additions & 67 deletions api/controllers/v1/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { markBuildArtifactsForDeletion, validateJsonWebhook } from '../../handle
import { DocsetsRepository } from '../../../src/repositories/docsetsRepository';

Check warning on line 7 in api/controllers/v1/github.ts

View workflow job for this annotation

GitHub Actions / test

'DocsetsRepository' is defined but never used
import { ReposBranchesDocsetsDocument } from '../../../modules/persistence/src/services/metadata/repos_branches';
import { PushEvent } from '@octokit/webhooks-types';

Check warning on line 9 in api/controllers/v1/github.ts

View workflow job for this annotation

GitHub Actions / test

'PushEvent' is defined but never used
import { APIGatewayProxyResult } from 'aws-lambda';

async function prepGithubPushPayload(

Check warning on line 12 in api/controllers/v1/github.ts

View workflow job for this annotation

GitHub Actions / test

'prepGithubPushPayload' is defined but never used
githubEvent: any,
Expand Down Expand Up @@ -61,75 +62,11 @@ async function prepGithubPushPayload(
};
}

export const TriggerBuild = async (event: any = {}, context: any = {}): Promise<any> => {
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<string>('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<string>('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<APIGatewayProxyResult> => {
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;

0 comments on commit 1d92b66

Please sign in to comment.