Skip to content
Open
4 changes: 2 additions & 2 deletions app_dart/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import 'dart:math';

import 'cocoon_service.dart';
import 'src/request_handlers/get_engine_artifacts_ready.dart';
import 'src/request_handlers/get_presubmit_checks.dart';
import 'src/request_handlers/get_presubmit_guard.dart';
import 'src/request_handlers/get_presubmit_guard_summaries.dart';
import 'src/request_handlers/get_presubmit_jobs.dart';
import 'src/request_handlers/get_tree_status_changes.dart';
import 'src/request_handlers/github_webhook_replay.dart';
import 'src/request_handlers/lookup_hash.dart';
Expand Down Expand Up @@ -196,7 +196,7 @@ Server createServer({
authenticationProvider: authProvider,
firestore: firestore,
),
'/api/get-presubmit-checks': GetPresubmitChecks(
'/api/get-presubmit-jobs': GetPresubmitJobs(
config: config,
authenticationProvider: authProvider,
firestore: firestore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// @docImport 'failed_presubmit_checks.dart';
/// @docImport 'failed_presubmit_jobs.dart';
library;

import 'package:github/github.dart';

import '../firestore/base.dart';

/// Contains the list of failed checks that are proposed to be re-run.
/// Contains the list of failed jobs that are proposed to be re-run.
///
/// See: [UnifiedCheckRun.reInitializeFailedChecks]
class FailedChecksForRerun {
/// See: [UnifiedCheckRun.reInitializeFailedJobs]
class FailedJobsForRerun {
final CheckRun checkRunGuard;
final CiStage stage;
final List<String> checkNames;

const FailedChecksForRerun({
const FailedJobsForRerun({
required this.checkRunGuard,
required this.stage,
required this.checkNames,
Expand All @@ -26,7 +26,7 @@ class FailedChecksForRerun {
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is FailedChecksForRerun &&
(other is FailedJobsForRerun &&
other.checkRunGuard == checkRunGuard &&
other.stage == stage &&
other.checkNames == checkNames);
Expand All @@ -36,5 +36,5 @@ class FailedChecksForRerun {

@override
String toString() =>
'FailedChecksForRerun("$checkRunGuard", "$stage", "$checkNames")';
'FailedJobsForRerun("$checkRunGuard", "$stage", "$checkNames")';
}
6 changes: 3 additions & 3 deletions app_dart/lib/src/model/common/presubmit_completed_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import '../firestore/base.dart';
import '../firestore/presubmit_guard.dart';
import '../github/checks.dart' as cocoon_checks;
import 'checks_extension.dart';
import 'presubmit_check_state.dart';
import 'presubmit_job_state.dart';

/// Unified representation of a completed presubmit check.
///
Expand Down Expand Up @@ -134,8 +134,8 @@ class PresubmitCompletedCheck {
);
}

PresubmitCheckState get state {
return PresubmitCheckState(
PresubmitJobState get state {
return PresubmitJobState(
buildName: name,
status: status,
attemptNumber: attempt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// @docImport 'presubmit_check_state.dart';
/// @docImport 'presubmit_job_state.dart';
library;

import 'package:buildbucket/buildbucket_pb.dart' as bbv2;
Expand All @@ -12,7 +12,7 @@ import '../../service/luci_build_service/build_tags.dart';
import '../bbv2_extension.dart';

/// Represents the current state of a check run.
class PresubmitCheckState {
class PresubmitJobState {
final String buildName;
final TaskStatus status;
final int attemptNumber; //static int _currentAttempt(BuildTags buildTags)
Expand All @@ -21,7 +21,7 @@ class PresubmitCheckState {
final String? summary;
final int? buildNumber;

const PresubmitCheckState({
const PresubmitJobState({
required this.buildName,
required this.status,
required this.attemptNumber,
Expand All @@ -32,8 +32,8 @@ class PresubmitCheckState {
});
}

extension BuildToPresubmitCheckState on bbv2.Build {
PresubmitCheckState toPresubmitCheckState() => PresubmitCheckState(
extension BuildToPresubmitJobState on bbv2.Build {
PresubmitJobState toPresubmitJobState() => PresubmitJobState(
buildName: builder.builder,
status: status.toTaskStatus(),
attemptNumber: BuildTags.fromStringPairs(tags).currentAttempt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// @docImport 'presubmit_check.dart';
/// @docImport 'presubmit_job.dart';
library;

import 'package:buildbucket/buildbucket_pb.dart' as bbv2;
Expand All @@ -16,8 +16,8 @@ import '../bbv2_extension.dart';
import 'base.dart';

@immutable
final class PresubmitCheckId extends AppDocumentId<PresubmitCheck> {
PresubmitCheckId({
final class PresubmitJobId extends AppDocumentId<PresubmitJob> {
PresubmitJobId({
required this.checkRunId,
required this.buildName,
required this.attemptNumber,
Expand All @@ -33,27 +33,27 @@ final class PresubmitCheckId extends AppDocumentId<PresubmitCheck> {
}
}

/// Parse the inverse of [PresubmitCheckId.documentName].
factory PresubmitCheckId.parse(String documentName) {
/// Parse the inverse of [PresubmitJobId.documentName].
factory PresubmitJobId.parse(String documentName) {
final result = tryParse(documentName);
if (result == null) {
throw FormatException(
'Unexpected firestore presubmit check document name: "$documentName"',
'Unexpected firestore presubmit job document name: "$documentName"',
);
}
return result;
}

/// Tries to parse the inverse of [PresubmitCheckId.documentName].
/// Tries to parse the inverse of [PresubmitJobId.documentName].
///
/// If could not be parsed, returns `null`.
static PresubmitCheckId? tryParse(String documentName) {
static PresubmitJobId? tryParse(String documentName) {
if (_parseDocumentName.matchAsPrefix(documentName) case final match?) {
final checkRunId = int.tryParse(match.group(1)!);
final buildName = match.group(2)!;
final attemptNumber = int.tryParse(match.group(3)!);
if (checkRunId != null && attemptNumber != null) {
return PresubmitCheckId(
return PresubmitJobId(
checkRunId: checkRunId,
buildName: buildName,
attemptNumber: attemptNumber,
Expand All @@ -80,12 +80,12 @@ final class PresubmitCheckId extends AppDocumentId<PresubmitCheck> {
}

@override
AppDocumentMetadata<PresubmitCheck> get runtimeMetadata =>
PresubmitCheck.metadata;
AppDocumentMetadata<PresubmitJob> get runtimeMetadata =>
PresubmitJob.metadata;
}

final class PresubmitCheck extends AppDocument<PresubmitCheck> {
static const collectionId = 'presubmit_checks';
final class PresubmitJob extends AppDocument<PresubmitJob> {
static const collectionId = 'presubmit_jobs';
static const fieldCheckRunId = 'checkRunId';
static const fieldBuildName = 'buildName';
static const fieldBuildNumber = 'buildNumber';
Expand All @@ -96,12 +96,12 @@ final class PresubmitCheck extends AppDocument<PresubmitCheck> {
static const fieldEndTime = 'endTime';
static const fieldSummary = 'summary';

static AppDocumentId<PresubmitCheck> documentIdFor({
static AppDocumentId<PresubmitJob> documentIdFor({
required int checkRunId,
required String buildName,
required int attemptNumber,
}) {
return PresubmitCheckId(
return PresubmitJobId(
checkRunId: checkRunId,
buildName: buildName,
attemptNumber: attemptNumber,
Expand All @@ -124,24 +124,24 @@ final class PresubmitCheck extends AppDocument<PresubmitCheck> {
}

@override
AppDocumentMetadata<PresubmitCheck> get runtimeMetadata => metadata;
AppDocumentMetadata<PresubmitJob> get runtimeMetadata => metadata;

static final metadata = AppDocumentMetadata<PresubmitCheck>(
static final metadata = AppDocumentMetadata<PresubmitJob>(
collectionId: collectionId,
fromDocument: PresubmitCheck.fromDocument,
fromDocument: PresubmitJob.fromDocument,
);

static Future<PresubmitCheck> fromFirestore(
static Future<PresubmitJob> fromFirestore(
FirestoreService firestoreService,
AppDocumentId<PresubmitCheck> id,
AppDocumentId<PresubmitJob> id,
) async {
final document = await firestoreService.getDocument(
p.posix.join(kDatabase, 'documents', collectionId, id.documentId),
);
return PresubmitCheck.fromDocument(document);
return PresubmitJob.fromDocument(document);
}

factory PresubmitCheck({
factory PresubmitJob({
required int checkRunId,
required String buildName,
required TaskStatus status,
Expand All @@ -152,7 +152,7 @@ final class PresubmitCheck extends AppDocument<PresubmitCheck> {
int? endTime,
String? summary,
}) {
return PresubmitCheck._(
return PresubmitJob._(
{
fieldCheckRunId: checkRunId.toValue(),
fieldBuildName: buildName.toValue(),
Expand All @@ -172,17 +172,17 @@ final class PresubmitCheck extends AppDocument<PresubmitCheck> {
);
}

factory PresubmitCheck.fromDocument(Document document) {
return PresubmitCheck._(document.fields!, name: document.name!);
factory PresubmitJob.fromDocument(Document document) {
return PresubmitJob._(document.fields!, name: document.name!);
}

factory PresubmitCheck.init({
factory PresubmitJob.init({
required String buildName,
required int checkRunId,
required int creationTime,
int? attemptNumber,
}) {
return PresubmitCheck(
return PresubmitJob(
buildName: buildName,
attemptNumber: attemptNumber ?? 1,
checkRunId: checkRunId,
Expand All @@ -195,7 +195,7 @@ final class PresubmitCheck extends AppDocument<PresubmitCheck> {
);
}

PresubmitCheck._(Map<String, Value> fields, {required String name}) {
PresubmitJob._(Map<String, Value> fields, {required String name}) {
this
..fields = fields
..name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import '../../cocoon_service.dart';
import '../request_handling/api_request_handler.dart';
import '../service/firestore/unified_check_run.dart';

/// Returns all checks for a specific presubmit check run.
/// Returns all job run attempts for a specific presubmit job.
///
/// GET: /api/get-presubmit-checks
/// GET: /api/get-presubmit-jobs
///
/// Parameters:
/// check_run_id: (int in query) mandatory. The GitHub Check Run ID.
/// build_name: (string in query) mandatory. The name of the check/build.
/// build_name: (string in query) mandatory. The name of the job/build.
///
/// Response: Status 200 OK
/// [
Expand All @@ -28,11 +28,11 @@ import '../service/firestore/unified_check_run.dart';
/// "start_time": 1620134240000,
/// "end_time": 1620134250000,
/// "status": "Succeeded",
/// "summary": "Check passed"
/// "summary": "Job passed"
/// }
/// ]
final class GetPresubmitChecks extends ApiRequestHandler {
const GetPresubmitChecks({
final class GetPresubmitJobs extends ApiRequestHandler {
const GetPresubmitJobs({
required super.config,
required super.authenticationProvider,
required FirestoreService firestore,
Expand Down Expand Up @@ -65,33 +65,33 @@ final class GetPresubmitChecks extends ApiRequestHandler {
}, statusCode: HttpStatus.badRequest);
}

final checks = await UnifiedCheckRun.getPresubmitCheckDetails(
final jobs = await UnifiedCheckRun.getPresubmitJobDetails(
firestoreService: _firestore,
checkRunId: checkRunId,
buildName: buildName,
);

if (checks.isEmpty) {
if (jobs.isEmpty) {
return Response.json({
'error':
'No checks found for check_run_id $checkRunId and build_name $buildName',
'No jobs found for check_run_id $checkRunId and build_name $buildName',
}, statusCode: HttpStatus.notFound);
}

final rpcChecks = [
for (final check in checks)
PresubmitCheckResponse(
attemptNumber: check.attemptNumber,
buildName: check.buildName,
creationTime: check.creationTime,
startTime: check.startTime,
endTime: check.endTime,
status: check.status.value,
summary: check.summary,
buildNumber: check.buildNumber,
final rpcJobs = [
for (final job in jobs)
PresubmitJobResponse(
attemptNumber: job.attemptNumber,
buildName: job.buildName,
creationTime: job.creationTime,
startTime: job.startTime,
endTime: job.endTime,
status: job.status.value,
summary: job.summary,
buildNumber: job.buildNumber,
),
];

return Response.json(rpcChecks);
return Response.json(rpcJobs);
}
}
Loading
Loading