Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit e80d6d1

Browse files
authored
DOP-3863: Persistence module inserts github_username to Atlas (#861)
* add github_username to documents collection and metadata * use github username on updated_documents collection, use docs-builder-bot as fallback * fix tests * point toward 3863-meta branch, set off preprd build * empty-build * change back test conditions
1 parent 219d282 commit e80d6d1

File tree

8 files changed

+37
-13
lines changed

8 files changed

+37
-13
lines changed

modules/persistence/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ Compiles the module using `tsc`. By default, compiles to the `./dist` directory.
2222

2323
Runs the contents of the `./dist` directory.
2424
Requires usage of `-- -path` argument, eg `npm run start -- --path ./build/artifacts.zip`.
25+
An optional argument to specify the github user and link the build to the user will require usage of `--githubUser <github_username>`.
2526
Recommended command for running this module in higher than local environments.
2627
Requires parser output artifacts to be present in specified directory and zip file at `--path` value specified.
2728

2829
### `npm run dev`
2930

3031
Cleans dist, compiles, and runs with arguments `-path ./build/artifacts.zip`.
32+
Optionally, add the usage of this argument to the command to link build to a desired github user `-- --githubUser <github_username>`.
3133
Requires parser output artifacts to be present in specified directory and zip file at `./build/artifacts.zip`.
3234

3335
## Available Arguments

modules/persistence/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { upsertAssets } from './src/services/assets';
1717

1818
interface ModuleArgs {
1919
path: string;
20+
githubUser: string;
2021
strict: string;
2122
[props: string | number | symbol]: unknown;
2223
}
@@ -29,15 +30,19 @@ const missingPathMessage = 'No path specified in arguments - please specify a bu
2930
// Load command line args into a parameterized argv
3031
const argv: ModuleArgs = minimist(process.argv.slice(2));
3132

32-
const app = async (path: string) => {
33+
const app = async (path: string, githubUser: string) => {
3334
try {
3435
if (!path) throw missingPathMessage;
3536
const zip = new AdmZip(path);
3637
// atomic buildId for all artifacts read by this module - fundamental assumption
3738
// that only one build will be used per run of this module.
3839
const buildId = new mongodb.ObjectId();
39-
const metadata = await metadataFromZip(zip);
40-
await Promise.all([insertAndUpdatePages(buildId, zip), insertMetadata(buildId, metadata), upsertAssets(zip)]);
40+
const metadata = await metadataFromZip(zip, githubUser);
41+
await Promise.all([
42+
insertAndUpdatePages(buildId, zip, githubUser),
43+
insertMetadata(buildId, metadata),
44+
upsertAssets(zip),
45+
]);
4146
await insertMergedMetadataEntries(buildId, metadata);
4247
// DOP-3447 clean up stale metadata
4348
await deleteStaleMetadata(metadata);
@@ -52,7 +57,7 @@ const app = async (path: string) => {
5257

5358
try {
5459
console.log(argv);
55-
app(argv['path']);
60+
app(argv['path'], argv['githubUser']);
5661
} catch (error) {
5762
console.log('caught in terminal handling');
5863
// only exit with non zero error code if running with strict mode on

modules/persistence/src/services/connector/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ export const insert = async (docs: any[], collection: string, buildId: ObjectId)
4444
const insertSession = await db();
4545
try {
4646
return insertSession.collection(collection).insertMany(
47-
docs.map((d) => ({ ...d, build_id: buildId, created_at: buildId.getTimestamp() })),
47+
docs.map((d) => ({
48+
...d,
49+
build_id: buildId,
50+
created_at: buildId.getTimestamp(),
51+
})),
4852
{ ordered: false }
4953
);
5054
} catch (error) {

modules/persistence/src/services/metadata/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ export interface Metadata {
1414
associated_products?: AssociatedProduct[];
1515
toctree: ToC;
1616
toctreeOrder: any[];
17+
github_username?: string;
1718
[key: string]: any;
1819
}
1920
// Service responsible for memoization of metadata entries.
2021
// Any extraneous logic performed on metadata entries as part of upload should be added here
2122
// or within subfolders of this module
22-
export const metadataFromZip = async (zip: AdmZip) => {
23+
export const metadataFromZip = async (zip: AdmZip, githubUser?: string) => {
2324
const zipEntries = zip.getEntries();
2425
const metadata = zipEntries
2526
.filter((entry) => entry.entryName === 'site.bson')
2627
.map((entry) => deserialize(entry.getData()))[0] as Metadata;
2728
await verifyMetadata(metadata);
29+
metadata.github_username = githubUser || 'docs-builder-bot';
2830
return metadata;
2931
};
3032

modules/persistence/src/services/pages/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ const UPDATED_AST_COLL_NAME = 'updated_documents';
4343
// Service responsible for memoization of page level documents.
4444
// Any extraneous logic performed on page level documents as part of upload should be added here
4545
// or within subfolders of this module
46-
const pagesFromZip = (zip: AdmZip) => {
46+
const pagesFromZip = (zip: AdmZip, githubUser?: string) => {
4747
const zipPages = zip.getEntries();
4848
return zipPages
4949
.filter((entry) => entry.entryName?.startsWith('documents/'))
50-
.map((entry) => deserialize(entry.getData()));
50+
.map((entry) => {
51+
const document = deserialize(entry.getData());
52+
document.github_username = githubUser || 'docs-builder-bot';
53+
return document;
54+
});
5155
};
5256

5357
/**
@@ -144,6 +148,7 @@ class UpdatedPagesManager {
144148
static_assets: this.findUpdatedAssets(page.static_assets, prevPageData?.static_assets),
145149
updated_at: this.updateTime,
146150
deleted: false,
151+
github_username: page.github_username || 'docs-builder-bot',
147152
},
148153
$setOnInsert: {
149154
created_at: this.updateTime,
@@ -278,9 +283,9 @@ const updatePages = async (pages: Document[], collection: string) => {
278283
}
279284
};
280285

281-
export const insertAndUpdatePages = async (buildId: ObjectId, zip: AdmZip) => {
286+
export const insertAndUpdatePages = async (buildId: ObjectId, zip: AdmZip, githubUser?: string) => {
282287
try {
283-
const pages = pagesFromZip(zip);
288+
const pages = pagesFromZip(zip, githubUser);
284289
const ops: PromiseLike<any>[] = [insert(pages, COLLECTION_NAME, buildId)];
285290

286291
const featureEnabled = process.env.FEATURE_FLAG_UPDATE_PAGES;

modules/persistence/tests/metadata/metadata.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ describe('metadata module', () => {
4949
describe('metadataFromZip', () => {
5050
it('should get metadata from site.bson', async () => {
5151
const metaFromZip = await _metadataFromZip(zip);
52-
expect(metaFromZip).toEqual(meta);
52+
expect(metaFromZip).toEqual({ ...meta, github_username: 'docs-builder-bot' });
53+
});
54+
55+
it('should add github username to metadata', async () => {
56+
const githubUser = 'gritty';
57+
const metaFromZip = await _metadataFromZip(zip, githubUser);
58+
expect(metaFromZip).toEqual({ ...meta, github_username: githubUser });
5359
});
5460
});
5561

src/job/stagingJobHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class StagingJobHandler extends JobHandler {
5555
prepStageSpecificNextGenCommands(): void {
5656
if (this.currJob.buildCommands) {
5757
this.currJob.buildCommands[this.currJob.buildCommands.length - 1] = 'make next-gen-parse';
58-
this.currJob.buildCommands.push('make next-gen-html');
58+
this.currJob.buildCommands.push(`make next-gen-html GH_USER=${this.currJob.payload.repoOwner}`);
5959
const project = this.currJob.payload.project === 'cloud-docs' ? this.currJob.payload.project : '';
6060
const branchName = /^[a-zA-Z0-9_\-\./]+$/.test(this.currJob.payload.branchName)
6161
? this.currJob.payload.branchName

tests/data/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class TestDataProvider {
162162
const genericCommands = TestDataProvider.getCommonBuildCommands(job);
163163
const commands = Array<string>().concat(genericCommands.slice(0, genericCommands.length - 1), [
164164
'make next-gen-parse',
165-
'make next-gen-html',
165+
`make next-gen-html GH_USER=${job.payload.repoOwner}`,
166166
]);
167167
const project = job.payload.project === 'cloud-docs' ? job.payload.project : '';
168168
const branchName = /^[a-zA-Z0-9_\-\./]+$/.test(job.payload.branchName) ? job.payload.branchName : '';

0 commit comments

Comments
 (0)