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

Commit f2745df

Browse files
authored
DOP-3518: get umbrella metadata with one from repos_branches (#764)
* when getting umbrella metadata for associated product, check for one within repo branches first * get most recent umbrella. use $ne flag null attr * update snapshots
1 parent 0917355 commit f2745df

File tree

1 file changed

+32
-2
lines changed
  • modules/persistence/src/services/metadata/associated_products

1 file changed

+32
-2
lines changed

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ export interface ReposBranchesDocument {
4242
}
4343

4444
// Queries pool*.repos_branches for any entries for the given project and branch from a metadata entry.
45-
const getRepoBranchesEntry = async (project, branch) => {
45+
const getRepoBranchesEntry = async (project, branch = ''): Promise<ReposBranchesDocument> => {
4646
const db = await pool();
47-
return db.collection('repos_branches').findOne({ branches: { $elemMatch: { gitBranchName: branch } }, project });
47+
const query = {
48+
project,
49+
};
50+
if (branch) {
51+
query['branches'] = {
52+
$elemMatch: { gitBranchName: branch },
53+
};
54+
}
55+
return db.collection('repos_branches').findOne(query) as unknown as ReposBranchesDocument;
4856
};
4957

5058
// Queries pool*.repos_branches for all entries for associated_products in a shared metadata entry
@@ -74,10 +82,30 @@ export const hasAssociations = (metadata) => !!metadata.associated_products?.len
7482
const umbrellaMetadataEntry = async (project: string): Promise<Metadata> => {
7583
try {
7684
const snooty = await db();
85+
86+
// first find any umbrella
87+
const umbrella = await snooty.collection('metadata').findOne(
88+
{
89+
'associated_products.name': project,
90+
is_merged_toc: { $ne: true },
91+
},
92+
{
93+
sort: { build_id: -1 },
94+
}
95+
);
96+
97+
if (!umbrella) {
98+
return null as unknown as Metadata;
99+
}
100+
101+
const repoDoc = await getRepoBranchesEntry(project);
102+
const branchNames = repoDoc.branches.map((branchEntry) => branchEntry.gitBranchName);
77103
const entry = await snooty
78104
.collection('metadata')
79105
.find({
80106
'associated_products.name': project,
107+
is_merged_toc: { $ne: true },
108+
branch: { $in: branchNames },
81109
})
82110
.sort({ build_id: -1 })
83111
.limit(1)
@@ -166,6 +194,8 @@ const getAssociatedProducts = async (umbrellaMetadata) => {
166194
export const mergeAssociatedToCs = async (metadata: Metadata) => {
167195
try {
168196
const { project, branch } = metadata;
197+
// TODO: DOP-3518
198+
// should get an umbrella metadata entry that is in repos branches
169199
const umbrellaMetadata = hasAssociations(metadata) ? metadata : await umbrellaMetadataEntry(project);
170200

171201
// Short circuit execution here if there's no umbrella product metadata found

0 commit comments

Comments
 (0)