Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Group "week in Openverse" items by stack label (#3955)
Madison Swain-Bowden74c9d4bbdd40
diff --git a/automations/js/src/last_week_tonight.mjs b/automations/js/src/last_week_tonight.mjsindex 536116de6..ed53034af 100644--- a/automations/js/src/last_week_tonight.mjs+++ b/automations/js/src/last_week_tonight.mjs@@ -57,6 +57,13 @@ const mergedPrsQ = (repo) =>const closedIssuesQ = (repo) =>`repo:${org}/${repo} is:issue is:closed closed:>=${startDate}`+/* Other constants */++const stackNameMap = {+ api: 'API',+ mgmt: 'Management',+}+/* Format issues, PRs and repos as HTML *//**@@ -69,16 +76,42 @@ const closedIssuesQ = (repo) =>const getItemsHtml = (title, items) => {if (!items.length) return []+ // Get a unique list of stack labels+ const stacks = [+ ...new Set(+ items+ .flatMap((item) => item.labels) // Flatten all labels into a single array+ .map((label) => label.name) // Extract the name of each label+ .filter((name) => name.startsWith('🧱 stack'))+ ),+ ].sort()++ // Aggregate items by stack+ let itemsByStack = {}++ for (const stack of stacks) {+ const stackName = stack.split(':')[1].trim()+ itemsByStack[stackName] = items+ .filter((item) => item.labels.map((label) => label.name).includes(stack))+ .sort((a, b) => a.number - b.number)+ }+return [`<h3>${title}</h3>`,- '<ul>',- ...items.map((item) => {- const href = item.html_url- const number = `#${item.number}`- const title = escapeHtml(item.title)- return `<li><a href="${href}">${number}</a>: ${title}`- }),- '</ul>',+ // Produce a list of elements for each stack, then combine them all+ ...Object.entries(itemsByStack)+ .map(([stackName, items]) => [+ `<h4>${stackNameMap[stackName] || stackName.replace(/\b[a-z]/g, (match) => match.toUpperCase())}</h4>`,+ '<ul>',+ ...items.map((item) => {+ const href = item.html_url+ const number = `#${item.number}`+ const title = escapeHtml(item.title)+ return `<li><a href="${href}">${number}</a>: ${title}`+ }),+ '</ul>',+ ])+ .flat(),]}