-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dashboard + branch] reimplement branch fetching logic (#2924)
For branches on cocoon dashboard, fetch any branch that has recent activities, AND, all the release branches. Sorry for the delay, it took me a huge amount of time to restudy the branching logic and dart syntax. The mocks and stubs in tests took me quite a while to get right.
- Loading branch information
1 parent
07c2214
commit 8eb603e
Showing
7 changed files
with
540 additions
and
201 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
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
50 changes: 50 additions & 0 deletions
50
app_dart/lib/src/request_handlers/github/branch_subscription.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,50 @@ | ||
// 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:convert'; | ||
|
||
import 'package:github/hooks.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
import '../../../protos.dart' as pb; | ||
import '../../request_handling/body.dart'; | ||
import '../../request_handling/subscription_handler.dart'; | ||
import '../../service/branch_service.dart'; | ||
import '../../service/logging.dart'; | ||
|
||
const String kWebhookCreateEvent = 'create'; | ||
|
||
/// Subscription for processing GitHub webhooks relating to branches. | ||
/// | ||
/// This subscription processes branch events on GitHub into Cocoon. | ||
@immutable | ||
class GithubBranchWebhookSubscription extends SubscriptionHandler { | ||
/// Creates a subscription for processing GitHub webhooks. | ||
const GithubBranchWebhookSubscription({ | ||
required super.cache, | ||
required super.config, | ||
required this.branchService, | ||
}) : super(subscriptionName: 'github-webhook-branches'); | ||
|
||
final BranchService branchService; | ||
|
||
@override | ||
Future<Body> post() async { | ||
if (message.data == null || message.data!.isEmpty) { | ||
log.warning('GitHub webhook message was empty. No-oping'); | ||
return Body.empty; | ||
} | ||
|
||
final pb.GithubWebhookMessage webhook = pb.GithubWebhookMessage.fromJson(message.data!); | ||
if (webhook.event != kWebhookCreateEvent) { | ||
return Body.empty; | ||
} | ||
|
||
log.fine('Processing ${webhook.event}'); | ||
final CreateEvent createEvent = CreateEvent.fromJson(json.decode(webhook.payload) as Map<String, dynamic>); | ||
await branchService.handleCreateRequest(createEvent); | ||
|
||
return Body.empty; | ||
} | ||
} |
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
Oops, something went wrong.