Skip to content

Commit

Permalink
Update changelog parser
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodoering committed Apr 20, 2021
1 parent ec078a6 commit 325044e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
11 changes: 7 additions & 4 deletions lib/components/screens/changelog/widgets/changelog_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ class ChangelogWidget extends StatelessWidget {
Widget _buildHeaderText() {
return Column(
children: <Widget>[
for (String headerLine in data.headerLines) ...<Widget>[
for (String headerLine in data.headerLines)
Text(headerLine, textAlign: TextAlign.start),
const SizedBox(height: 12),
],
const SizedBox(height: 12)
],
);
}
Expand All @@ -34,7 +33,11 @@ class ChangelogWidget extends StatelessWidget {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
icon,
Padding(
// move the icon down a bit to make up for the text's line height
padding: const EdgeInsets.only(top: 2),
child: icon,
),
const SizedBox(width: 24),
Expanded(
child: Column(
Expand Down
42 changes: 36 additions & 6 deletions lib/misc/changelog_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:harpy/harpy.dart';

/// Parses the [ChangelogData] from a changelog file located in
/// `android/fastlane/metadata/android/$flavor/en-US/changelogs/$versionCode.txt`.
class ChangelogParser {
class ChangelogParser with HarpyLogger {
static const String linePrefix = '· ';

/// Returns the [ChangelogData] for the current version.
Expand Down Expand Up @@ -35,10 +35,15 @@ class ChangelogParser {
}

final String headerString = changelogString.substring(0, entryStart);
final List<String> headerLines = _cleanEmptyLines(
headerString.split('\n'),
);

for (int i = 0; i < headerLines.length; i++) {
final String line = headerLines[i].trim();

for (String line in headerString.split('\n')) {
line = line.trim();
if (line.isNotEmpty) {
// only add empty lines if they are not the first or last line
if (line.isNotEmpty || i != 0 || i != headerLines.length - 1) {
data.headerLines.add(line);
}
}
Expand Down Expand Up @@ -74,8 +79,10 @@ class ChangelogParser {
}

return data;
} catch (e) {
// changelog file not found
} on FlutterError {
// ignore asset not found exception (version has no changelog)
} catch (e, st) {
log.severe('error parsing changelog data', e, st);
return null;
}
}
Expand All @@ -90,6 +97,29 @@ class ChangelogParser {
ChangelogEntry _parseLine(String line) {
return ChangelogEntry(line: line.trim());
}

List<String> _cleanEmptyLines(List<String> lines) {
lines = _trimLeadingLines(lines);
lines = _trimLeadingLines(lines.reversed.toList());
return lines.reversed.toList();
}

List<String> _trimLeadingLines(List<String> lines) {
final List<String> cleaned = <String>[];

bool ignore = true;
for (String line in lines) {
if (ignore && line.trim().isEmpty) {
continue;
}

ignore = false;

cleaned.add(line.trim());
}

return cleaned;
}
}

/// Represents the data of a changelog for one version.
Expand Down

0 comments on commit 325044e

Please sign in to comment.