forked from gacybercenter/kinetic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChangeLog-generator.js
154 lines (138 loc) · 3.84 KB
/
ChangeLog-generator.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const child = require("child_process");
const fs = require("fs");
const latestTag = child.execSync('git describe --long --tags').toString('utf-8').split('-')[0];
const output = child.execSync(`git log ${latestTag}..HEAD --format=%B%H----DELIMITER----`).toString("utf-8");
const commitsArray = output.split("----DELIMITER----\n")
.map(commit => {
const [message, sha] = commit.split("\n");
return { sha, message };
})
.filter(commit => Boolean(commit.sha));
const currentChangelog = fs.readFileSync("./CHANGELOG.md", "utf-8");
const newVersion = Number(require("./package.json").version);
let newChangelog = `# Version: GCR.RC.${newVersion} (${
new Date().toISOString().split("T")[0]
})\n\n`;
//List initialization
const features = [];
const chores = [];
const bugs = [];
const builds = [];
const documents = [];
const general = [];
commitsArray.forEach(commit => {
if (commit.message.startsWith("feat: ")) {
features.push(
`* ${commit.message.replace("feat: ", "")} ([${commit.sha.substring(
0,
6
)}](https://gitlab.com/gacybercenter/orchestration/-/commit/${
commit.sha
}))\n`
);
}
else if (commit.message.startsWith("chore: ")) {
chores.push(
`* ${commit.message.replace("chore: ", "")} ([${commit.sha.substring(
0,
6
)}](https://gitlab.com/gacybercenter/orchestration/-/commit/${
commit.sha
}))\n`
);
}
else if (commit.message.startsWith("fix: ")) {
bugs.push(
`* ${commit.message.replace("fix: ", "")} ([${commit.sha.substring(
0,
6
)}](https://gitlab.com/gacybercenter/orchestration/-/commit/${
commit.sha
}))\n`
);
}
else if (commit.message.startsWith("build: ")) {
builds.push(
`* ${commit.message.replace("build: ", "")} ([${commit.sha.substring(
0,
6
)}](https://gitlab.com//gacybercenter/orchestration/commit/${
commit.sha
}))\n`
);
}
else if (commit.message.startsWith("doc: ")) {
documents.push(
`* ${commit.message.replace("doc: ", "")} ([${commit.sha.substring(
0,
6
)}](https://gitlab.com//gacybercenter/orchestration/commit/${
commit.sha
}))\n`
);
}
else {
general.push(
`* ${commit.message} ([${commit.sha.substring(
0,
6
)}](https://gitlab.com//gacybercenter/orchestration/commit/${
commit.sha
}))\n`
);
}
});
if (features.length) {
newChangelog += `## Feature\n`;
features.forEach(feature => {
newChangelog += feature;
});
newChangelog += '\n';
}
if (chores.length) {
newChangelog += `## Chore\n`;
chores.forEach(chore => {
newChangelog += chore;
});
newChangelog += '\n';
}
if (bugs.length) {
newChangelog += `## Bug Fix\n`;
bugs.forEach(bug => {
newChangelog += bug;
});
newChangelog += '\n';
}
if (builds.length) {
newChangelog += `## System Configuration\n`;
builds.forEach(build => {
newChangelog += build;
});
newChangelog += '\n';
}
if (documents.length) {
newChangelog += `## Documentation\n`;
documents.forEach(doc => {
newChangelog += doc;
});
newChangelog += '\n';
}
if (general.length) {
newChangelog += `## Other\n`;
general.forEach(gen => {
newChangelog += gen;
});
newChangelog += '\n';
}
// create a new commit
child.execSync('git add .');
child.execSync(`git commit -m "chore: Bump to version GCR.RC.${newVersion}"`);
child.execSync('git push');
// prepend the newChangelog to the current one
fs.writeFileSync("./CHANGELOG.md", `${newChangelog}${currentChangelog}`);
child.execSync('git add .');
child.execSync(`git commit -m "chore: Automated ChangeLog Content Update."`);
child.execSync('git push');
// tag the commit
child.execSync(`git tag -a -m "Tag for version GCR.RC.${newVersion}" GCR.RC.${newVersion}`);
child.execSync(`git push origin --tags`);