diff --git a/api/controllers/v1/github.ts b/api/controllers/v1/github.ts index c7d0ff5c9..f86677800 100644 --- a/api/controllers/v1/github.ts +++ b/api/controllers/v1/github.ts @@ -7,17 +7,12 @@ 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 { MONOREPO_NAME } from '../../../src/monorepo/utils/monorepo-constants'; -import { getMonorepoPaths } from '../../../src/monorepo'; -import { getUpdatedFilePaths } from '../../../src/monorepo/utils/path-utils'; -import { JobStatus } from '../../../src/entities/job'; async function prepGithubPushPayload( githubEvent: any, repoBranchesRepository: RepoBranchesRepository, prefix: string, - repoInfo: ReposBranchesDocsetsDocument, - directory?: string + repoInfo: ReposBranchesDocsetsDocument ) { const branch_name = githubEvent.ref.split('/')[2]; const branch_info = await repoBranchesRepository.getRepoBranchAliases( @@ -61,7 +56,6 @@ async function prepGithubPushPayload( urlSlug: urlSlug, prefix: prefix, project: project, - directory: directory, }, logs: [], }; @@ -116,70 +110,14 @@ export const TriggerBuild = async (event: any = {}, context: any = {}): Promise< } const env = c.get('env'); - - async function createAndInsertJob(path?: string) { - const repoInfo = await docsetsRepository.getRepo(body.repository.name, path); - const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : ''; - const job = await prepGithubPushPayload(body, repoBranchesRepository, jobPrefix, repoInfo, path); - + 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')); - jobRepository.notify(jobId, c.get('jobUpdatesQueueUrl'), JobStatus.inQueue, 0); consoleLogger.info(job.title, `Created Job ${jobId}`); - } - - if (body.repository.name === MONOREPO_NAME) { - // TODO: MONOREPO feature flag needed here - consoleLogger.info(body.repository.full_name, `past feature flag and monorepo conditional`); - let monorepoPaths: string[] = []; - try { - if (body.head_commit && body.repository.owner.name) { - consoleLogger.info( - body.repository.full_name, - `commitSha: ${body.head_commit.id}\nrepoName: ${body.repository.name}\nownerName: ${ - body.repository.owner.name - }\nUpdatedfilepaths: ${getUpdatedFilePaths(body.head_commit)}` - ); - monorepoPaths = await getMonorepoPaths({ - commitSha: body.head_commit.id, - repoName: body.repository.name, - ownerName: body.repository.owner.name, - updatedFilePaths: getUpdatedFilePaths(body.head_commit), - consoleLogger, - }); - consoleLogger.info(body.repository.full_name, `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) { - consoleLogger.info(body.repository.full_name, `Each path: ${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, @@ -192,27 +130,6 @@ export const TriggerBuild = async (event: any = {}, context: any = {}): Promise< headers: { 'Content-Type': 'text/plain' }, body: 'Job Queued', }; - - // 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, - // }; - // } - // return { - // statusCode: 202, - // headers: { 'Content-Type': 'text/plain' }, - // body: 'Job Queued', - // }; }; export const MarkBuildArtifactsForDeletion = markBuildArtifactsForDeletion; diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index 8bcf520a4..288b4fcb7 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -717,22 +717,17 @@ export abstract class JobHandler { this._currJob._id, `* Starting Job with ID: ${this._currJob._id} and type: ${this._currJob.payload.jobType}` ); + await this._logger.save(this._currJob._id, `* Starting Job with repo name: ${this._currJob.payload.repoName}`); try { - // this.cleanup(); - // await this.cloneRepo(this._config.get('repo_dir')); - // this._logger.save(this._currJob._id, 'Cloned Repo'); - // await this.commitCheck(); - // this._logger.save(this._currJob._id, 'Checked Commit'); - // await this.pullRepo(); - // this._logger.save(this._currJob._id, 'Pulled Repo'); - // TODO: MONOREPO feature flag needed here if ( // process.env.FEATURE_FLAG_MONOREPO_PATH === 'true' && this._currJob.payload.repoName === MONOREPO_NAME ) { + await this._logger.save(this._currJob._id, `* Using build without Makefiles`); await this.build(); } else { + await this._logger.save(this._currJob._id, `* Using build with Makefiles`); await this.buildWithMakefiles(); }