This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
72 lines (66 loc) · 2.24 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const fetch = require('node-fetch')
const semver = require('semver')
const Octokit = require('@octokit/rest')
const github = new Octokit({auth: process.env.GITHUB_TOKEN})
const PACKAGES = [
{name: '@primer/css', repo: 'primer/css'},
{name: '@primer/components', repo: 'primer/components'},
{name: '@primer/octicons', repo: 'primer/octicons'},
{name: '@primer/view-components', repo: 'primer/view_components'}
].map(pkg => {
pkg.url = `https://github.com/${pkg.repo}`
return pkg
})
module.exports = async () => {
const releases = []
for (const pkg of PACKAGES) {
const npmReleases = await getNpmReleases(pkg)
const githubReleases = await getGitHubReleases(pkg)
console.warn(`[${pkg.name}] got ${npmReleases.length} npm releases, ${githubReleases.length} github`)
for (const npmRelease of npmReleases) {
const {version, date} = npmRelease
const {major, minor, patch, prerelease: [preid]} = semver.parse(version)
if (!preid && patch === 0) {
const tag = `v${version}`
const githubRelease = githubReleases.find(release => release.tag_name === tag)
if (githubRelease) {
const {name: title, body: description} = githubRelease
releases.push({
package: pkg,
version,
semver: {major, minor, patch},
date,
title,
description,
tag,
npm: npmRelease,
github: githubRelease
})
}
}
}
}
releases.sort((a, b) => b.date.localeCompare(a.date))
return {releases, packages: PACKAGES}
}
async function getNpmReleases(pkg) {
const {name, repo, url} = pkg
const packageInfo = await fetch(`https://registry.npmjs.org/${name}`).then(res => res.json())
return Object.keys(packageInfo.versions)
.sort(semver.rcompare)
.map(version => {
return {
name,
version,
repo,
url: `https://www.npmjs.com/package/${name}/v/${version}`,
date: packageInfo.time[version],
packageJSON: packageInfo.versions[version]
}
})
}
async function getGitHubReleases(pkg) {
const [owner, repo] = pkg.repo.split('/')
return await github.repos.listReleases({owner, repo})
.then(res => res.data)
}