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