Skip to content

Commit

Permalink
Fix scorecard isSkipped status + simpler isPending. (#7031)
Browse files Browse the repository at this point in the history
* Fix scorecard isSkipped status.

* Remove obsolete templates test.

* Fix isPending on score tab.
  • Loading branch information
isoos authored Sep 14, 2023
1 parent 0068d61 commit 05e28f5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 100 deletions.
2 changes: 1 addition & 1 deletion app/lib/frontend/templates/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ String _renderPkgPage({
);
final noIndex = pkgPageTab == urls.PkgPageTab.install ||
pkgPageTab == urls.PkgPageTab.score ||
(card.isSkipped) ||
card.isSkipped ||
(card.grantedPubPoints == 0) ||
data.package.isExcludedInRobots;
return renderLayoutPage(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/frontend/templates/views/pkg/score_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ d.Node scoreTabNode({
}

final report = card.report;
final showPending = !card.isSkipped && report == null;
final showPending = card.isPending;
final showReport = !card.isSkipped && report != null;

final toolEnvInfo = showReport
Expand Down
34 changes: 8 additions & 26 deletions app/lib/package/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import '../shared/model_properties.dart';
import '../shared/popularity_storage.dart';
import '../shared/urls.dart' as urls;
import '../shared/utils.dart';
import '../task/models.dart';

part 'models.g.dart';

Expand Down Expand Up @@ -946,47 +945,30 @@ class PackageView extends Object with FlagMixin {
required Package package,
required LatestReleases releases,
PackageVersion? version,
ScoreCardData? scoreCard,
required ScoreCardData scoreCard,
List<ApiPageRef>? apiPages,
}) {
final hasPanaReport = scoreCard?.hasPanaReport ?? false;
final taskStatus = scoreCard?.taskStatus;
bool isPending = false;
if (taskStatus != null) {
isPending = taskStatus == PackageVersionStatus.pending;
} else {
isPending =
// Job processing has not created any card yet.
(scoreCard == null) ||
// The uploader has recently removed the "discontinued" flag, but the
// analysis did not complete yet.
(scoreCard.isDiscontinued && !package.isDiscontinued) ||
// No blocker for analysis, but no results yet.
(!scoreCard.isSkipped && !hasPanaReport);
}

final tags = <String>{
...package.getTags(),
...?version?.getTags(),
...?scoreCard?.derivedTags,
...?scoreCard.derivedTags,
};
return PackageView(
name: package.name!,
releases: releases,
ellipsizedDescription: version?.ellipsizedDescription,
created: package.created!,
publisherId: package.publisherId,
isPending: isPending,
isPending: scoreCard.isPending,
likes: package.likes,
grantedPubPoints: scoreCard?.grantedPubPoints,
maxPubPoints: scoreCard?.maxPubPoints,
grantedPubPoints: scoreCard.grantedPubPoints,
maxPubPoints: scoreCard.maxPubPoints,
tags: tags.toList(),
replacedBy: package.replacedBy,
spdxIdentifiers: scoreCard?.panaReport?.licenses
?.map((e) => e.spdxIdentifier)
.toList(),
spdxIdentifiers:
scoreCard.panaReport?.licenses?.map((e) => e.spdxIdentifier).toList(),
apiPages: apiPages,
screenshots: scoreCard?.panaReport?.screenshots,
screenshots: scoreCard.panaReport?.screenshots,
topics: version?.pubspec?.topics,
);
}
Expand Down
6 changes: 3 additions & 3 deletions app/lib/scorecard/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ mixin FlagMixin {
tags?.contains(PackageVersionTags.isDart3Incompatible) ?? false;

bool get isObsolete => tags?.contains(PackageVersionTags.isObsolete) ?? false;

bool get isSkipped =>
isDiscontinued || isLegacy || isDart3Incompatible || isObsolete;
}

@JsonSerializable()
Expand Down Expand Up @@ -82,6 +79,9 @@ class ScoreCardData extends Object with FlagMixin {
/// List of tags computed by `pana` or other analyzer.
List<String>? get derivedTags => panaReport?.derivedTags;

bool get isSkipped => taskStatus == null;
// TODO: also consider finished status
bool get isPending => taskStatus == PackageVersionStatus.pending;
bool get hasApiDocs => dartdocReport?.reportStatus == ReportStatus.success;
bool get hasPanaReport => panaReport != null;

Expand Down
38 changes: 0 additions & 38 deletions app/test/frontend/golden/analysis_tab_aborted.html

This file was deleted.

31 changes: 0 additions & 31 deletions app/test/frontend/templates_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -361,37 +361,6 @@ void main() {
'<i>Awaiting analysis to complete.</i>');
});

testWithProfile('aborted analysis tab', fn: () async {
final timestamp = DateTime(2017, 12, 18, 14, 26, 00);
final card = ScoreCardData(
packageName: 'pkg',
panaReport: PanaReport(
timestamp: timestamp,
panaRuntimeInfo: _panaRuntimeInfo,
reportStatus: ReportStatus.aborted,
derivedTags: null,
allDependencies: null,
licenses: null,
report: Report(sections: <ReportSection>[]),
result: null,
urlProblems: null,
screenshots: null,
),
);
final html = scoreTabNode(
card: card,
likeCount: 1000000,
usesFlutter: false,
).toString();

expectGoldenFile(
html,
'analysis_tab_aborted.html',
isFragment: true,
timestamps: {'timestamp': timestamp},
);
});

testWithProfile('outdated analysis tab', fn: () async {
final timestamp = DateTime(2017, 12, 18, 14, 26, 00);
final card = ScoreCardData(
Expand Down

0 comments on commit 05e28f5

Please sign in to comment.