Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,26 @@ const mapRepoBranches = (repoBranches: ReposBranchesDocsetsDocument[]) =>

export const hasAssociations = (metadata) => !!metadata.associated_products?.length;

const umbrellaMetadataEntry = async (project: string): Promise<Metadata> => {
const umbrellaMetadataEntry = async (project: string): Promise<Metadata | null> => {
try {
const snooty = await db();

// first find any umbrella
const umbrella = await snooty.collection('metadata').findOne(
const umbrellaRepos = await getRepoBranchesEntry(project);
const branchNames = umbrellaRepos.branches.map((branchEntry) => branchEntry.gitBranchName);
const entry = await snooty.collection('metadata').findOne(
{
'associated_products.name': project,
is_merged_toc: { $ne: true },
branch: { $in: branchNames },
},
{
sort: { build_id: -1 },
sort: { build_id: -1, is_merged_toc: -1 },
}
);

if (!umbrella) {
return null as unknown as Metadata;
if (!entry) {
return null;
}

const umbrellaRepos = await getRepoBranchesEntry(umbrella.project);
const branchNames = umbrellaRepos.branches.map((branchEntry) => branchEntry.gitBranchName);
const entry = await snooty
.collection('metadata')
.find({
'associated_products.name': project,
is_merged_toc: { $ne: true },
branch: { $in: branchNames },
})
.sort({ build_id: -1 })
.limit(1)
.toArray();
return entry[0] as unknown as Metadata;
return entry as unknown as Metadata;
} catch (error) {
console.log(`Error at time of querying for umbrella metadata entry: ${error}`);
throw error;
Expand Down Expand Up @@ -159,7 +147,8 @@ const getAssociatedProducts = async (umbrellaMetadata) => {
export const mergeAssociatedToCs = async (metadata: Metadata) => {
try {
const { project, branch } = metadata;
const umbrellaMetadata = hasAssociations(metadata) ? metadata : await umbrellaMetadataEntry(project);
const isUmbrellaMetadata = hasAssociations(metadata);
const umbrellaMetadata = isUmbrellaMetadata ? metadata : await umbrellaMetadataEntry(project);

// Short circuit execution here if there's no umbrella product metadata found
if (!umbrellaMetadata) return;
Expand All @@ -173,7 +162,12 @@ export const mergeAssociatedToCs = async (metadata: Metadata) => {
if (!umbrellaRepoBranchesEntry)
throw `No repoBranches entry available for umbrella metadata with project: ${umbrellaMetadata.project}, branch: ${umbrellaMetadata.branch}`;

const repoBranchesEntries = await getAllAssociatedRepoBranchesEntries(umbrellaMetadata);
// if input is already umbrella metadata, update all the children projects
// if input is child metadata, update only the current branch and the parent
const repoBranchesEntries = isUmbrellaMetadata
? await getAllAssociatedRepoBranchesEntries(umbrellaMetadata)
: [await getRepoBranchesEntry(project, branch)];

const repoBranchesMap = mapRepoBranches(repoBranchesEntries);
const metadataCursor = await getAssociatedProducts(umbrellaMetadata);

Expand Down Expand Up @@ -203,6 +197,10 @@ export const mergeAssociatedToCs = async (metadata: Metadata) => {
mergedMetadataEntry.is_merged_toc = true;
return mergedMetadataEntry;
});
console.log(
'mergedMetadataEntries versions ',
mergedMetadataEntries.map((m) => m.branch)
);
return mergedMetadataEntries;
} catch (error) {
console.log(`Error at time of merging associated ToC entries: ${error}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const getAllAssociatedRepoBranchesEntries = async (metadata: Metadata) =>
};

// Queries pool*.repos_branches and pool*. for any entries for the given project and branch from a metadata entry.
export const getRepoBranchesEntry = async (project: project, branch = ''): Promise<ReposBranchesDocument> => {
export const getRepoBranchesEntry = async (project: project, branch = ''): Promise<ReposBranchesDocsetsDocument> => {
const cachedDoc = internals[project];
// return cached repo doc if exists
if (cachedDoc !== undefined) {
Expand All @@ -120,7 +120,7 @@ export const getRepoBranchesEntry = async (project: project, branch = ''): Promi

return cachedDoc.branches.map((b) => b.gitBranchName).includes(branch)
? cachedDoc
: (null as unknown as ReposBranchesDocument);
: (null as unknown as ReposBranchesDocsetsDocument);
}

// get from DB if not cached
Expand Down
Loading