Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit 2ababbd

Browse files
committed
fix(changelog): group changelog item rows by key feature change
1 parent 2367050 commit 2ababbd

File tree

4 files changed

+45
-27
lines changed

4 files changed

+45
-27
lines changed

lib/utils/changelog/changelog.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ class Changelog {
99
String? motd;
1010

1111
@JsonKey(name: 'feat')
12-
List<Change>? feat;
12+
Map<String, List<Change>>? feat;
1313

1414
@JsonKey(name: 'refactor')
15-
List<Change>? tweaks;
15+
Map<String, List<Change>>? tweaks;
1616

1717
@JsonKey(name: 'fix')
18-
List<Change>? fixes;
18+
Map<String, List<Change>>? fixes;
1919

2020
@JsonKey(name: 'docs')
21-
List<Change>? docs;
21+
Map<String, List<Change>>? docs;
2222

2323
@JsonKey(name: 'chore')
24-
List<Change>? chores;
24+
Map<String, List<Change>>? chores;
2525

2626
Changelog({
2727
this.motd,

lib/utils/changelog/sheet.dart

+13-10
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import 'package:lunasea/system/build.dart';
55
import 'package:lunasea/system/environment.dart';
66
import 'package:lunasea/system/flavor.dart';
77
import 'package:lunasea/system/logger.dart';
8-
import 'package:lunasea/utils/links.dart';
9-
import 'package:lunasea/vendor.dart';
108
import 'package:lunasea/utils/changelog/change.dart';
119
import 'package:lunasea/utils/changelog/changelog.dart';
10+
import 'package:lunasea/utils/links.dart';
11+
import 'package:lunasea/vendor.dart';
1212
import 'package:lunasea/widgets/ui.dart';
1313

1414
class ChangelogSheet extends LunaBottomModalSheet {
@@ -88,18 +88,21 @@ class ChangelogSheet extends LunaBottomModalSheet {
8888
);
8989
}
9090

91-
List<Widget> _buildChangeBlock(String header, List<Change>? changes) {
91+
List<Widget> _buildChangeBlock(
92+
String header,
93+
Map<String, List<Change>>? changes,
94+
) {
9295
if (changes == null || changes.isEmpty) return [];
96+
final keys = changes.keys.toList()..sort();
9397
return [
9498
LunaHeader(text: header),
9599
LunaTableCard(
96-
content: List<LunaTableContent>.generate(
97-
changes.length,
98-
(i) => LunaTableContent(
99-
body: changes[i].message.bulleted(),
100-
url: LunaBuild().getCommitUrl(changes[i].commit),
101-
),
102-
),
100+
content: keys.map<LunaTableContent>((feature) {
101+
final combined = changes[feature]!.map((i) {
102+
return i.message.bulleted();
103+
}).join('\n');
104+
return LunaTableContent(title: feature, body: combined);
105+
}).toList(),
103106
),
104107
];
105108
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"fastlane:update:macos": "cd macos && bundle update",
2424
"generate": "npm run generate:environment && npm run generate:assets && npm run generate:build_runner && npm run generate:localization",
2525
"generate:assets": "dart pub global activate spider && spider build",
26-
"generate:build_runner": "flutter packages pub run build_runner build",
26+
"generate:build_runner": "flutter packages pub run build_runner build --delete-conflicting-outputs",
2727
"generate:environment": "flutter pub run environment_config:generate",
2828
"generate:localization": "dart ./scripts/generate_localization.dart",
2929
"git:ignore": "npm run git:ignore:firebase && npm run git:ignore:changelog",

scripts/generate_changelog.dart

+26-11
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,29 @@ Future<void> main(List<String> args) async {
1919
if (type.isNotEmpty && results[type] != null) {
2020
results[type]!.add({
2121
"commit": commit,
22-
"message": parsed,
22+
"feature": parsed[0],
23+
"message": parsed[1],
2324
});
2425
}
2526
}
2627

27-
export(args[0], results);
28+
final output = results.map((k, v) => MapEntry(k, groupContent(v)));
29+
export(args[0], output);
30+
}
31+
32+
Map<String, List<Map>> groupContent(List<dynamic> items) {
33+
Map<String, List<Map>> results = {};
34+
for (final item in items) {
35+
results[item['feature']] ??= [];
36+
results[item['feature']]!.add({
37+
'commit': item['commit'],
38+
'message': item['message'],
39+
});
40+
}
41+
results.values.forEach((items) {
42+
items.sort((a, b) => a['message'].compareTo(b['message']));
43+
});
44+
return results;
2845
}
2946

3047
void export(String flavor, Map<String, dynamic> results) {
@@ -40,7 +57,6 @@ void loadCommitTypes(Map<String, dynamic> results) {
4057
final file = File('.czrc');
4158
final config = json.decode(file.readAsStringSync());
4259

43-
results['motd'] = '';
4460
for (final key in (config['types'] as Map).keys) {
4561
results[key] = [];
4662
}
@@ -51,16 +67,14 @@ String parseCommitType(String commit) {
5167
return type.split('(')[0];
5268
}
5369

54-
String parseCommitMessage(String commit, String type) {
70+
List<String> parseCommitMessage(String commit, String type) {
5571
final index = type.length;
5672
final endIndex = commit.indexOf(':');
57-
58-
if (commit[index] == '(') {
59-
final feature = commit.substring(index + 1, endIndex - 1);
60-
final message = commit.substring(endIndex + 2);
61-
return '$feature: $message';
62-
}
63-
return commit.substring(endIndex + 2);
73+
final message = commit.substring(endIndex + 2);
74+
final feature = commit[index] == '('
75+
? commit.substring(index + 1, endIndex - 1)
76+
: 'other';
77+
return [feature, message];
6478
}
6579

6680
Future<List<String>> getChanges(String flavor) async {
@@ -85,5 +99,6 @@ Future<List<String>> getChanges(String flavor) async {
8599
'-n ${(currentVersion - lastVersion).toString()}',
86100
]);
87101

102+
if ((messages.stdout as String).isEmpty) return [];
88103
return (messages.stdout as String).trim().split('\n');
89104
}

0 commit comments

Comments
 (0)