Skip to content

Commit

Permalink
Merge branch 'master' into DOP-4033
Browse files Browse the repository at this point in the history
  • Loading branch information
branberry authored Oct 26, 2023
2 parents 759689a + 2829104 commit e442448
Show file tree
Hide file tree
Showing 5 changed files with 701 additions and 6 deletions.
20 changes: 16 additions & 4 deletions modules/persistence/src/services/metadata/repos_branches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface ReposBranchesDocument extends WithId<Document> {
branches: BranchEntry[];
url: EnvKeyedObject;
prefix: EnvKeyedObject;
internalOnly: boolean;
[key: string]: any;
}

Expand Down Expand Up @@ -82,7 +83,7 @@ export const getAllAssociatedRepoBranchesEntries = async (metadata: Metadata) =>

try {
const db = await pool();
const aggregationPipeline = getAggregationPipeline({ project: { $in: fetch } });
const aggregationPipeline = getAggregationPipeline({ project: { $in: fetch }, internalOnly: false });
const cursor = db.collection('docsets').aggregate(aggregationPipeline);
const docsets = (await cursor.toArray()) as ReposBranchesDocument[];
docsets.forEach((doc: ReposBranchesDocument) => {
Expand Down Expand Up @@ -114,20 +115,31 @@ export const getRepoBranchesEntry = async (project: project, branch = ''): Promi
// get from DB if not cached
try {
const db = await pool();
const matchCondition = { project };
const matchCondition = {
project,
// We want the repo branches of the single deployable repo for a docset
internalOnly: false,
};
if (branch) {
matchCondition['branches'] = { $elemMatch: { gitBranchName: branch } };
}
const aggregationPipeline = getAggregationPipeline(matchCondition);

const cursor = db.collection('docsets').aggregate(aggregationPipeline);
const res = (await cursor.toArray()) as unknown as ReposBranchesDocument[];
const returnedEntry = res[0];

if (res.length > 1) {
console.warn(
`Expected 1 deployable repo for docset with project "${project}", but found ${res.length} instead. Defaulting to first found: "${returnedEntry.repoName}".`
);
}

// if not already set, set cache value for repo_branches
if (!internals[project]) {
internals[project] = res[0];
internals[project] = returnedEntry;
}
return res[0];
return returnedEntry;
} catch (e) {
console.error(`Error while getting repo branches entry: ${e}`);
throw e;
Expand Down
60 changes: 60 additions & 0 deletions modules/persistence/tests/data/docsets.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,65 @@
"categoryTitle": "Atlas CLI"
},
"repos": ["6243aa3f0aae3635a59a1150"]
},
{
"_id": "6500937d24fcc731b4735cff",
"project": "docs",
"bucket": {
"regression": "docs-mongodb-org-stg",
"dev": "docs-mongodb-org-dev",
"stg": "docs-mongodb-org-stg",
"prd": "docs-mongodb-org-prd",
"dotcomstg": "docs-mongodb-org-dotcomstg",
"dotcomprd": "docs-mongodb-org-dotcomprd"
},
"directories": {
"snooty_toml": "/docs"
},
"prefix": {
"stg": "",
"prd": "",
"dotcomstg": "docs-qa",
"dotcomprd": "docs"
},
"repos": ["5fac1ce373a72fca02ec90c5", "614b9f5b8d181382ca755ade"],
"url": {
"regression": "https://docs-mongodbcom-integration.corp.mongodb.com",
"dev": "https://docs-mongodborg-staging.corp.mongodb.com",
"stg": "https://docs-mongodborg-staging.corp.mongodb.com",
"prd": "https://docs.mongodb.com",
"dotcomprd": "http://mongodb.com/",
"dotcomstg": "https://mongodbcom-cdn.website.staging.corp.mongodb.com/"
}
},
{
"_id": "6500937d24fcc731b4735d00",
"project": "multiple-deployables",
"bucket": {
"regression": "docs-mongodb-org-stg",
"dev": "docs-mongodb-org-dev",
"stg": "docs-mongodb-org-stg",
"prd": "docs-mongodb-org-prd",
"dotcomstg": "docs-mongodb-org-dotcomstg",
"dotcomprd": "docs-mongodb-org-dotcomprd"
},
"directories": {
"snooty_toml": "/docs"
},
"prefix": {
"stg": "",
"prd": "",
"dotcomstg": "docs-qa",
"dotcomprd": "docs"
},
"repos": ["6526fe0d17c4f50e837e419f", "6526fe0d17c4f50e837e420f"],
"url": {
"regression": "https://docs-mongodbcom-integration.corp.mongodb.com",
"dev": "https://docs-mongodborg-staging.corp.mongodb.com",
"stg": "https://docs-mongodborg-staging.corp.mongodb.com",
"prd": "https://docs.mongodb.com",
"dotcomprd": "http://mongodb.com/",
"dotcomstg": "https://mongodbcom-cdn.website.staging.corp.mongodb.com/"
}
}
]
Loading

0 comments on commit e442448

Please sign in to comment.