@@ -19,25 +19,34 @@ let get_mock_payloads () =
19
19
let state_path = Caml.Filename. concat mock_state_dir fn in
20
20
if Caml.Sys. file_exists state_path then kind, payload_path, Some state_path else kind, payload_path, None )
21
21
22
- let process ~(ctx : Context.t ) (kind , path , state_path ) =
23
- let % lwt ctx =
22
+ let process ~(secrets : Config_t.secrets ) ~config (kind , path , state_path ) =
23
+ let headers = [ " x-github-event" , kind ] in
24
+ let make_test_context event =
25
+ let repo = Github. repo_of_notification @@ Github. parse_exn ~secret: secrets.gh_token headers event in
26
+ let ctx = Context. make () in
27
+ ctx.secrets < - Some secrets;
28
+ ignore (State. find_or_add_repo ctx.state repo.url);
24
29
match state_path with
25
- | None -> Lwt. return ctx
30
+ | None ->
31
+ State. set_repo_config ctx.state ~config ~repo_url: repo.url;
32
+ Lwt. return ctx
26
33
| Some state_path ->
27
34
match Common. get_local_file state_path with
28
35
| Error e ->
29
36
log#error " failed to read %s: %s" state_path e;
30
37
Lwt. return ctx
31
38
| Ok file ->
32
- let state = State_j. state_of_string file in
33
- state.config < - ctx.state.config;
34
- Lwt. return { ctx with state }
39
+ let repo_state = State_j. repo_state_of_string file in
40
+ Hashtbl. set ctx.state ~key: repo.url ~data: repo_state;
41
+ State. set_repo_config ctx.state ~repo_url: repo.url ~config ;
42
+ Lwt. return ctx
35
43
in
36
44
Stdio. printf " ===== file %s =====\n " path;
37
45
let headers = [ " x-github-event" , kind ] in
38
46
match Common. get_local_file path with
39
47
| Error e -> Lwt. return @@ log#error " failed to read %s: %s" path e
40
48
| Ok event ->
49
+ let % lwt ctx = make_test_context event in
41
50
let % lwt _ctx = Action_local. process_github_notification ctx headers event in
42
51
Lwt. return_unit
43
52
@@ -51,12 +60,10 @@ let () =
51
60
log#error " %s" e;
52
61
Lwt. return_unit
53
62
| Ok config ->
54
- ctx.state.config < - Some config;
55
- ( match Context. refresh_secrets ctx with
56
- | Ok ctx -> Lwt_list. iter_s (process ~ctx ) payloads
57
- | Error e ->
58
- log#error " failed to read secrets:" ;
59
- log#error " %s" e;
60
- Lwt. return_unit
61
- )
63
+ match Context. refresh_secrets ctx with
64
+ | Ok ctx -> Lwt_list. iter_s (process ~secrets: (Option. value_exn ctx.secrets) ~config ) payloads
65
+ | Error e ->
66
+ log#error " failed to read secrets:" ;
67
+ log#error " %s" e;
68
+ Lwt. return_unit
62
69
)
0 commit comments