Skip to content

Commit 8367194

Browse files
committed
New field and endpoint to rename automated publishing to generic.
1 parent aeb0f44 commit 8367194

File tree

15 files changed

+186
-116
lines changed

15 files changed

+186
-116
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Important changes to data models, configuration, and migrations between each
22
AppEngine version, listed here to ease deployment and troubleshooting.
33

44
## Next Release (replace with git tag when deployed)
5+
* Note: new `Package.publishingConfig` field in Datastore, new `PUT /api/packages/<package>/publishing` endpoint.
56

67
## `20251023t081900-all`
78
* Bump runtimeVersion to `2025.10.22`.

app/lib/frontend/handlers/pubapi.client.dart

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/lib/frontend/handlers/pubapi.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,17 @@ class PubApi {
402402
) => putPackageOptionsHandler(request, package, body);
403403

404404
@EndPoint.put('/api/packages/<package>/automated-publishing')
405-
Future<AutomatedPublishingConfig> setAutomatedPublishing(
405+
Future<PkgPublishingConfig> setAutomatedPublishing(
406406
Request request,
407407
String package,
408-
AutomatedPublishingConfig body,
408+
PkgPublishingConfig body,
409+
) => packageBackend.setAutomatedPublishing(package, body);
410+
411+
@EndPoint.put('/api/packages/<package>/publishing')
412+
Future<PkgPublishingConfig> setPackagePublishing(
413+
Request request,
414+
String package,
415+
PkgPublishingConfig body,
409416
) => packageBackend.setAutomatedPublishing(package, body);
410417

411418
@EndPoint.get('/api/packages/<package>/versions/<version>/options')

app/lib/frontend/handlers/pubapi.g.dart

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/lib/frontend/templates/views/pkg/admin_page.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ d.Node packageAdminPageNode({
314314
}
315315

316316
d.Node _automatedPublishing(Package package) {
317-
final github = package.automatedPublishing?.githubConfig;
318-
final gcp = package.automatedPublishing?.gcpConfig;
317+
final github = package.publishingConfig?.githubConfig;
318+
final gcp = package.publishingConfig?.gcpConfig;
319319
final isGitHubEnabled = github?.isEnabled ?? false;
320320
return d.fragment([
321321
d.a(name: 'automated-publishing'),
@@ -469,7 +469,7 @@ d.Node _automatedPublishing(Package package) {
469469
}
470470

471471
d.Node _manualPublishing(Package package) {
472-
final manual = package.automatedPublishing?.manualConfig;
472+
final manual = package.publishingConfig?.manualConfig;
473473
return d.fragment([
474474
d.a(name: 'manual-publishing'),
475475
d.h3(text: 'Manual publishing'),

app/lib/package/backend.dart

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,9 @@ class PackageBackend {
624624

625625
/// Verifies an update to the credential-less publishing settings and
626626
/// updates the Datastore entity if everything is valid.
627-
Future<api.AutomatedPublishingConfig> setAutomatedPublishing(
627+
Future<api.PkgPublishingConfig> setAutomatedPublishing(
628628
String package,
629-
api.AutomatedPublishingConfig body,
629+
api.PkgPublishingConfig body,
630630
) async {
631631
final authenticatedUser = await requireAuthenticatedWebUser();
632632
final user = authenticatedUser.user;
@@ -714,30 +714,30 @@ class PackageBackend {
714714
}
715715

716716
// update lock
717-
final current = p.automatedPublishing;
717+
final current = p.publishingConfig;
718718
final githubChanged =
719719
(githubConfig?.isEnabled != current?.githubConfig?.isEnabled) ||
720720
(githubConfig?.repository != current?.githubConfig?.repository);
721721
if (githubChanged) {
722-
p.automatedPublishing?.githubLock = null;
722+
p.publishingConfig?.githubLock = null;
723723
}
724724
final gcpChanged =
725725
(gcpConfig?.isEnabled != current?.gcpConfig?.isEnabled) ||
726726
(gcpConfig?.serviceAccountEmail !=
727727
current?.gcpConfig?.serviceAccountEmail);
728728
if (gcpChanged) {
729-
p.automatedPublishing?.gcpLock = null;
729+
p.publishingConfig?.gcpLock = null;
730730
}
731731

732732
// finalize changes
733-
final automatedPublishing = p.automatedPublishing ??=
734-
AutomatedPublishing();
735-
automatedPublishing.githubConfig =
736-
githubConfig ?? automatedPublishing.githubConfig;
737-
automatedPublishing.gcpConfig =
738-
gcpConfig ?? automatedPublishing.gcpConfig;
739-
automatedPublishing.manualConfig =
740-
manualConfig ?? automatedPublishing.manualConfig;
733+
final publishingConfig = p.publishingConfig ?? PublishingConfig();
734+
p.automatedPublishing = publishingConfig;
735+
p.newPublishingConfig = publishingConfig;
736+
publishingConfig.githubConfig =
737+
githubConfig ?? publishingConfig.githubConfig;
738+
publishingConfig.gcpConfig = gcpConfig ?? publishingConfig.gcpConfig;
739+
publishingConfig.manualConfig =
740+
manualConfig ?? publishingConfig.manualConfig;
741741

742742
p.updated = clock.now().toUtc();
743743
tx.insert(p);
@@ -748,10 +748,10 @@ class PackageBackend {
748748
user: user,
749749
),
750750
);
751-
return api.AutomatedPublishingConfig(
752-
github: p.automatedPublishing!.githubConfig,
753-
gcp: p.automatedPublishing!.gcpConfig,
754-
manual: p.automatedPublishing!.manualConfig,
751+
return api.PkgPublishingConfig(
752+
github: p.publishingConfig!.githubConfig,
753+
gcp: p.publishingConfig!.gcpConfig,
754+
manual: p.publishingConfig!.manualConfig,
755755
);
756756
});
757757
}
@@ -1617,7 +1617,7 @@ class PackageBackend {
16171617
if (agent is AuthenticatedUser &&
16181618
await packageBackend.isPackageAdmin(package, agent.user.userId)) {
16191619
final isEnabled =
1620-
package.automatedPublishing?.manualConfig?.isEnabled ?? true;
1620+
package.publishingConfig?.manualConfig?.isEnabled ?? true;
16211621
if (!isEnabled) {
16221622
throw AuthorizationException.manualPublishingDisabled(package.name!);
16231623
}
@@ -1647,8 +1647,8 @@ class PackageBackend {
16471647
Package package,
16481648
String newVersion,
16491649
) async {
1650-
final githubConfig = package.automatedPublishing?.githubConfig;
1651-
final githubLock = package.automatedPublishing?.githubLock;
1650+
final githubConfig = package.publishingConfig?.githubConfig;
1651+
final githubLock = package.publishingConfig?.githubLock;
16521652

16531653
if (githubConfig?.isEnabled != true) {
16541654
throw AuthorizationException.githubActionIssue(
@@ -1722,7 +1722,7 @@ class PackageBackend {
17221722
);
17231723
await withRetryTransaction(db, (tx) async {
17241724
final p = await tx.lookupValue<Package>(package.key);
1725-
p.automatedPublishing!.githubConfig!.isEnabled = false;
1725+
p.publishingConfig!.githubConfig!.isEnabled = false;
17261726
tx.insert(p);
17271727
});
17281728
throw AuthorizationException.githubActionIssue(
@@ -1737,8 +1737,8 @@ class PackageBackend {
17371737
Package package,
17381738
String newVersion,
17391739
) async {
1740-
final gcpConfig = package.automatedPublishing?.gcpConfig;
1741-
final gcpLock = package.automatedPublishing?.gcpLock;
1740+
final gcpConfig = package.publishingConfig?.gcpConfig;
1741+
final gcpLock = package.publishingConfig?.gcpLock;
17421742
if (gcpConfig?.isEnabled != true) {
17431743
throw AuthorizationException.serviceAccountPublishingIssue(
17441744
'publishing with service account is not enabled',
@@ -1766,7 +1766,7 @@ class PackageBackend {
17661766
);
17671767
await withRetryTransaction(db, (tx) async {
17681768
final p = await tx.lookupValue<Package>(package.key);
1769-
p.automatedPublishing!.gcpConfig!.isEnabled = false;
1769+
p.publishingConfig!.gcpConfig!.isEnabled = false;
17701770
tx.insert(p);
17711771
});
17721772
throw AuthorizationException.githubActionIssue(
@@ -2008,7 +2008,7 @@ class PackageBackend {
20082008
Package package,
20092009
AuthenticatedAgent agent,
20102010
) {
2011-
final current = package.automatedPublishing;
2011+
final current = package.publishingConfig;
20122012
if (current == null) {
20132013
if (agent is AuthenticatedGitHubAction ||
20142014
agent is AuthenticatedGcpServiceAccount) {

app/lib/package/models.dart

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,15 @@ class Package extends db.ExpandoModel<String> {
149149
@db.StringListProperty()
150150
List<String>? deletedVersions;
151151

152-
/// Scheduling state for all versions of this package.
153-
@AutomatedPublishingProperty()
154-
AutomatedPublishing? automatedPublishing;
152+
/// The configuration for automated and manual publishing.
153+
@PublishingConfigProperty()
154+
PublishingConfig? automatedPublishing;
155+
156+
@PublishingConfigProperty(propertyName: 'publishingConfig')
157+
PublishingConfig? newPublishingConfig;
158+
159+
PublishingConfig? get publishingConfig =>
160+
newPublishingConfig ?? automatedPublishing;
155161

156162
/// The latest point in time at which a security advisory that affects this
157163
/// package has been synchronized into pub.
@@ -455,33 +461,31 @@ class Release {
455461
}
456462

457463
@JsonSerializable(explicitToJson: true, includeIfNull: false)
458-
class AutomatedPublishing {
464+
class PublishingConfig {
459465
GitHubPublishingConfig? githubConfig;
460466
GitHubPublishingLock? githubLock;
461467
GcpPublishingConfig? gcpConfig;
462468
GcpPublishingLock? gcpLock;
463469
ManualPublishingConfig? manualConfig;
464470

465-
AutomatedPublishing({
471+
PublishingConfig({
466472
this.githubConfig,
467473
this.githubLock,
468474
this.gcpConfig,
469475
this.gcpLock,
470476
this.manualConfig,
471477
});
472478

473-
factory AutomatedPublishing.fromJson(Map<String, dynamic> json) =>
474-
_$AutomatedPublishingFromJson(json);
479+
factory PublishingConfig.fromJson(Map<String, dynamic> json) =>
480+
_$PublishingConfigFromJson(json);
475481

476-
Map<String, dynamic> toJson() => _$AutomatedPublishingToJson(this);
482+
Map<String, dynamic> toJson() => _$PublishingConfigToJson(this);
477483
}
478484

479-
/// A [db.Property] encoding [AutomatedPublishing] as JSON.
480-
class AutomatedPublishingProperty extends db.Property {
481-
const AutomatedPublishingProperty({
482-
super.propertyName,
483-
super.required = false,
484-
}) : super(indexed: false);
485+
/// A [db.Property] encoding [PublishingConfig] as JSON.
486+
class PublishingConfigProperty extends db.Property {
487+
const PublishingConfigProperty({super.propertyName, super.required = false})
488+
: super(indexed: false);
485489

486490
@override
487491
Object? encodeValue(
@@ -490,21 +494,21 @@ class AutomatedPublishingProperty extends db.Property {
490494
bool forComparison = false,
491495
}) {
492496
if (value == null) return null;
493-
return json.encode(value as AutomatedPublishing);
497+
return json.encode(value as PublishingConfig);
494498
}
495499

496500
@override
497501
Object? decodePrimitiveValue(db.ModelDB mdb, Object? value) {
498502
if (value == null) return null;
499-
return AutomatedPublishing.fromJson(
503+
return PublishingConfig.fromJson(
500504
json.decode(value as String) as Map<String, dynamic>,
501505
);
502506
}
503507

504508
@override
505509
bool validate(db.ModelDB mdb, Object? value) =>
506510
super.validate(mdb, value) &&
507-
(value == null || value is AutomatedPublishing);
511+
(value == null || value is PublishingConfig);
508512
}
509513

510514
@JsonSerializable(explicitToJson: true, includeIfNull: false)

app/lib/package/models.g.dart

Lines changed: 10 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/lib/tool/backfill/backfill_new_fields.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:logging/logging.dart';
6+
import 'package:pub_dev/package/models.dart';
7+
import 'package:pub_dev/shared/datastore.dart';
68

79
final _logger = Logger('backfill_new_fields');
810

@@ -12,5 +14,14 @@ final _logger = Logger('backfill_new_fields');
1214
/// CHANGELOG.md must be updated with the new fields, and the next
1315
/// release could remove the backfill from here.
1416
Future<void> backfillNewFields() async {
15-
_logger.info('Nothing to backfill.');
17+
_logger.info('Backfill new Package.publishingConfig.');
18+
await for (final p in dbService.query<Package>().run()) {
19+
if (p.automatedPublishing != null && p.newPublishingConfig == null) {
20+
await withRetryTransaction(dbService, (tx) async {
21+
final pkg = await tx.lookupValue<Package>(p.key);
22+
pkg.newPublishingConfig = pkg.automatedPublishing;
23+
tx.insert(pkg);
24+
});
25+
}
26+
}
1627
}

0 commit comments

Comments
 (0)