blob: d1d21fbded0d93a03c167c0f9e44284362925472 [file] [log] [blame]
// Copyright 2023 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:auto_submit/model/auto_submit_query_result.dart';
import 'package:auto_submit/validations/validation.dart';
import 'package:github/github.dart' as github;
/// Validates that a pull request is in a mergeable state.
class Mergeable extends Validation {
Mergeable({required super.config});
@override
Future<ValidationResult> validate(QueryResult result, github.PullRequest messagePullRequest) async {
final int pullRequestNumber = messagePullRequest.number!;
final github.RepositorySlug slug = messagePullRequest.base!.repo!.slug();
final MergeableState mergeableState = result.repository!.pullRequest!.mergeable!;
switch (mergeableState) {
case MergeableState.MERGEABLE:
return ValidationResult(
true,
Action.REMOVE_LABEL,
'Pull request ${slug.fullName}/$pullRequestNumber is mergeable',
);
case MergeableState.UNKNOWN:
return ValidationResult(
false,
Action.IGNORE_TEMPORARILY,
'Mergeability of pull request ${slug.fullName}/$pullRequestNumber could not be determined at time of merge.',
);
case MergeableState.CONFLICTING:
return ValidationResult(
false,
Action.REMOVE_LABEL,
'Pull request ${slug.fullName}/$pullRequestNumber is not in a mergeable state.',
);
}
}
}