Skip to content

Commit

Permalink
add to v1?
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs committed Dec 11, 2023
1 parent c0c4c57 commit 2adf502
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Dockerfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ RUN git clone -b v${MUT_VERSION} --depth 1 https://github.com/mongodb/mut.git \
&& mv dist/mut /opt/

# install redoc fork
RUN git clone -b @dop/redoc-cli@${REDOC_CLI_VERSION} --depth 1 https://github.com/mongodb-forks/redoc.git redoc \
# Install dependencies for Redoc CLI
&& cd redoc/ \
&& npm ci --prefix cli/ --omit=dev
# RUN git clone -b @dop/redoc-cli@${REDOC_CLI_VERSION} --depth 1 https://github.com/mongodb-forks/redoc.git redoc \
# # Install dependencies for Redoc CLI
# && cd redoc/ \
# && npm ci --prefix cli/ --omit=dev

ENV PATH="${PATH}:/opt/snooty:/opt/mut:/${WORK_DIRECTORY}/.local/bin"

Expand Down
95 changes: 89 additions & 6 deletions api/controllers/v1/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ 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,

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

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
repoBranchesRepository: RepoBranchesRepository,
prefix: string,
repoInfo: ReposBranchesDocsetsDocument
repoInfo: ReposBranchesDocsetsDocument,
directory?: string
) {
const branch_name = githubEvent.ref.split('/')[2];
const branch_info = await repoBranchesRepository.getRepoBranchAliases(
Expand Down Expand Up @@ -56,6 +61,7 @@ async function prepGithubPushPayload(
urlSlug: urlSlug,
prefix: prefix,
project: project,
directory: directory,
},
logs: [],
};
Expand Down Expand Up @@ -110,14 +116,70 @@ export const TriggerBuild = async (event: any = {}, context: any = {}): Promise<
}

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 {

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);

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,
Expand All @@ -130,6 +192,27 @@ 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;
4 changes: 0 additions & 4 deletions api/controllers/v2/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ export const TriggerBuild = async (event: APIGatewayEvent): Promise<APIGatewayPr
consoleLogger.info(job.title, `Created Job ${jobId}`);
}

consoleLogger.info(body.repository.full_name, `IN V2!!! `);
consoleLogger.info(body.repository.full_name, `body repo name ${body.repository.name}`);
consoleLogger.info(body.repository.full_name, `feature flag value: ${process.env.FEATURE_FLAG_MONOREPO_PATH} `);

if (body.repository.name === MONOREPO_NAME) {
// TODO: MONOREPO feature flag needed here
consoleLogger.info(body.repository.full_name, `past feature flag and monorepo conditional`);
Expand Down

0 comments on commit 2adf502

Please sign in to comment.