@@ -93,13 +93,14 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
93
93
if List. is_empty matched_channel_names then default else matched_channel_names
94
94
95
95
let partition_status (ctx : Context.t ) (n : status_notification ) =
96
- let cfg = Context. get_config_exn ctx in
96
+ let repo = n.repository in
97
+ let cfg = Context. find_repo_config_exn ctx repo.url in
97
98
let pipeline = n.context in
98
99
let current_status = n.state in
99
100
let rules = cfg.status_rules.rules in
100
101
let action_on_match (branches : branch list ) =
101
102
let default = Option. to_list cfg.prefix_rules.default_channel in
102
- let () = Context. refresh_pipeline_status ~pipeline ~branches ~status: current_status ctx in
103
+ let () = Context. refresh_pipeline_status ctx repo.url ~pipeline ~branches ~status: current_status in
103
104
match List. is_empty branches with
104
105
| true -> Lwt. return []
105
106
| false ->
@@ -111,13 +112,12 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
111
112
| false -> Lwt. return default
112
113
| true ->
113
114
let sha = n.commit.sha in
114
- let repo = n.repository in
115
115
( match % lwt Github_api. get_api_commit ~ctx ~repo ~sha with
116
116
| Error e -> action_error e
117
117
| Ok commit -> Lwt. return @@ partition_commit cfg commit.files
118
118
)
119
119
in
120
- if Context. is_pipeline_allowed ctx ~pipeline then begin
120
+ if Context. is_pipeline_allowed ctx repo.url ~pipeline then begin
121
121
match Rule.Status. match_rules ~rules n with
122
122
| Some Ignore | None -> Lwt. return []
123
123
| Some Allow -> action_on_match n.branches
@@ -136,7 +136,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
136
136
else Lwt. return []
137
137
138
138
let partition_commit_comment (ctx : Context.t ) n =
139
- let cfg = Context. get_config_exn ctx in
139
+ let cfg = Context. find_repo_config_exn ctx n.repository.url in
140
140
match n.comment.commit_id with
141
141
| None -> action_error " unable to find commit id for this commit comment event"
142
142
| Some sha ->
@@ -155,7 +155,8 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
155
155
)
156
156
157
157
let generate_notifications (ctx : Context.t ) req =
158
- let cfg = Context. get_config_exn ctx in
158
+ let repo = Github. repo_of_notification req in
159
+ let cfg = Context. find_repo_config_exn ctx repo.url in
159
160
match req with
160
161
| Github. Push n ->
161
162
partition_push cfg n |> List. map ~f: (fun (channel , n ) -> generate_push_notification n channel) |> Lwt. return
@@ -184,20 +185,20 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
184
185
in
185
186
Lwt_list. iter_s notify notifications
186
187
187
- (* * [refresh_config_of_context ctx n] updates the current context if the configuration
188
- hasn't been loaded yet , or if the incoming request [n] is a push
188
+ (* * [refresh_repo_config ctx n] fetches the latest repo config if it's
189
+ uninitialized , or if the incoming request [n] is a push
189
190
notification containing commits that touched the config file. *)
190
- let refresh_config_of_context (ctx : Context.t ) notification =
191
+ let refresh_repo_config (ctx : Context.t ) notification =
192
+ let repo = Github. repo_of_notification notification in
191
193
let fetch_config () =
192
- let repo = Github. repo_of_notification notification in
193
194
match % lwt Github_api. get_config ~ctx ~repo with
194
195
| Ok config ->
195
- ctx.config < - Some config;
196
- Context. print_config ctx;
196
+ Context. set_repo_config ctx repo.url config;
197
+ Context. print_config ctx repo.url ;
197
198
Lwt. return @@ Ok ()
198
199
| Error e -> action_error e
199
200
in
200
- match ctx.config with
201
+ match Context. find_repo_config ctx repo.url with
201
202
| None -> fetch_config ()
202
203
| Some _ ->
203
204
match notification with
@@ -214,7 +215,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
214
215
match Github. parse_exn ~secret: secrets.gh_hook_token headers body with
215
216
| exception exn -> Exn_lwt. fail ~exn " failed to parse payload"
216
217
| payload ->
217
- ( match % lwt refresh_config_of_context ctx payload with
218
+ ( match % lwt refresh_repo_config ctx payload with
218
219
| Error e -> action_error e
219
220
| Ok () ->
220
221
let % lwt notifications = generate_notifications ctx payload in
0 commit comments