-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathissue.ts
74 lines (65 loc) · 2.05 KB
/
issue.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
67
68
69
70
71
72
73
74
import { Argv } from "mri";
import consola from "consola";
import { ChangelogConfig } from "../../config";
import { getGitDiff, parseCommits } from "../../git";
import { bumpVersion } from "../../semver";
import { generateMarkDown } from "../../markdown";
/**
* This command will:
* - Get the new version
* - Create a new issue with the changelog
*/
export async function issue(args: Argv, config: ChangelogConfig) {
// Get raw commits from the last release
const rawCommits = await getGitDiff(config.from, config.to);
// Parse commits as conventional commits in order to get the new version
const commits = parseCommits(rawCommits, config).filter(
(c) =>
config.types[c.type] &&
!(c.type === "chore" && c.scope === "deps" && !c.isBreaking)
);
// Get the new version
const bumpOptions = _getBumpVersionOptions(args);
// TODO: create a new function to only get the new version (using semver.inc without bumping package.json)
const newVersion = await bumpVersion(commits, config, bumpOptions);
if (!newVersion) {
consola.error("Unable to bump version based on changes.");
process.exit(1);
}
config.newVersion = newVersion;
// Generate changelog
// TODO: Add a template for the markdown issue body
const markdown = await generateMarkDown(commits, config);
const [currentIssue] = await getGithubIssue(config);
if (currentIssue) {
await updateGithubIssue(config, currentIssue, markdown);
}
// TODO: Add a type for the issue body
const body = {}
await createGithubIssue(config, body);
}
// Duplicated from ./src/commands/default.ts. Can we create a shared function?
function _getBumpVersionOptions(args: Argv): BumpVersionOptions {
for (const type of [
"major",
"premajor",
"minor",
"preminor",
"patch",
"prepatch",
"prerelease",
] as const) {
const value = args[type];
if (value) {
if (type.startsWith("pre")) {
return {
type,
preid: typeof value === "string" ? value : "",
};
}
return {
type,
};
}
}
}