Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
axel-op committed Oct 7, 2019
2 parents 6c8f087 + 4d0fae4 commit d3bd9e3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 45 deletions.
2 changes: 1 addition & 1 deletion app/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ linter:

- prefer_typing_uninitialized_variables
- always_declare_return_types
- always_specify_types
#- always_specify_types

- annotate_overrides

Expand Down
10 changes: 5 additions & 5 deletions app/bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ dynamic main(List<String> args) async {
if (outputPana == null) throw ArgumentError.notNull('outputPana');
final Map<String, dynamic> resultPana = jsonDecode(outputPana);
final Event event = getEvent(jsonDecode(eventPayload));
final Result results = processOutput(resultPana);
final String comment = buildComment(results, event, commitSha);
final Result result = processOutput(resultPana);
final String comment = buildComment(result, event, commitSha);

// Post a comment on GitHub
if (maxScore != null &&
results.healthScore > maxScore &&
results.maintenanceScore > maxScore) {
result.healthScore > maxScore &&
result.maintenanceScore > maxScore) {
stdout.writeln(
'Health score and maintenance score are both higher than the maximum score, so no general commit comment will be made.' +
(results.lineSuggestions.isNotEmpty
(result.lineSuggestions.isNotEmpty
? ' However, specific comments are still posted under each line where static analysis has found an issue.'
: ''));
exitCode = 0;
Expand Down
5 changes: 4 additions & 1 deletion app/lib/result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Result {
final double healthScore;
final double maintenanceScore;
final String panaVersion;
final List<Suggestion> generalSuggestions;
final List<Suggestion> maintenanceSuggestions;
final List<Suggestion> healthSuggestions;
final List<LineSuggestion> lineSuggestions;
Expand All @@ -12,10 +13,12 @@ class Result {
@required this.healthScore,
@required this.maintenanceScore,
@required this.panaVersion,
@required this.generalSuggestions,
@required this.maintenanceSuggestions,
@required this.healthSuggestions,
@required this.lineSuggestions,
}) : assert(maintenanceSuggestions != null),
}) : assert(generalSuggestions != null),
assert(maintenanceSuggestions != null),
assert(healthSuggestions != null),
assert(lineSuggestions != null);
}
Expand Down
84 changes: 46 additions & 38 deletions app/lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ import 'package:app/result.dart';

