@@ -87,7 +87,8 @@ 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 = Context. get_config_exn ctx in
90
+ let repo = n.repository in
91
+ let cfg = Context. find_repo_config_exn ctx 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
@@ -111,7 +112,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
111
112
| Ok commit -> Lwt. return @@ partition_commit cfg commit.files
112
113
)
113
114
in
114
- if Context. is_pipeline_allowed ctx ~pipeline then begin
115
+ if Context. is_pipeline_allowed ctx repo.url ~pipeline then begin
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
@@ -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 = Context. get_config_exn ctx in
134
+ let cfg = Context. find_repo_config_exn ctx 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 = Context. get_config_exn ctx in
153
+ let repo = Github. repo_of_notification req in
154
+ let cfg = Context. find_repo_config_exn ctx 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,20 @@ 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 , 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.config < - Some config;
190
- Context. print_config ctx;
191
+ Context. set_repo_config ctx 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.config with
196
+ match Context. find_repo_config ctx repo.url with
195
197
| None -> fetch_config ()
196
198
| Some _ ->
197
199
match notification with
@@ -208,7 +210,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
208
210
match Github. parse_exn ~secret: secrets.gh_hook_token headers body with
209
211
| exception exn -> Exn_lwt. fail ~exn " failed to parse payload"
210
212
| payload ->
211
- ( match % lwt refresh_config_of_context ctx payload with
213
+ ( match % lwt refresh_repo_config ctx payload with
212
214
| Error e -> action_error e
213
215
| Ok () ->
214
216
let % lwt notifications = generate_notifications ctx payload in
0 commit comments