forked from flutter/cocoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates github gold status to Firestore (flutter#3513)
Part of flutter/flutter#142951 This PR: 1) starts updating Github Gold Status to Firestore 2) updates status in a try block to avoid breaking prod workflow 3) creates a corresponding Firestore model 4) updates `documentsToWrites` to have default `exists=null` to support generic document writes.
- Loading branch information
Showing
10 changed files
with
266 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2019 The Flutter Authors. 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:cocoon_service/cocoon_service.dart'; | ||
import 'package:github/github.dart'; | ||
import 'package:googleapis/firestore/v1.dart' hide Status; | ||
|
||
import '../../service/firestore.dart'; | ||
|
||
class GithubGoldStatus extends Document { | ||
/// Lookup [GithubGoldStatus] from Firestore. | ||
/// | ||
/// `documentName` follows `/projects/{project}/databases/{database}/documents/{document_path}` | ||
static Future<GithubGoldStatus> fromFirestore({ | ||
required FirestoreService firestoreService, | ||
required String documentName, | ||
}) async { | ||
final Document document = await firestoreService.getDocument(documentName); | ||
return GithubGoldStatus.fromDocument(githubGoldStatus: document); | ||
} | ||
|
||
/// Create [Commit] from a Commit Document. | ||
static GithubGoldStatus fromDocument({ | ||
required Document githubGoldStatus, | ||
}) { | ||
return GithubGoldStatus() | ||
..fields = githubGoldStatus.fields! | ||
..name = githubGoldStatus.name!; | ||
} | ||
|
||
// The flutter-gold status cannot report a `failure` status | ||
// due to auto-rollers. This is why we hold a `pending` status | ||
// when there are image changes. This provides the opportunity | ||
// for images to be triaged, and the auto-roller to proceed. | ||
// For more context, see: https://github.com/flutter/flutter/issues/48744 | ||
|
||
static const String statusCompleted = 'success'; | ||
|
||
static const String statusRunning = 'pending'; | ||
|
||
int? get prNumber => int.parse(fields![kGithubGoldStatusPrNumberField]!.integerValue!); | ||
|
||
String? get head => fields![kGithubGoldStatusHeadField]!.stringValue!; | ||
|
||
String? get status => fields![kGithubGoldStatusStatusField]!.stringValue!; | ||
|
||
String? get description => fields![kGithubGoldStatusDescriptionField]!.stringValue!; | ||
|
||
int? get updates => int.parse(fields![kGithubGoldStatusUpdatesField]!.integerValue!); | ||
|
||
/// A serializable form of [slug]. | ||
/// | ||
/// This will be of the form `<org>/<repo>`. e.g. `flutter/flutter`. | ||
String? get repository => fields![kGithubGoldStatusRepositoryField]!.stringValue!; | ||
|
||
/// [RepositorySlug] of where this commit exists. | ||
RepositorySlug get slug => RepositorySlug.full(repository!); | ||
|
||
@override | ||
String toString() { | ||
final StringBuffer buf = StringBuffer() | ||
..write('$runtimeType(') | ||
..write(', $kGithubGoldStatusPrNumberField: $prNumber') | ||
..write(', $kGithubGoldStatusHeadField: $head') | ||
..write(', $kGithubGoldStatusStatusField: $status') | ||
..write(', $kGithubGoldStatusDescriptionField $description') | ||
..write(', $kGithubGoldStatusUpdatesField: $updates') | ||
..write(', $kGithubGoldStatusRepositoryField: $repository') | ||
..write(')'); | ||
return buf.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app_dart/test/model/firestore/github_gold_status_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2019 The Flutter Authors. 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:cocoon_service/src/model/firestore/github_gold_status.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../../src/utilities/entity_generators.dart'; | ||
import '../../src/utilities/mocks.dart'; | ||
|
||
void main() { | ||
group('GithubGoldStatus.fromFirestore', () { | ||
late MockFirestoreService mockFirestoreService; | ||
|
||
setUp(() { | ||
mockFirestoreService = MockFirestoreService(); | ||
}); | ||
|
||
test('generates githubGoldStatus correctly', () async { | ||
final GithubGoldStatus githubGoldStatus = generateFirestoreGithubGoldStatus(1); | ||
when( | ||
mockFirestoreService.getDocument( | ||
captureAny, | ||
), | ||
).thenAnswer((Invocation invocation) { | ||
return Future<GithubGoldStatus>.value( | ||
githubGoldStatus, | ||
); | ||
}); | ||
final GithubGoldStatus resultedGithubGoldStatus = await GithubGoldStatus.fromFirestore( | ||
firestoreService: mockFirestoreService, | ||
documentName: 'test', | ||
); | ||
expect(resultedGithubGoldStatus.name, githubGoldStatus.name); | ||
expect(resultedGithubGoldStatus.fields, githubGoldStatus.fields); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.