-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
51 lines (46 loc) · 1.38 KB
/
script.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
/**
* Find releases in repositories. Pass an optional `since` option (`YYYY-MM-dd`) to ignore
* releases prior a set date
*
* @param {import('@octoherd/cli').Octokit} octokit
* @param {import('@octoherd/cli').Repository} repository
* @param { {since?: string} } options Custom user options passed to the CLI
*/
export async function script(octokit, repository, options) {
const since = options.since || "";
const owner = repository.owner.login;
const repo = repository.name;
// https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#list-releases
const allReleases = await octokit.paginate(
"GET /repos/{owner}/{repo}/releases",
{
owner,
repo,
per_page: 100,
}
);
const releases = allReleases.filter((release) => {
return since ? release.created_at > String(since) : true;
});
octokit.log.info(
{
releases: releases.map((release) => {
const type = /\.0\.0$/.test(release.tag_name)
? "breaking"
: /\.0$/.test(release.tag_name)
? "feature"
: "fix";
return {
created_at: release.created_at,
version: release.tag_name,
notes: release.body,
type,
};
}),
repository: [owner, repo].join("/"),
},
`${releases.length} releases found in ${repository.html_url}${
since ? ` since ${since}` : ""
}`
);
}