Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display curl requests and responses in debug #36

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

- API: `Contributions.of_json` parameter `~from` is replaced by `~period` (#31, @gpetiot)

### Added

- Display curl requests and responses in debug mode (`-vv` or `--verbosity debug`) (#<PR_NUMBER>, @gpetiot)
gpetiot marked this conversation as resolved.
Show resolved Hide resolved

## 1.0.1

### Fixed
Expand Down
9 changes: 8 additions & 1 deletion bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
(name main)
(public_name get-activity)
(package get-activity)
(libraries cmdliner dune-build-info get-activity-lib))
(libraries
cmdliner
dune-build-info
get-activity-lib
logs.cli
logs.fmt
fmt.cli
fmt.tty))
14 changes: 11 additions & 3 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ let mode = `Normal

open Cmdliner

let setup_log style_renderer level =
Fmt_tty.setup_std_outputs ?style_renderer ();
Logs.set_level level;
Logs.set_reporter (Logs_fmt.reporter ());
()

let setup_log =
Term.(const setup_log $ Fmt_cli.style_renderer () $ Logs_cli.level ())

let from =
let doc =
Arg.info ~docv:"TIMESTAMP" ~doc:"Starting date (ISO8601)." [ "from" ]
Expand Down Expand Up @@ -88,11 +97,10 @@ let version =

let info = Cmd.info "get-activity" ~version

let run period user : unit =
let run () period user : unit =
match mode with
| `Normal ->
Period.with_period period ~last_fetch_file ~f:(fun period ->
(* Fmt.pr "period: %a@." Fmt.(pair string string) period; *)
let* token = get_token () in
let request = Contributions.request ~period ~user ~token in
let* contributions = Graphql.exec request in
Expand All @@ -112,6 +120,6 @@ let run period user : unit =
in
show ~period ~user @@ Yojson.Safe.from_file "activity.json"

let term = Term.(const run $ term_result period $ user)
let term = Term.(const run $ setup_log $ term_result period $ user)
let cmd = Cmd.v info term
let () = Stdlib.exit @@ Cmd.eval cmd
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
astring
curly
(fmt (>= 0.8.7))
logs
ppx_yojson_conv
(yojson (>= 1.6))
(ocaml (>= 4.08))))
1 change: 1 addition & 0 deletions get-activity-lib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ depends: [
"astring"
"curly"
"fmt" {>= "0.8.7"}
"logs"
"ppx_yojson_conv"
"yojson" {>= "1.6"}
"ocaml" {>= "4.08"}
Expand Down
2 changes: 1 addition & 1 deletion lib/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(library
(name get_activity)
(public_name get-activity-lib)
(libraries astring curly fmt yojson)
(libraries astring curly fmt logs yojson)
(preprocess
(pps ppx_yojson_conv)))
4 changes: 3 additions & 1 deletion lib/graphql.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ let exec request =
let { meth; url; headers; body } = request in
let body = Yojson.Safe.to_string body in
let request = Curly.Request.make ~headers ~body ~url ~meth () in
Logs.debug (fun m -> m "request: @[%a@]@." Curly.Request.pp request);
match Curly.run request with
| Ok { Curly.Response.body; _ } -> (
| Ok ({ Curly.Response.body; _ } as response) -> (
Logs.debug (fun m -> m "response: @[%a@]@." Curly.Response.pp response);
let json = Yojson.Safe.from_string body in
match json / "message" with
| `Null -> Ok json
Expand Down
Loading