Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions app/lib/tool/test_profile/import_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ class ImportSource {
}

/// Resolve all the package-version required for the [profile].
Future<List<ResolvedVersion>> resolveVersions(TestProfile profile) async {
return <ResolvedVersion>[
...await resolver.resolveVersions(_client, profile),
...await _resolveGeneratedVersions(profile),
];
Future<List<ResolvedVersion>> resolveImportedVersions(
TestProfile profile) async {
return await resolver.resolveVersions(_client, profile);
}

Future<List<ResolvedVersion>> _resolveGeneratedVersions(
Future<List<ResolvedVersion>> resolveGeneratedVersions(
TestProfile profile) async {
final versions = <ResolvedVersion>[];
profile.generatedPackages.forEach((p) {
Expand Down
24 changes: 15 additions & 9 deletions app/lib/tool/test_profile/importer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ Future<void> importProfile({
String? adminUserEmail,
}) async {
source ??= ImportSource();
final resolvedVersions = await source.resolveVersions(profile);
resolvedVersions.sort();
final importedVersions = await source.resolveImportedVersions(profile);
final generatedVersions = await source.resolveGeneratedVersions(profile);
final resolvedVersions = [...importedVersions, ...generatedVersions]..sort();

// expand profile with resolved version information
profile = normalize(profile, resolvedVersions: resolvedVersions);
profile = normalize(profile);

if (profile.importedPackages
.any((p) => p.uploaders != null && p.uploaders!.length > 1)) {
Expand Down Expand Up @@ -97,11 +98,12 @@ Future<void> importProfile({
lastActiveUploaderEmails[rv.package] = uploaderEmail;

var bytes = pendingBytes['${rv.package}/${rv.version}'] ??
(profile.isGenerated(rv.package, rv.version)
? await source.getGeneratedArchiveBytes(rv.package, rv.version)
: await source.getPubDevArchiveBytes(rv.package, rv.version));
(importedVersions.contains(rv)
? await source.getPubDevArchiveBytes(rv.package, rv.version)
: await source.getGeneratedArchiveBytes(rv.package, rv.version));
bytes = await _mayCleanupTarModeBits(bytes);
try {
// TODO: use the created field with fake clock header to set the published timestamp
await withRetryPubApiClient(
authToken: createFakeAuthTokenForEmail(uploaderEmail,
audience: activeConfiguration.pubClientAudience),
Expand Down Expand Up @@ -232,9 +234,13 @@ Future<void> importProfile({
}

List<String> _potentialActiveEmails(TestProfile profile, String packageName) {
final testPackage =
profile.importedPackages.firstWhereOrNull((p) => p.name == packageName) ??
profile.generatedPackages.firstWhere((p) => p.name == packageName);
final testPackage = profile.importedPackages
.firstWhereOrNull((p) => p.name == packageName) ??
profile.generatedPackages.firstWhereOrNull((p) => p.name == packageName);

if (testPackage == null) {
return [profile.resolvedDefaultUser];
}

// uploaders
if (testPackage.publisher == null) {
Expand Down
24 changes: 0 additions & 24 deletions app/lib/tool/test_profile/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ class TestProfile {
);
}

/// Returns whether the [package]/[version] is part of the generated packages list.
bool isGenerated(String package, String version) {
final p = generatedPackages.firstWhereOrNull((p) => p.name == package);
final v = p?.versions?.firstWhereOrNull((v) => v.version == version);
return v != null;
}

/// The [defaultUser] if specified, otherwise:
/// - the first entry in the [users] list,
/// - the first specified member in the [publishers] list,
Expand Down Expand Up @@ -116,23 +109,6 @@ class TestPackage {
}

Map<String, dynamic> toJson() => _$TestPackageToJson(this);

TestPackage change({
List<TestVersion>? versions,
}) {
return TestPackage(
name: name,
uploaders: uploaders,
publisher: publisher,
versions: versions ?? this.versions,
replacedBy: replacedBy,
isDiscontinued: isDiscontinued,
isUnlisted: isUnlisted,
isFlutterFavorite: isFlutterFavorite,
retractedVersions: retractedVersions,
likeCount: likeCount,
);
}
}

@JsonSerializable(explicitToJson: true, includeIfNull: false)
Expand Down
42 changes: 1 addition & 41 deletions app/lib/tool/test_profile/normalizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import 'models.dart';

/// Creates a new TestProfile with the missing entities (e.g. users or publishers)
/// created.
TestProfile normalize(
TestProfile profile, {
List<ResolvedVersion>? resolvedVersions,
}) {
TestProfile normalize(TestProfile profile) {
final users = <String, TestUser>{};
final publishers = <String, TestPublisher>{};
final importedPackages = <String, TestPackage>{};
Expand Down Expand Up @@ -42,43 +39,6 @@ TestProfile normalize(
});
});

// add missing packages from resolved versions
if (resolvedVersions != null) {
resolvedVersions.forEach((rv) {
if (generatedPackages.containsKey(rv.package)) {
return;
}
importedPackages.putIfAbsent(
rv.package,
() => TestPackage(
name: rv.package,
versions: [
TestVersion(version: rv.version, created: rv.created),
],
uploaders: [profile.resolvedDefaultUser],
));
});
// update versions from resolved versions
List<TestVersion> getUpdateVersions(TestPackage p) {
return resolvedVersions
.where((rv) => rv.package == p.name)
.map((rv) => rv.version)
.toSet()
.map((v) => TestVersion(
version: v,
created:
resolvedVersions.firstWhere((x) => x.version == v).created))
.toList();
}

importedPackages.values.toList().forEach((p) {
importedPackages[p.name] = p.change(versions: getUpdateVersions(p));
});
generatedPackages.values.toList().forEach((p) {
generatedPackages[p.name] = p.change(versions: getUpdateVersions(p));
});
}

final publishersToCreate = {
...importedPackages.values.map((p) => p.publisher).nonNulls,
...generatedPackages.values.map((p) => p.publisher).nonNulls,
Expand Down
39 changes: 0 additions & 39 deletions app/test/tool/test_profile/model_normalization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:clock/clock.dart';
import 'package:pub_dev/tool/test_profile/models.dart';
import 'package:pub_dev/tool/test_profile/normalizer.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -86,43 +85,5 @@ generatedPackages:
},
);
});

test('resolved versions', () {
expect(
normalize(
TestProfile.fromYaml('''
defaultUser: [email protected]
generatedPackages:
- name: foo
'''),
resolvedVersions: [
ResolvedVersion(
package: 'foo',
version: '1.1.0',
created: clock.now(),
),
],
).toJson(),
{
'importedPackages': [],
'generatedPackages': [
{
'name': 'foo',
'versions': [
{'version': '1.1.0', 'created': isNotEmpty},
],
}
],
'publishers': [],
'users': [
{
'email': '[email protected]',
'likes': [],
}
],
'defaultUser': '[email protected]',
},
);
});
});
}