-
Notifications
You must be signed in to change notification settings - Fork 1
/
github.ts
66 lines (54 loc) · 1.43 KB
/
github.ts
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
import { Octokit, restEndpointMethods } from "./deps.ts";
import git from "./git.ts";
export interface Commits {
major: string[];
minor: string[];
patch: string[];
docs: string[];
}
function generateNotes(
version: string,
{ major, minor, patch, docs }: Commits,
): string {
function listNotes(notes: string[]): string {
return notes.map((note) => `- ${note}`).join("\n");
}
let notes = `# Version ${version}\n\n`;
if (major.length) {
notes += `## Breaking Changes\n\n`;
notes += `${listNotes(major)}\n`;
}
if (minor.length) {
notes += `## Features\n\n`;
notes += `${listNotes(minor)}\n`;
}
if (patch.length) {
notes += `## Bug Fixes\n\n`;
notes += `${listNotes(patch)}\n`;
}
if (docs.length) {
notes += `## Documentation\n\n`;
notes += `${listNotes(docs)}\n`;
}
return notes;
}
export default {
async release(nextVer: string, commits: Commits): Promise<string> {
const { owner, repo } = await git.repoInfo();
const restOctokit = Octokit.plugin(restEndpointMethods);
const octokit = new restOctokit({
auth: Deno.env.get("GITHUB_TOKEN"),
});
const res = await octokit.rest.repos.createRelease({
owner,
repo,
name: nextVer,
tag_name: nextVer,
body: generateNotes(nextVer, commits),
});
if (res.status !== 201) {
throw new Error(`Github release failed: ${res.status}`);
}
return res.data.html_url;
},
};