Skip to content

Commit

Permalink
Merge pull request #89 from arvidj/arvid@events-fixes
Browse files Browse the repository at this point in the history
Some fixes to events
  • Loading branch information
tmcgilchrist authored Sep 12, 2023
2 parents a100e2b + a358583 commit 770383b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
9 changes: 7 additions & 2 deletions cli/user.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions lib/gitlab.atd
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,21 @@ type event_action_name = [
| Updated <json name="updated">
]

type event_action_type = [
| Approved <json name="approved">
| Closed <json name="closed">
| Commented <json name="commented">
| Created <json name="created">
| Destroyed <json name="destroyed">
| Expired <json name="expired">
| Joined <json name="joined">
| Left <json name="left">
| Merged <json name="merged">
| Pushed <json name="pushed">
| Reopened <json name="reopened">
| Updated <json name="updated">
]

type command_changes = {
?promote_to_epic: bool option;
}
Expand Down
21 changes: 9 additions & 12 deletions lib/gitlab_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 () =
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 7 additions & 4 deletions lib/gitlab_s.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 770383b

Please sign in to comment.