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