From 01147c7623e62a2eb17f6776022fa262bfdff1f0 Mon Sep 17 00:00:00 2001 From: Hossein Margani Date: Mon, 24 Jun 2024 17:06:53 +0100 Subject: [PATCH] feat(route): add Microsoft Artifact Registry route (#15973) * Add Microsoft Artifact Registry route * Update category * Add braces around arrow function bodies * Remove semicolons * Change string interpolation * Add required semicolons * Set product parameter as wildcard * Refactor the code And fix the issues with the return of got * Correct the item link * Change descriptions separator to new line * Move mcr.microsoft to microsoft route * Correct the path --- lib/routes/microsoft/mcr.ts | 63 +++++++++++++++++++++++++++++++ lib/routes/microsoft/namespace.ts | 4 +- 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 lib/routes/microsoft/mcr.ts diff --git a/lib/routes/microsoft/mcr.ts b/lib/routes/microsoft/mcr.ts new file mode 100644 index 000000000..56580750b --- /dev/null +++ b/lib/routes/microsoft/mcr.ts @@ -0,0 +1,63 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; + +export const route: Route = { + path: '/mcr/product/*', + categories: ['program-update'], + example: '/microsoft/mcr/product/dotnet/framework/runtime', + parameters: { product: 'repository path in mcr.microsoft.com' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['https://mcr.microsoft.com/en-us/product/:product/tags'], + }, + ], + name: 'Product tags in mcr.microsoft.com', + maintainers: ['margani'], + handler, +}; + +async function handler(ctx) { + const product = ctx.req.path.replace('/microsoft/mcr/product/', ''); + const { data: details } = await got({ + method: 'get', + url: `https://mcr.microsoft.com/api/v1/catalog/${product}/details`, + }); + const { data: tags } = await got({ + method: 'get', + url: `https://mcr.microsoft.com/api/v1/catalog/${product}/tags`, + }); + + return { + title: `${details.name} - Microsoft Artifact Registry`, + description: String(details.shortDescription), + image: `https://mcr.microsoft.com${details.imagePath}`, + link: `https://mcr.microsoft.com/en-us/product/${product}`, + item: tags.map((tag: any) => { + const descriptionItems = [`Digest: \`${tag.digest}\``, `Last modified date: ${new Date(tag.lastModifiedDate).toDateString()}`]; + + if (tag.architecture) { + descriptionItems.push(`Architecture: ${tag.architecture}`); + } + if (tag.operatingSystem) { + descriptionItems.push(`Operating system: ${tag.operatingSystem}`); + } + + return { + title: `${details.name} - ${tag.name}`, + author: details.publisher, + description: descriptionItems.join('
'), + pubDate: new Date(tag.lastModifiedDate), + guid: `mcr::${product}::${tag.name}::${tag.digest}`, + link: `https://mcr.microsoft.com/en-us/product/${product}/tags`, + }; + }), + }; +} diff --git a/lib/routes/microsoft/namespace.ts b/lib/routes/microsoft/namespace.ts index 74ca7a261..44f7a31b6 100644 --- a/lib/routes/microsoft/namespace.ts +++ b/lib/routes/microsoft/namespace.ts @@ -1,6 +1,6 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { - name: 'Microsoft Edge', - url: 'microsoftedge.microsoft.com', + name: 'Microsoft', + url: 'microsoft.com', };