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.
Merge branch 'flutter:main' into main
- Loading branch information
Showing
27 changed files
with
647 additions
and
153 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ dependencies: | |
|
||
dev_dependencies: | ||
mockito: 5.4.4 | ||
test_api: 0.7.0 | ||
test_api: 0.7.1 |
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
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,35 @@ | ||
// 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 'commit.dart'; | ||
import 'task.dart'; | ||
|
||
/// Class that holds the status for all tasks corresponding to a particular | ||
/// commit. | ||
/// | ||
/// Tasks may still be running, and thus their status is subject to change. | ||
/// Put another way, this class holds information that is a snapshot in time. | ||
class CommitTasksStatus { | ||
/// Creates a new [CommitTasksStatus]. | ||
const CommitTasksStatus(this.commit, this.tasks); | ||
|
||
/// The commit against which all the tasks are run. | ||
final Commit commit; | ||
|
||
/// Tasks running against the commit. | ||
final List<Task> tasks; | ||
} | ||
|
||
class SerializableCommitTasksStatus { | ||
const SerializableCommitTasksStatus(this.status); | ||
|
||
final CommitTasksStatus status; | ||
|
||
Map<String, dynamic> toJson() { | ||
return <String, dynamic>{ | ||
'Commit': status.commit.toJson(), | ||
'Tasks': status.tasks, | ||
}; | ||
} | ||
} |
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
85 changes: 85 additions & 0 deletions
85
app_dart/lib/src/request_handlers/get_status_firestore.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,85 @@ | ||
// 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 'dart:async'; | ||
|
||
import 'package:gcloud/db.dart'; | ||
import 'package:github/github.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
import '../model/appengine/commit.dart'; | ||
import '../model/firestore/commit_tasks_status.dart'; | ||
import '../model/appengine/key_helper.dart'; | ||
import '../request_handling/body.dart'; | ||
import '../request_handling/exceptions.dart'; | ||
import '../request_handling/request_handler.dart'; | ||
import '../service/build_status_provider.dart'; | ||
import '../service/config.dart'; | ||
import '../service/datastore.dart'; | ||
import '../service/firestore.dart'; | ||
|
||
@immutable | ||
class GetStatusFirestore extends RequestHandler<Body> { | ||
const GetStatusFirestore({ | ||
required super.config, | ||
@visibleForTesting this.datastoreProvider = DatastoreService.defaultProvider, | ||
@visibleForTesting this.buildStatusProvider = BuildStatusService.defaultProvider, | ||
}); | ||
|
||
final DatastoreServiceProvider datastoreProvider; | ||
final BuildStatusServiceProvider buildStatusProvider; | ||
|
||
static const String kLastCommitKeyParam = 'lastCommitKey'; | ||
static const String kBranchParam = 'branch'; | ||
static const String kRepoParam = 'repo'; | ||
|
||
@override | ||
Future<Body> get() async { | ||
final String? encodedLastCommitKey = request!.uri.queryParameters[kLastCommitKeyParam]; | ||
final String repoName = request!.uri.queryParameters[kRepoParam] ?? Config.flutterSlug.name; | ||
final RepositorySlug slug = RepositorySlug('flutter', repoName); | ||
final String branch = request!.uri.queryParameters[kBranchParam] ?? Config.defaultBranch(slug); | ||
final DatastoreService datastore = datastoreProvider(config.db); | ||
final FirestoreService firestoreService = await config.createFirestoreService(); | ||
final BuildStatusService buildStatusService = buildStatusProvider(datastore, firestoreService); | ||
final KeyHelper keyHelper = config.keyHelper; | ||
final int commitNumber = config.commitNumber; | ||
final int lastCommitTimestamp = await _obtainTimestamp(encodedLastCommitKey, keyHelper, datastore); | ||
|
||
final List<SerializableCommitTasksStatus> statuses = await buildStatusService | ||
.retrieveCommitStatusFirestore( | ||
limit: commitNumber, | ||
timestamp: lastCommitTimestamp, | ||
branch: branch, | ||
slug: slug, | ||
) | ||
.map<SerializableCommitTasksStatus>( | ||
(CommitTasksStatus status) => SerializableCommitTasksStatus(status), | ||
) | ||
.toList(); | ||
|
||
return Body.forJson(<String, dynamic>{ | ||
'Statuses': statuses, | ||
}); | ||
} | ||
|
||
Future<int> _obtainTimestamp(String? encodedLastCommitKey, KeyHelper keyHelper, DatastoreService datastore) async { | ||
/// [lastCommitTimestamp] is initially set as the current time, which allows query return | ||
/// latest commit list. If [owerKeyParam] is not empty, [lastCommitTimestamp] will be set | ||
/// as the timestamp of that [commit], and the query will return lastest commit | ||
/// list whose timestamp is smaller than [lastCommitTimestamp]. | ||
int lastCommitTimestamp = DateTime.now().millisecondsSinceEpoch; | ||
|
||
if (encodedLastCommitKey != null) { | ||
final Key<String> ownerKey = keyHelper.decode(encodedLastCommitKey) as Key<String>; | ||
final Commit commit = await datastore.db.lookupValue<Commit>( | ||
ownerKey, | ||
orElse: () => throw NotFoundException('Failed to find commit with key $ownerKey'), | ||
); | ||
|
||
lastCommitTimestamp = commit.timestamp!; | ||
} | ||
return lastCommitTimestamp; | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
app_dart/test/model/firestore/commit_tasks_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,32 @@ | ||
// 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/commit.dart'; | ||
import 'package:cocoon_service/src/model/firestore/commit_tasks_status.dart'; | ||
import 'package:cocoon_service/src/model/firestore/task.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../../src/utilities/entity_generators.dart'; | ||
|
||
void main() { | ||
group('CommitTasksStatus', () { | ||
test('generates json correctly', () async { | ||
final Commit commit = generateFirestoreCommit(1, sha: 'sha1'); | ||
final CommitTasksStatus commitTasksStatus = CommitTasksStatus(commit, <Task>[]); | ||
expect(SerializableCommitTasksStatus(commitTasksStatus).toJson(), <String, dynamic>{ | ||
'Commit': <String, dynamic>{ | ||
'DocumentName': 'sha1', | ||
'RepositoryPath': 'flutter/flutter', | ||
'CreateTimestamp': 1, | ||
'Sha': 'sha1', | ||
'Message': 'test message', | ||
'Author': 'author', | ||
'Avatar': 'avatar', | ||
'Branch': 'master', | ||
}, | ||
'Tasks': [], | ||
}); | ||
}); | ||
}); | ||
} |
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.