| // Copyright 2020 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:convert'; |
| |
| import 'package:github/github.dart' |
| show CheckSuite, PullRequest, Repository, User; |
| import 'package:github/hooks.dart' show HookEvent; |
| import 'package:json_annotation/json_annotation.dart'; |
| |
| part 'checks.g.dart'; |
| |
| /// Data models for json messages coming from GitHub Checks API. |
| /// |
| /// See more: |
| /// * https://docs.github.com/en/webhooks/webhook-events-and-payloads#check_run. |
| @JsonSerializable(fieldRename: FieldRename.snake) |
| class CheckRunEvent extends HookEvent { |
| CheckRunEvent({this.action, this.checkRun, this.sender, this.repository}); |
| |
| factory CheckRunEvent.fromJson(Map<String, dynamic> input) => |
| _$CheckRunEventFromJson(input); |
| CheckRun? checkRun; |
| String? action; |
| User? sender; |
| Repository? repository; |
| |
| Map<String, dynamic> toJson() => _$CheckRunEventToJson(this); |
| |
| @override |
| String toString() { |
| return 'CheckRunEvent ${const JsonEncoder.withIndent(' ').convert(toJson())}'; |
| } |
| } |
| |
| @JsonSerializable(fieldRename: FieldRename.snake) |
| class CheckRun { |
| const CheckRun({ |
| this.conclusion, |
| this.headSha, |
| this.id, |
| this.pullRequests, |
| this.name, |
| this.checkSuite, |
| }); |
| |
| factory CheckRun.fromJson(Map<String, dynamic> input) => |
| _$CheckRunFromJson(input); |
| final int? id; |
| final String? headSha; |
| final String? conclusion; |
| final String? name; |
| final CheckSuite? checkSuite; |
| @JsonKey(name: 'pull_requests', defaultValue: <PullRequest>[]) |
| final List<PullRequest>? pullRequests; |
| |
| Map<String, dynamic> toJson() => _$CheckRunToJson(this); |
| |
| @override |
| String toString() { |
| return 'CheckRun ${const JsonEncoder.withIndent(' ').convert(toJson())}'; |
| } |
| } |
| |
| /// Data model for a `merge_group` event. |
| /// |
| /// The event may request one of two actions: |
| /// |
| /// * `checks_requested`: request to create checks and kick of CI tasks. |
| /// * `destroyed`: a notification that a `merge_group` is no longer neede and CI |
| /// jobs can be stopped. |
| /// |
| /// See more: |
| /// * https://docs.github.com/en/webhooks/webhook-events-and-payloads#merge_group. |
| @JsonSerializable(fieldRename: FieldRename.snake) |
| class MergeGroupEvent extends HookEvent { |
| MergeGroupEvent({ |
| required this.action, |
| required this.mergeGroup, |
| this.reason, |
| this.repository, |
| this.sender, |
| }); |
| |
| factory MergeGroupEvent.fromJson(Map<String, dynamic> input) => |
| _$MergeGroupEventFromJson(input); |
| |
| String action; |
| |
| /// Possible reasons for the 'destroyed' event. |
| static const String merged = 'merged'; |
| static const String invalidated = 'invalidated'; |
| static const String dequeued = 'dequeued'; |
| static const destroyReasons = <String>[merged, invalidated, dequeued]; |
| |
| /// If [action] is "destroyed", explains why the merge group is being destroyed. |
| /// |
| /// The group could have been merged, removed from the queue (dequeued), or |
| /// invalidated by an earlier queue entry being dequeued (invalidated). |
| /// |
| /// Can be one of: merged, invalidated, dequeued. |
| /// |
| /// If [action] is not "destroyed", this field is null. |
| String? reason; |
| |
| MergeGroup mergeGroup; |
| Repository? repository; |
| User? sender; |
| |
| Map<String, dynamic> toJson() => _$MergeGroupEventToJson(this); |
| |
| @override |
| String toString() { |
| return 'MergeGroupEvent ${const JsonEncoder.withIndent(' ').convert(toJson())}'; |
| } |
| } |
| |
| /// Data model for a `merge_group`. |
| /// |
| /// This object is supplied by [MergeGroupEvent]. |
| @JsonSerializable(fieldRename: FieldRename.snake) |
| class MergeGroup { |
| const MergeGroup({ |
| required this.headSha, |
| required this.headRef, |
| required this.baseSha, |
| required this.baseRef, |
| required this.headCommit, |
| }); |
| |
| factory MergeGroup.fromJson(Map<String, dynamic> input) => |
| _$MergeGroupFromJson(input); |
| |
| /// The commit SHA generated for the candidate PR to be merged. |
| /// |
| /// This is the SHA that must be checked by the CI. |
| final String headSha; |
| |
| /// The ref to the read-only branch generated by Github for the respective PR. |
| final String headRef; |
| |
| /// The SHA of the merge group's parent commit. |
| final String baseSha; |
| |
| /// The full ref of the branch the merge group will be merged into. |
| final String baseRef; |
| |
| /// Commit details for the [headSha]. |
| final HeadCommit headCommit; |
| |
| Map<String, dynamic> toJson() => _$MergeGroupToJson(this); |
| |
| @override |
| String toString() { |
| return 'MergeGroup ${const JsonEncoder.withIndent(' ').convert(toJson())}'; |
| } |
| } |
| |
| /// Data model for `merge_group.head_commit`. |
| /// |
| /// Provides the details of the [MergeGroup.headSha] commit. |
| /// |
| /// This object is supplied by [MergeGroup]. |
| @JsonSerializable(fieldRename: FieldRename.snake) |
| class HeadCommit { |
| const HeadCommit({ |
| required this.id, |
| required this.treeId, |
| required this.message, |
| }); |
| |
| factory HeadCommit.fromJson(Map<String, dynamic> input) => |
| _$HeadCommitFromJson(input); |
| |
| /// The commit SHA generated for the candidate PR to be merged. |
| /// |
| /// Same as [MergeGroup.headSha]. |
| final String id; |
| |
| /// SHA for the commit's tree. |
| final String treeId; |
| |
| /// The commit message. |
| final String message; |
| |
| Map<String, dynamic> toJson() => _$HeadCommitToJson(this); |
| |
| @override |
| String toString() { |
| return 'HeadCommit ${const JsonEncoder.withIndent(' ').convert(toJson())}'; |
| } |
| } |