@@ -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.repos ~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
@@ -53,12 +62,10 @@ let () =
53
62
log#error " %s" e;
54
63
Lwt. return_unit
55
64
| Ok config ->
56
- ctx.state.config < - Some config;
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
- )
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
64
71
)
0 commit comments