-
Notifications
You must be signed in to change notification settings - Fork 3
/
collect-releases.js
42 lines (36 loc) · 1.55 KB
/
collect-releases.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import ghGot from 'gh-got'
import { md2html, buildRFC822Date, composeFeedItem, getFeedContent, overwriteFeedContent, getConfig } from '../utils/index.js'
const { lastCheckTimestamp, releasePaginationLimit, reposPaginationLimit, breakDelimiter } = getConfig()
// Collect Org Repos
const repos = await ghGot.paginate.all(
'users/nodejs/repos',
{
token: process.env.GITHUB_TOKEN,
pagination: { countLimit: reposPaginationLimit }
}
)
// Collect New Releases
const releases = await Promise.all(repos.map(async repo => {
const repoReleases = await ghGot(
`repos/${repo.full_name}/releases`,
{
token: process.env.GITHUB_TOKEN,
pagination: { countLimit: releasePaginationLimit }
}
).json()
// Select only releases that are newer than the last check and add the repo name
return repoReleases
.filter(rel => new Date(rel.published_at).getTime() > lastCheckTimestamp)
.map(rel => ({ ...rel, repo: repo.full_name }))
}))
const relevantReleases = releases.flat().map(rel => composeFeedItem({
title: `Released ${rel.repo} ${rel.tag_name}`,
description: `<![CDATA[${md2html(`Released ${rel.repo} ${rel.tag_name} by ${rel.author.login}. [More details](${rel.html_url})`)}]]>`,
pubDate: buildRFC822Date(rel.published_at),
link: rel.html_url,
guid: rel.html_url
})).join('')
const feedContent = getFeedContent()
const [before, after] = feedContent.split(breakDelimiter)
const updatedFeedContent = `${before}${breakDelimiter}${relevantReleases}${after}`
overwriteFeedContent(updatedFeedContent)