(prefix, feedUrl, ignoreCache = false)
| 24 | } |
| 25 | |
| 26 | export async function getChangelogItems(prefix, feedUrl, ignoreCache = false) { |
| 27 | if (CHANGELOG_DISABLED) { |
| 28 | if (process.env.NODE_ENV === 'development') { |
| 29 | console.warn(`Downloading changelog (${feedUrl}) items is disabled.`) |
| 30 | } |
| 31 | return |
| 32 | } |
| 33 | if (!ignoreCache) { |
| 34 | const fromCache = getChangelogItemsFromCache(prefix, feedUrl) |
| 35 | if (fromCache) return fromCache |
| 36 | } |
| 37 | |
| 38 | const feed = await getRssFeed(feedUrl) |
| 39 | |
| 40 | if (!feed || !feed.items) { |
| 41 | console.log(feed) |
| 42 | console.error('feed is not valid or has no items') |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | // only show the first 3 posts |
| 47 | const changelog = feed.items.slice(0, 3).map((item) => { |
| 48 | // remove the prefix if it exists (Ex: 'GitHub Actions: '), where the colon and expected whitespace should be hardcoded. |
| 49 | const title = prefix ? item.title.replace(new RegExp(`^${prefix}`), '') : item.title |
| 50 | return { |
| 51 | // capitalize the first letter of the title |
| 52 | title: title.trim().charAt(0).toUpperCase() + title.slice(1), |
| 53 | date: item.isoDate, |
| 54 | href: item.link, |
| 55 | } |
| 56 | }) |
| 57 | |
| 58 | // We don't cache the raw payload we'd get from the network request |
| 59 | // because it would waste memory. Instead we store the "serialized" |
| 60 | // object that's created from the raw payload. |
| 61 | setChangelogItemsCache(prefix, feedUrl, changelog) |
| 62 | |
| 63 | return changelog |
| 64 | } |
| 65 | |
| 66 | const globalCache = new Map() |
| 67 |
no test coverage detected