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
57 changes: 57 additions & 0 deletions app_dart/lib/src/model/common/presubmit_check_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2025 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.

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

import 'package:buildbucket/buildbucket_pb.dart' as bbv2;
import 'package:cocoon_common/task_status.dart';

import '../../service/luci_build_service/build_tags.dart';
import '../bbv2_extension.dart';

/// Represents the current state of a check run.
class PresubmitCheckState {
final String buildName;
final TaskStatus status;
final int attemptNumber; //static int _currentAttempt(BuildTags buildTags)
final int? startTime;
final int? endTime;
final String? summary;

const PresubmitCheckState({
required this.buildName,
required this.status,
required this.attemptNumber,
this.startTime,
this.endTime,
this.summary,
});

/// Returns true if the build is waiting for backfill or in progress.
bool get isBuildInProgress =>
status == TaskStatus.waitingForBackfill ||
status == TaskStatus.inProgress;

/// Returns true if the build succeeded or was skipped.
bool get isBuildSuccessed =>
status == TaskStatus.succeeded || status == TaskStatus.skipped;

/// Returns true if the build failed, had an infra failure, or was cancelled.
bool get isBuildFailed =>
status == TaskStatus.failed ||
status == TaskStatus.infraFailure ||
status == TaskStatus.cancelled;
}

extension BuildToPresubmitCheckState on bbv2.Build {
PresubmitCheckState toPresubmitCheckState() => PresubmitCheckState(
buildName: builder.builder,
status: status.toTaskStatus(),
attemptNumber: BuildTags.fromStringPairs(tags).currentAttempt,
startTime: startTime.toDateTime().microsecondsSinceEpoch,
endTime: endTime.toDateTime().microsecondsSinceEpoch,
summary: summaryMarkdown,
);
}
81 changes: 81 additions & 0 deletions app_dart/lib/src/model/common/presubmit_guard_conclusion.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2025 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.

/// @docImport 'presubmit_guard_conclusion.dart';
library;

/// Explains what happened when attempting to mark the conclusion of a check run
/// using [PresubmitGuard.markConclusion].
enum PresubmitGuardConclusionResult {
/// Check run update recorded successfully in the respective CI stage.
///
/// It is OK to evaluate returned results for stage completeness.
ok,

/// The check run is not in the specified CI stage.
///
/// Perhaps it's from a different CI stage.
missing,

/// An unexpected error happened, and the results of the conclusion are
/// undefined.
///
/// Examples of situations that can lead to this result:
///
/// * The Firestore document is missing.
/// * The contents of the Firestore document are inconsistent.
/// * An unexpected error happend while trying to read from/write to Firestore.
///
/// When this happens, it's best to stop the current transaction, report the
/// error to the logs, and have someone investigate the issue.
internalError,
}

/// Results from attempting to mark a staging task as completed.
///
/// See: [PresubmitGuard.markConclusion]
class PresubmitGuardConclusion {
final PresubmitGuardConclusionResult result;
final int remaining;
final int? checkRunId;
final int failed;
final String summary;
final String details;

const PresubmitGuardConclusion({
required this.result,
required this.remaining,
required this.checkRunId,
required this.failed,
required this.summary,
required this.details,
});

bool get isOk => result == PresubmitGuardConclusionResult.ok;

bool get isPending => isOk && remaining > 0;

bool get isFailed => isOk && !isPending && failed > 0;

bool get isComplete => isOk && !isPending && !isFailed;

@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is PresubmitGuardConclusion &&
other.result == result &&
other.remaining == remaining &&
other.checkRunId == checkRunId &&
other.failed == failed &&
other.summary == summary &&
other.details == details);

@override
int get hashCode =>
Object.hashAll([result, remaining, checkRunId, failed, summary, details]);

@override
String toString() =>
'BuildConclusion("$result", "$remaining", "$checkRunId", "$failed", "$summary", "$details")';
}
19 changes: 19 additions & 0 deletions app_dart/lib/src/model/firestore/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ import 'dart:convert';
import 'package:googleapis/firestore/v1.dart' as g;
import 'package:meta/meta.dart';

/// Well-defined stages in the build infrastructure.
enum CiStage implements Comparable<CiStage> {
/// Build engine artifacts
fusionEngineBuild('engine'),

/// All non-engine artifact tests (engine & framework)
fusionTests('fusion');

const CiStage(this.name);

final String name;

@override
int compareTo(CiStage other) => index - other.index;

@override
String toString() => name;
}

/// Defines the `documentId` for a given document [T].
///
/// The path to a document in Firestore follows the pattern:
Expand Down
19 changes: 0 additions & 19 deletions app_dart/lib/src/model/firestore/ci_staging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -479,25 +479,6 @@ enum TaskConclusion {
bool get isSuccess => this == success;
}

/// Well-defined stages in the build infrastructure.
enum CiStage implements Comparable<CiStage> {
/// Build engine artifacts
fusionEngineBuild('engine'),

/// All non-engine artifact tests (engine & framework)
fusionTests('fusion');

const CiStage(this.name);

final String name;

@override
int compareTo(CiStage other) => index - other.index;

@override
String toString() => name;
}

/// Explains what happened when attempting to mark the conclusion of a check run
/// using [CiStaging.markConclusion].
enum StagingConclusionResult {
Expand Down
Loading
Loading