File tree Expand file tree Collapse file tree 4 files changed +21
-11
lines changed Expand file tree Collapse file tree 4 files changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
100
100
let rules = cfg.status_rules.rules in
101
101
let action_on_match (branches : branch list ) =
102
102
let default = Option. to_list cfg.prefix_rules.default_channel in
103
- let () = Context. refresh_pipeline_status ctx repo.url ~pipeline ~branches ~status: current_status in
103
+ State. set_repo_pipeline_status ctx.state repo.url ~pipeline ~branches ~status: current_status;
104
104
match List. is_empty branches with
105
105
| true -> Lwt. return []
106
106
| false ->
@@ -118,11 +118,12 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
118
118
)
119
119
in
120
120
if Context. is_pipeline_allowed ctx repo.url ~pipeline then begin
121
+ let repo_state = State. find_or_add_repo ctx.state repo.url in
121
122
match Rule.Status. match_rules ~rules n with
122
123
| Some Ignore | None -> Lwt. return []
123
124
| Some Allow -> action_on_match n.branches
124
125
| Some Allow_once ->
125
- match Map. find ctx.state .pipeline_statuses pipeline with
126
+ match Map. find repo_state .pipeline_statuses pipeline with
126
127
| Some branch_statuses ->
127
128
let has_same_status_state_as_prev (branch : branch ) =
128
129
match Map. find branch_statuses branch.name with
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ let default : t =
22
22
state_filepath = None ;
23
23
secrets = None ;
24
24
config = Stringtbl. empty () ;
25
- state = State. empty;
25
+ state = State. empty () ;
26
26
}
27
27
28
28
let make ?config_filename ?secrets_filepath ?state_filepath () =
@@ -61,9 +61,6 @@ let is_pipeline_allowed ctx repo_url ~pipeline =
61
61
| Some allowed_pipelines when not @@ List. exists allowed_pipelines ~f: (String. equal pipeline) -> false
62
62
| _ -> true
63
63
64
- let refresh_pipeline_status ctx repo_url ~pipeline ~(branches : Github_t.branch list ) ~status =
65
- if is_pipeline_allowed ctx repo_url ~pipeline then State. refresh_pipeline_status ctx.state ~pipeline ~branches ~status
66
-
67
64
let log = Log. from " context"
68
65
69
66
let refresh_secrets ctx =
Original file line number Diff line number Diff line change 1
1
type status_state <ocaml from="Github"> = abstract
2
2
type 'v map_as_object <ocaml from="Common"> = abstract
3
+ type 'v table_as_object <ocaml from="Common"> = abstract
3
4
4
5
(* A map from branch names to build statuses *)
5
6
type branch_statuses = status_state map_as_object
@@ -9,8 +10,13 @@ type branch_statuses = status_state map_as_object
9
10
branch *)
10
11
type pipeline_statuses = branch_statuses map_as_object
11
12
13
+ (* The runtime state of a given GitHub repository *)
14
+ type repo_state = {
15
+ pipeline_statuses <ocaml mutable>: pipeline_statuses
16
+ }
17
+
12
18
(* The serializable runtime state of the bot *)
13
19
type state = {
14
- pipeline_statuses <ocaml mutable>: pipeline_statuses ;
20
+ repos : repo_state table_as_object ;
15
21
?bot_user_id <ocaml mutable>: string nullable;
16
22
}
Original file line number Diff line number Diff line change @@ -2,15 +2,21 @@ open Base
2
2
open Common
3
3
open Devkit
4
4
5
- let empty : State_t.state = { pipeline_statuses = StringMap. empty; bot_user_id = None }
5
+ let empty_repo_state () : State_t.repo_state = { pipeline_statuses = StringMap. empty }
6
6
7
- let refresh_pipeline_status (state : State_t.state ) ~pipeline ~(branches : Github_t.branch list ) ~status =
8
- let update_pipeline_status branch_statuses =
7
+ let empty () : State_t.state = { repos = Stringtbl. empty () ; bot_user_id = None }
8
+
9
+ let find_or_add_repo (state : State_t.state ) repo_url =
10
+ Stringtbl. find_or_add state.repos repo_url ~default: empty_repo_state
11
+
12
+ let set_repo_pipeline_status (state : State_t.state ) repo_url ~pipeline ~(branches : Github_t.branch list ) ~status =
13
+ let set_branch_status branch_statuses =
9
14
let new_statuses = List. map branches ~f: (fun b -> b.name, status) in
10
15
let init = Option. value branch_statuses ~default: (Map. empty (module String )) in
11
16
List. fold_left new_statuses ~init ~f: (fun m (key , data ) -> Map. set m ~key ~data )
12
17
in
13
- state.pipeline_statuses < - Map. update state.pipeline_statuses pipeline ~f: update_pipeline_status
18
+ let repo_state = find_or_add_repo state repo_url in
19
+ repo_state.pipeline_statuses < - Map. update repo_state.pipeline_statuses pipeline ~f: set_branch_status
14
20
15
21
let log = Log. from " state"
16
22
You can’t perform that action at this time.
0 commit comments