@@ -19,24 +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 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
+ Context. set_repo_config ctx repo.url config;
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
- Lwt. return { ctx with state }
39
+ let repo_state = State_j. repo_state_of_string file in
40
+ Hashtbl. set ctx.state.repos ~key: repo.url ~data: repo_state;
41
+ Context. set_repo_config ctx repo.url config;
42
+ Lwt. return ctx
34
43
in
35
44
Stdio. printf " ===== file %s =====\n " path;
36
45
let headers = [ " x-github-event" , kind ] in
37
46
match Common. get_local_file path with
38
47
| Error e -> Lwt. return @@ log#error " failed to read %s: %s" path e
39
48
| Ok event ->
49
+ let % lwt ctx = make_test_context event in
40
50
let % lwt _ctx = Action_local. process_github_notification ctx headers event in
41
51
Lwt. return_unit
42
52
@@ -52,12 +62,10 @@ let () =
52
62
log#error " %s" e;
53
63
Lwt. return_unit
54
64
| Ok config ->
55
- let ctx = { ctx with config = Some config } in
56
- ( match Context. refresh_secrets ctx with
57
- | Ok ctx -> Lwt_list. iter_s (process ~ctx ) payloads
58
- | Error e ->
59
- log#error " failed to read secrets:" ;
60
- log#error " %s" e;
61
- Lwt. return_unit
62
- )
65
+ match Context. refresh_secrets ctx with
66
+ | Ok ctx -> Lwt_list. iter_s (process ~secrets: (Option. value_exn ctx.secrets) ~config ) payloads
67
+ | Error e ->
68
+ log#error " failed to read secrets:" ;
69
+ log#error " %s" e;
70
+ Lwt. return_unit
63
71
)
0 commit comments