/// Build message to be posted on GitHub
String buildComment(Result result, Event event, String commitSha) {
final Map<String, List<Suggestion>> suggestions = {
'General': result.generalSuggestions,
'Health': result.healthSuggestions,
'Maintenance': result.maintenanceSuggestions,
};

String comment = '## Package analysis results for commit $commitSha';
comment +=
'\n(version of [pana](https://pub.dev/packages/pana) used: ${result.panaVersion})';
comment +=
'\n\n* Health score is **${result.healthScore.toString()} / 100.0**';
comment +=
'\n* Maintenance score is **${result.maintenanceScore.toString()} / 100.0**';
if (result.healthSuggestions.isNotEmpty ||
result.maintenanceSuggestions.isNotEmpty) {
if (suggestions.values.where((l) => l.isNotEmpty).isNotEmpty) {
comment += '\n\n### Issues';
}
if (result.healthSuggestions.isNotEmpty) {
comment += '\n#### Health';
result.healthSuggestions
.forEach((Suggestion s) => comment += _stringSuggestion(s));
}
if (result.maintenanceSuggestions.isNotEmpty) {
comment += '\n#### Maintenance';
result.maintenanceSuggestions
.forEach((Suggestion s) => comment += _stringSuggestion(s));
for (final MapEntry<String, List<Suggestion>> entry in suggestions.entries) {
if (entry.value.isNotEmpty) {
comment += '\n#### ${entry.key}';
entry.value.forEach((s) => comment += _stringSuggestion(s));
}
}
return comment;
}
Expand All @@ -31,14 +32,14 @@ String _stringSuggestion(Suggestion suggestion) {
String str = '\n* ';
if (suggestion.title != null || suggestion.loss != null) {
str += '**';
if (suggestion.title != null) str += '${suggestion.title} ';
if (suggestion.title != null) str += '${suggestion.title}'.trim();
if (suggestion.loss != null) {
str += '(${suggestion.loss.toString()} points)';
str += ' (${suggestion.loss.toString()} points)';
}
str += '**: ';
}
;
str += suggestion.description.replaceAll(RegExp(r'(\n)+'), '\n * ');
str += suggestion.description.replaceAll(RegExp(r'(\n *)+'), '\n * ');
return str;
}

Expand All @@ -48,25 +49,31 @@ Result processOutput(Map<String, dynamic> output) {
final String panaVersion = output['runtimeInfo']['panaVersion'];
final double healthScore = scores['health'];
final double maintenanceScore = scores['maintenance'];
final List<Suggestion> generalSuggestions = <Suggestion>[];
final List<Suggestion> maintenanceSuggestions = <Suggestion>[];
final List<Suggestion> healthSuggestions = <Suggestion>[];
final List<LineSuggestion> lineSuggestions = <LineSuggestion>[];

if (output.containsKey('suggestions')) {
final List<Map<String, dynamic>> suggestions =
List.castFrom<dynamic, Map<String, dynamic>>(output['suggestions']);
maintenanceSuggestions.addAll(_parseSuggestions(suggestions));
}
final Map<String, void Function(List<Suggestion>)> categories = {
'health': (suggestions) => healthSuggestions.addAll(suggestions),
'maintenance': (suggestions) => maintenanceSuggestions.addAll(suggestions),
};

if (output.containsKey('health')) {
final Map<String, dynamic> health = output['health'];
if (health.containsKey('suggestions')) {
final List<Map<String, dynamic>> suggestions =
List.castFrom<dynamic, Map<String, dynamic>>(health['suggestions']);
healthSuggestions.addAll(_parseSuggestions(suggestions));
const String suggestionKey = 'suggestions';

for (final String key in categories.keys) {
if (output.containsKey(key)) {
final Map<String, dynamic> category = output[key];
if (category.containsKey(suggestionKey)) {
categories[key](_parseSuggestions(category[suggestionKey]));
}
}
}

if (output.containsKey(suggestionKey)) {
generalSuggestions.addAll(_parseSuggestions(output[suggestionKey]));
}

if (output.containsKey('dartFiles')) {
final Map<String, dynamic> dartFiles = output['dartFiles'];
for (final String file in dartFiles.keys) {
Expand All @@ -75,12 +82,11 @@ Result processOutput(Map<String, dynamic> output) {
final List<Map<String, dynamic>> problems =
List.castFrom<dynamic, Map<String, dynamic>>(
details['codeProblems']);
lineSuggestions.addAll(
problems.map((Map<String, dynamic> jsonObj) => LineSuggestion(
lineNumber: jsonObj['line'],
description: jsonObj['description'],
relativePath: jsonObj['file'],
)));
lineSuggestions.addAll(problems.map((jsonObj) => LineSuggestion(
lineNumber: jsonObj['line'],
description: jsonObj['description'],
relativePath: jsonObj['file'],
)));
}
}
}
Expand All @@ -89,16 +95,18 @@ Result processOutput(Map<String, dynamic> output) {
panaVersion: panaVersion,
maintenanceScore: maintenanceScore,
healthScore: healthScore,
generalSuggestions: generalSuggestions,
maintenanceSuggestions: maintenanceSuggestions,
healthSuggestions: healthSuggestions,
lineSuggestions: lineSuggestions,
);
}

List<Suggestion> _parseSuggestions(List<Map<String, dynamic>> list) => list
.map((Map<String, dynamic> s) => Suggestion(
description: s['description'],
title: s['title'],
loss: s['score'],
))
.toList();
List<Suggestion> _parseSuggestions(List<dynamic> list) =>
List.castFrom<dynamic, Map<String, dynamic>>(list)
.map((s) => Suggestion(
description: s['description'],
title: s['title'],
loss: s['score'],
))
.toList();
Binary file modified example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit d3bd9e3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package analysis results for commit d3bd9e3

(version of pana used: 0.12.21)

  • Health score is 99.5 / 100.0
  • Maintenance score is 50.0 / 100.0

Issues

Health

  • Fix lib/test_package.dart. (0.5 points): Analysis of lib/test_package.dart reported 1 hint:
    • line 12 col 22: 'value' is deprecated and shouldn't be used.

Maintenance

  • Homepage URL isn't helpful. (10.0 points): Update the homepage field from pubspec.yaml: link to a website about the package or use the source repository URL.
  • The package description is too short. (20.0 points): Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.
  • Maintain an example. (10.0 points): Create a short demo in the example/ directory to show how to use this package.
    • Common filename patterns include main.dart, example.dart, and test_package.dart. Packages with multiple examples should provide example/README.md.
    • For more information see the pub package layout conventions.
  • Package is pre-v0.1 release. (10.0 points): While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Please sign in to comment.