@@ -3,7 +3,7 @@ use std::sync::Arc;
3
3
use tracing:: Instrument ;
4
4
5
5
use crate :: bors:: command:: { BorsCommand , CommandParseError } ;
6
- use crate :: bors:: event:: { BorsEvent , PullRequestComment } ;
6
+ use crate :: bors:: event:: { BorsRepositoryEvent , PullRequestComment } ;
7
7
use crate :: bors:: handlers:: help:: command_help;
8
8
use crate :: bors:: handlers:: ping:: command_ping;
9
9
use crate :: bors:: handlers:: refresh:: refresh_repository;
@@ -16,6 +16,8 @@ use crate::database::DbClient;
16
16
use crate :: github:: GithubRepoName ;
17
17
use crate :: utils:: logging:: LogError ;
18
18
19
+ use super :: event:: { BorsEvent , BorsGlobalEvent } ;
20
+
19
21
mod help;
20
22
mod labels;
21
23
mod ping;
@@ -28,10 +30,26 @@ pub async fn handle_bors_event<Client: RepositoryClient>(
28
30
event : BorsEvent ,
29
31
state : Arc < dyn BorsState < Client > > ,
30
32
ctx : Arc < BorsContext > ,
33
+ ) -> anyhow:: Result < ( ) > {
34
+ match event {
35
+ BorsEvent :: Repository ( event) => {
36
+ handle_bors_repository_event ( event, state, ctx) . await ?;
37
+ }
38
+ BorsEvent :: Global ( event) => {
39
+ handle_bors_global_event ( event, state, ctx) . await ?;
40
+ }
41
+ }
42
+ Ok ( ( ) )
43
+ }
44
+
45
+ pub async fn handle_bors_repository_event < Client : RepositoryClient > (
46
+ event : BorsRepositoryEvent ,
47
+ state : Arc < dyn BorsState < Client > > ,
48
+ ctx : Arc < BorsContext > ,
31
49
) -> anyhow:: Result < ( ) > {
32
50
let db = Arc :: clone ( & ctx. db ) ;
33
51
match event {
34
- BorsEvent :: Comment ( comment) => {
52
+ BorsRepositoryEvent :: Comment ( comment) => {
35
53
// We want to ignore comments made by this bot
36
54
if let Some ( repo) = get_repo_state ( state, & comment. repository ) {
37
55
if repo. client . is_comment_internal ( & comment) . await ? {
@@ -64,13 +82,8 @@ pub async fn handle_bors_event<Client: RepositoryClient>(
64
82
}
65
83
}
66
84
}
67
- BorsEvent :: InstallationsChanged => {
68
- let span = tracing:: info_span!( "Repository reload" ) ;
69
- if let Err ( error) = state. reload_repositories ( ) . instrument ( span. clone ( ) ) . await {
70
- span. log_error ( error) ;
71
- }
72
- }
73
- BorsEvent :: WorkflowStarted ( payload) => {
85
+
86
+ BorsRepositoryEvent :: WorkflowStarted ( payload) => {
74
87
if let Some ( _) = get_repo_state ( state, & payload. repository ) {
75
88
let span = tracing:: info_span!(
76
89
"Workflow started" ,
@@ -85,7 +98,7 @@ pub async fn handle_bors_event<Client: RepositoryClient>(
85
98
}
86
99
}
87
100
}
88
- BorsEvent :: WorkflowCompleted ( payload) => {
101
+ BorsRepositoryEvent :: WorkflowCompleted ( payload) => {
89
102
if let Some ( repo) = get_repo_state ( state, & payload. repository ) {
90
103
let span = tracing:: info_span!(
91
104
"Workflow completed" ,
@@ -100,7 +113,7 @@ pub async fn handle_bors_event<Client: RepositoryClient>(
100
113
}
101
114
}
102
115
}
103
- BorsEvent :: CheckSuiteCompleted ( payload) => {
116
+ BorsRepositoryEvent :: CheckSuiteCompleted ( payload) => {
104
117
if let Some ( repo) = get_repo_state ( state, & payload. repository ) {
105
118
let span = tracing:: info_span!(
106
119
"Check suite completed" ,
@@ -114,7 +127,24 @@ pub async fn handle_bors_event<Client: RepositoryClient>(
114
127
}
115
128
}
116
129
}
117
- BorsEvent :: Refresh => {
130
+ }
131
+ Ok ( ( ) )
132
+ }
133
+
134
+ pub async fn handle_bors_global_event < Client : RepositoryClient > (
135
+ event : BorsGlobalEvent ,
136
+ state : Arc < dyn BorsState < Client > > ,
137
+ ctx : Arc < BorsContext > ,
138
+ ) -> anyhow:: Result < ( ) > {
139
+ let db = Arc :: clone ( & ctx. db ) ;
140
+ match event {
141
+ BorsGlobalEvent :: InstallationsChanged => {
142
+ let span = tracing:: info_span!( "Repository reload" ) ;
143
+ if let Err ( error) = state. reload_repositories ( ) . instrument ( span. clone ( ) ) . await {
144
+ span. log_error ( error) ;
145
+ }
146
+ }
147
+ BorsGlobalEvent :: Refresh => {
118
148
let span = tracing:: info_span!( "Refresh" ) ;
119
149
let repos = state. get_all_repos ( ) ;
120
150
futures:: future:: join_all ( repos. into_iter ( ) . map ( |repo| {
0 commit comments