diff --git a/CHANGES.md b/CHANGES.md index 7a9a258..0169a3e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,9 @@ * `gitlab.atd`: add `tag`, `user`, `duration` and `queued_duration` to `pipeline_job`. Make `created_at` field mandatory (remove `nullable`). + * `gitlab.atd`: add `event_action_type` type + * `User.events`: add paging and `after` parameter. Return a stream + instead of single list of events. ## Bug fixes @@ -36,6 +39,8 @@ `secrets_provider_not_found`, `reached_max_descendant_pipelines_depth`, `ip_restriction_failure`, and `reached_max_pipeline_hierarchy_size` + * the `action` param of `Events.all` takes an `event_action_type`, + not an `event_action` ## Added diff --git a/cli/user.ml b/cli/user.ml index 7d3ecc1..46ceac7 100644 --- a/cli/user.ml +++ b/cli/user.ml @@ -80,8 +80,13 @@ let user_events_cmd config = let open Gitlab in let open Monad in let config = config () in - User.events ~token:config.token ~id () >|~ fun events -> - printf "%s\n" (Yojson.Basic.prettify @@ Gitlab_j.string_of_events events) + let* events = return @@ User.events ~token:config.token ~id () in + Stream.iter + (fun event -> + return + @@ printf "%s\n" + (Yojson.Basic.prettify @@ Gitlab_j.string_of_event event)) + events in Lwt_main.run @@ Gitlab.Monad.run cmd in diff --git a/lib/gitlab.atd b/lib/gitlab.atd index 8d952c8..0607a6c 100644 --- a/lib/gitlab.atd +++ b/lib/gitlab.atd @@ -1145,6 +1145,21 @@ type event_action_name = [ | Updated ] +type event_action_type = [ + | Approved + | Closed + | Commented + | Created + | Destroyed + | Expired + | Joined + | Left + | Merged + | Pushed + | Reopened + | Updated +] + type command_changes = { ?promote_to_epic: bool option; } diff --git a/lib/gitlab_core.ml b/lib/gitlab_core.ml index c765a0f..baee585 100644 --- a/lib/gitlab_core.ml +++ b/lib/gitlab_core.ml @@ -1085,23 +1085,18 @@ struct ("include_retried", if b then "true" else "false") | None -> uri - let action_param (action : Gitlab_t.event_action_name option) uri = + let action_type_param (action : Gitlab_t.event_action_type option) uri = let show = function - | `Accepted -> "accepted" | `Approved -> "approved" | `Closed -> "closed" - | `CommentedOn -> "commented on" + | `Commented -> "commented" | `Created -> "created" | `Destroyed -> "destroyed" - | `Deleted -> "deleted" | `Expired -> "expired" | `Joined -> "joined" | `Left -> "left" | `Merged -> "merged" - | `Opened -> "opened" | `Pushed -> "pushed" - | `PushedTo -> "pushed to" - | `PushedNew -> "pushed new" | `Reopened -> "reopened" | `Updated -> "updated" in @@ -1347,7 +1342,7 @@ struct URI.events |> before_param before |> after_param after |> event_scope_param scope |> sort_param sort |> target_type_param target_type - |> action_param action + |> action_type_param action in API.get ~token ~uri (fun body -> return (Gitlab_j.events_of_string body)) end @@ -1397,12 +1392,14 @@ struct API.get_stream ~token ~uri (fun body -> return (Gitlab_j.issues_of_string body)) - let events ~token ~id ?action ?target_type () = + let events ~token ~id ?action ?target_type ?per_page ?after ?sort () = let uri = - URI.user_events ~id |> action_param action + URI.user_events ~id |> action_type_param action |> target_type_param target_type + |> per_page_param per_page |> after_param after |> sort_param sort in - API.get ~token ~uri (fun body -> return (Gitlab_j.events_of_string body)) + API.get_stream ~token ~uri (fun body -> + return (Gitlab_j.events_of_string body)) module PersonalAccessToken = struct let tokens ~token ?user_id () = @@ -1575,7 +1572,7 @@ struct let events ~token ~project_id ?action ?target_type () = let uri = URI.project_events ~id:project_id - |> action_param action + |> action_type_param action |> target_type_param target_type in API.get ~token ~uri (fun body -> return (Gitlab_j.events_of_string body)) diff --git a/lib/gitlab_s.mli b/lib/gitlab_s.mli index 777ff1b..8ebad83 100644 --- a/lib/gitlab_s.mli +++ b/lib/gitlab_s.mli @@ -403,7 +403,7 @@ module type Gitlab = sig ?scope:string -> ?sort:Gitlab_t.sort -> ?target_type:Gitlab_t.event_target_type -> - ?action:Gitlab_t.event_action_name -> + ?action:Gitlab_t.event_action_type -> unit -> Gitlab_t.events Response.t Monad.t (** [all ~token] get a list of events for the authenticated user. @@ -476,10 +476,13 @@ module type Gitlab = sig val events : token:Token.t -> id:string -> - ?action:Gitlab_t.event_action_name -> + ?action:Gitlab_t.event_action_type -> ?target_type:Gitlab_t.event_target_type -> + ?per_page:int -> + ?after:string -> + ?sort:Gitlab_t.sort -> unit -> - Gitlab_t.events Response.t Monad.t + Gitlab_t.event Stream.t (** [events ~token ~id] get the contribution events for the specified user. See {{:https://docs.gitlab.com/ee/api/events.html#get-user-contribution-events}Get user contribution events}. @@ -765,7 +768,7 @@ module type Gitlab = sig val events : token:Token.t -> project_id:int -> - ?action:Gitlab_t.event_action_name -> + ?action:Gitlab_t.event_action_type -> ?target_type:Gitlab_t.event_target_type -> unit -> Gitlab_t.events Response.t Monad.t