Skip to content

Commit 86c4a66

Browse files
authored
Versioning script improvements (#943)
* More types * Show type in changelog
1 parent 0b7d9f5 commit 86c4a66

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

.changes/.gitkeep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

scripts/create_version.dart

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import 'dart:io';
2323
///
2424
/// Where:
2525
/// - level: One of [patch, minor, major] indicating the version bump level
26-
/// - kind: One of [added, changed, fixed] indicating the type of change
26+
/// - kind: One of [added, changed, fixed, refactor, performance, security, deprecated, removed, docs, chore]
2727
/// - description: A detailed description of the change
2828
///
2929
/// Examples:
@@ -60,8 +60,15 @@ class _Color {
6060

6161
enum ChangeKind {
6262
added,
63+
changed,
6364
fixed,
64-
changed;
65+
refactor,
66+
performance,
67+
security,
68+
deprecated,
69+
removed,
70+
docs,
71+
chore;
6572

6673
static ChangeKind? fromString(String value) {
6774
return ChangeKind.values.where((e) => e.name == value).firstOrNull;
@@ -108,15 +115,15 @@ class SemanticVersion {
108115
});
109116

110117
factory SemanticVersion.parse(String versionString) {
111-
final parts = versionString.split('.');
112-
if (parts.length != 3) {
118+
final match = RegExp(r'^(\d+)\.(\d+)\.(\d+)(?:[+-].*)?$').firstMatch(versionString);
119+
if (match == null) {
113120
throw FormatException('Invalid version format: $versionString');
114121
}
115122

116123
return SemanticVersion(
117-
major: int.parse(parts[0]),
118-
minor: int.parse(parts[1]),
119-
patch: int.parse(parts[2]),
124+
major: int.parse(match.group(1)!),
125+
minor: int.parse(match.group(2)!),
126+
patch: int.parse(match.group(3)!),
120127
);
121128
}
122129

@@ -202,13 +209,23 @@ String generateChangelogEntry(SemanticVersion version, List<Change> changes) {
202209
buffer.writeln('## $version');
203210
buffer.writeln();
204211

205-
// Group changes by kind
206-
final added = changes.where((c) => c.kind == ChangeKind.added).toList();
207-
final changed = changes.where((c) => c.kind == ChangeKind.changed).toList();
208-
final fixed = changes.where((c) => c.kind == ChangeKind.fixed).toList();
209-
210-
for (final change in [...added, ...changed, ...fixed]) {
211-
buffer.writeln('* ${change.description}');
212+
String prefixFor(ChangeKind kind) => switch (kind) {
213+
ChangeKind.added => 'Added',
214+
ChangeKind.changed => 'Changed',
215+
ChangeKind.fixed => 'Fixed',
216+
ChangeKind.refactor => 'Refactor',
217+
ChangeKind.performance => 'Performance',
218+
ChangeKind.security => 'Security',
219+
ChangeKind.deprecated => 'Deprecated',
220+
ChangeKind.removed => 'Removed',
221+
ChangeKind.docs => 'Docs',
222+
ChangeKind.chore => 'Chore',
223+
};
224+
225+
for (final kind in ChangeKind.values) {
226+
for (final change in changes.where((c) => c.kind == kind)) {
227+
buffer.writeln('* ${prefixFor(change.kind)}: ${change.description}');
228+
}
212229
}
213230

214231
buffer.writeln();

0 commit comments

Comments
 (0)