@@ -87,13 +87,14 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
87
87
if List. is_empty matched_channel_names then default else matched_channel_names
88
88
89
89
let partition_status (ctx : Context.t ) (n : status_notification ) =
90
- let cfg = State. find_repo_config_exn ctx.state in
90
+ let repo = n.repository in
91
+ let cfg = State. find_repo_config_exn ctx.state repo.url in
91
92
let pipeline = n.context in
92
93
let current_status = n.state in
93
94
let rules = cfg.status_rules.rules in
94
95
let action_on_match (branches : branch list ) =
95
96
let default = Option. to_list cfg.prefix_rules.default_channel in
96
- let () = State. set_repo_pipeline_status ~pipeline ~branches ~status: current_status ctx.state in
97
+ State. set_repo_pipeline_status ctx.state repo.url ~pipeline ~branches ~status: current_status;
97
98
match List. is_empty branches with
98
99
| true -> Lwt. return []
99
100
| false ->
@@ -105,18 +106,18 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
105
106
| false -> Lwt. return default
106
107
| true ->
107
108
let sha = n.commit.sha in
108
- let repo = n.repository in
109
109
( match % lwt Github_api. get_api_commit ~ctx ~repo ~sha with
110
110
| Error e -> action_error e
111
111
| Ok commit -> Lwt. return @@ partition_commit cfg commit.files
112
112
)
113
113
in
114
- if State. is_pipeline_allowed ctx.state ~pipeline then begin
114
+ if State. is_pipeline_allowed ctx.state repo.url ~pipeline then begin
115
+ let repo_state = State. find_repo_exn ctx.state repo.url in
115
116
match Rule.Status. match_rules ~rules n with
116
117
| Some Ignore | None -> Lwt. return []
117
118
| Some Allow -> action_on_match n.branches
118
119
| Some Allow_once ->
119
- match Map. find ctx.state .pipeline_statuses pipeline with
120
+ match Map. find repo_state .pipeline_statuses pipeline with
120
121
| Some branch_statuses ->
121
122
let has_same_status_state_as_prev (branch : branch ) =
122
123
match Map. find branch_statuses branch.name with
@@ -130,7 +131,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
130
131
else Lwt. return []
131
132
132
133
let partition_commit_comment (ctx : Context.t ) n =
133
- let cfg = State. find_repo_config_exn ctx.state in
134
+ let cfg = State. find_repo_config_exn ctx.state n.repository.url in
134
135
match n.comment.commit_id with
135
136
| None -> action_error " unable to find commit id for this commit comment event"
136
137
| Some sha ->
@@ -149,7 +150,8 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
149
150
)
150
151
151
152
let generate_notifications (ctx : Context.t ) req =
152
- let cfg = State. find_repo_config_exn ctx.state in
153
+ let repo = Github. repo_of_notification req in
154
+ let cfg = State. find_repo_config_exn ctx.state repo.url in
153
155
match req with
154
156
| Github. Push n ->
155
157
partition_push cfg n |> List. map ~f: (fun (channel , n ) -> generate_push_notification n channel) |> Lwt. return
@@ -178,20 +180,21 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
178
180
in
179
181
Lwt_list. iter_s notify notifications
180
182
181
- (* * `refresh_config_of_context ctx n` updates the current context if the configuration
182
- hasn't been loaded yet , or if the incoming request `n` is a push
183
+ (* * `refresh_repo_config ctx n` fetches the latest repo config if it's
184
+ uninitialized in state , or if the incoming request `n` is a push
183
185
notification containing commits that touched the config file. *)
184
- let refresh_config_of_context (ctx : Context.t ) notification =
186
+ let refresh_repo_config (ctx : Context.t ) notification =
187
+ let repo = Github. repo_of_notification notification in
185
188
let fetch_config () =
186
- let repo = Github. repo_of_notification notification in
187
189
match % lwt Github_api. get_config ~ctx ~repo with
188
190
| Ok config ->
189
- ctx.state.config < - Some config;
190
- Context. print_config ctx;
191
+ State. set_repo_config ctx.state ~repo_url: repo.url ~ config ;
192
+ Context. print_config ctx repo.url ;
191
193
Lwt. return @@ Ok ()
192
194
| Error e -> action_error e
193
195
in
194
- match ctx.state.config with
196
+ let repo_state = State. find_or_add_repo ctx.state repo.url in
197
+ match repo_state.config with
195
198
| None -> fetch_config ()
196
199
| Some _ ->
197
200
match notification with
@@ -208,7 +211,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
208
211
match Github. parse_exn ~secret: secrets.gh_hook_token headers body with
209
212
| exception exn -> Exn_lwt. fail ~exn " failed to parse payload"
210
213
| payload ->
211
- ( match % lwt refresh_config_of_context ctx payload with
214
+ ( match % lwt refresh_repo_config ctx payload with
212
215
| Error e -> action_error e
213
216
| Ok () ->
214
217
let % lwt notifications = generate_notifications ctx payload in
@@ -232,6 +235,9 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
232
235
| Context. Context_error msg ->
233
236
log#error " %s" msg;
234
237
Lwt. return_unit
238
+ | State. State_error msg ->
239
+ log#error " %s" msg;
240
+ Lwt. return_unit
235
241
236
242
let process_link_shared_event (ctx : Context.t ) (event : Slack_t.link_shared_event ) =
237
243
let process link =
0 commit comments