forked from justinawrey/shipit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.ts
More file actions
83 lines (71 loc) · 2.08 KB
/
Copy pathgithub.ts
File metadata and controls
83 lines (71 loc) · 2.08 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
import { request } from "@octokit/request";
import git from "./git.ts";
export interface Commits {
major: string[];
minor: string[];
patch: string[];
docs: string[];
other: string[];
}
/**
* Generates the release notes for a given version and {@link Commits}.
* @param version The version to generate notes for.
* @param major The commits that are considered major.
* @param minor The commits that are considered minor.
* @param patch The commits that are considered patch.
* @param docs The commits that are considered docs.
* @param other The commits that are considered other.
* @returns The release notes for the given version.
*/
export function generateReleaseNotes(
version: string,
{ major, minor, patch, docs, other }: 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\n`;
}
if (minor.length) {
notes += `## Features\n\n`;
notes += `${listNotes(minor)}\n\n`;
}
if (patch.length) {
notes += `## Bug Fixes\n\n`;
notes += `${listNotes(patch)}\n\n`;
}
if (docs.length) {
notes += `## Documentation\n\n`;
notes += `${listNotes(docs)}\n\n`;
}
if (other.length) {
notes += `## Other\n\n`;
notes += `${listNotes(other)}\n\n`;
}
return notes;
}
export default {
async release(nextVer: string, releaseNotes: string): Promise<string> {
const { owner, repo } = await git.repoInfo();
// Get the GitHub token from environment variables
const token = Deno.env.get("GITHUB_TOKEN");
if (!token) {
throw new Error("GITHUB_TOKEN environment variable is not set.");
}
// Create a new release using the 'request' function
const res = await request("POST /repos/{owner}/{repo}/releases", {
headers: {
authorization: `token ${token}`,
},
owner,
repo,
name: nextVer,
tag_name: nextVer,
body: releaseNotes,
});
return res.data.html_url;
},
};