Skip to content

Commit

Permalink
Support listing and creating Notes in merge requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterDA committed May 31, 2022
1 parent 2bc4ff4 commit b8a67f0
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/gitlab.atd
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,8 @@ type noteable_type = [
| Issue <json name="Issue">
]

type notes = note list

type note = {
id: int;
note_type <json name="type"> : string nullable;
Expand All @@ -1135,6 +1137,12 @@ type note = {
noteable_iid: int;
} <ocaml field_prefix="note_">

type create_note = {
body: string;
created_at: date_time option;
merge_request_diff_sha: string option;
} <ocaml field_prefix="create_note_">

type branch = {
id: int;
project_id: int;
Expand Down
29 changes: 29 additions & 0 deletions lib/gitlab_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ struct
(Printf.sprintf "%s/projects/%i/merge_requests/%s/changes" api id
merge_request_iid)

let project_merge_request_notes ~project_id ~merge_request_iid =
Uri.of_string
(Printf.sprintf "%s/projects/%i/merge_requests/%s/notes" api project_id
merge_request_iid)

let project_merge_request_note_id ~project_id ~merge_request_iid ~note_id =
Uri.of_string
(Printf.sprintf "%s/projects/%i/merge_requests/%s/notes/%i" api project_id
merge_request_iid note_id)

let project_events ~id =
Uri.of_string (Printf.sprintf "%s/projects/%i/events" api id)

Expand Down Expand Up @@ -1515,6 +1525,25 @@ struct
API.post ~token ~uri ~body ~expected_code:`Created (fun s ->
Lwt.return (Gitlab_j.issue_of_string s))
end

module Notes = struct
module Merge_request = struct
let list ?token ~project_id ~merge_request_iid ?sort () =
let uri = URI.project_merge_request_notes ~project_id ~merge_request_iid |> sort_param sort in
API.get_stream ?token ~uri (fun body ->
return (Gitlab_j.notes_of_string body))

let by_id ?token ~project_id ~merge_request_iid ~note_id () =
let uri = URI.project_merge_request_note_id ~project_id ~merge_request_iid ~note_id in
API.get ?token ~uri (fun body -> return (Gitlab_j.note_of_string body))

let create ~token ~project_id ~merge_request_iid ~create_note () =
let uri = URI.project_merge_request_notes ~project_id ~merge_request_iid in
let body = Gitlab_j.string_of_create_note create_note in
API.post ~token ~uri ~body ~expected_code:`Created (fun s ->
Lwt.return (Gitlab_j.note_of_string s))
end
end
end

module Group = struct
Expand Down
52 changes: 52 additions & 0 deletions lib/gitlab_s.mli
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,58 @@ module type Gitlab = sig
See {{:https://docs.gitlab.com/ee/api/issues.html#new-issue}New issue}.
*)
end

(** The [Notes] module provides access to
{{:https://docs.gitlab.com/ee/api/notes.html#merge-requests}Notes
API}.
*)
module Notes : sig

(** The [Merge_request] module provides access to
{{:https://docs.gitlab.com/ee/api/notes.html#merge-requests}Merge
requests notes API}.
*)
module Merge_request : sig
val list :
?token:Token.t ->
project_id:int ->
merge_request_iid:string ->
?sort:Gitlab_t.sort ->
unit ->
Gitlab_t.note Stream.t
(** [list ?token ~project_id ~merge_request_iid]
Request a list of a merge request notes. See
{{:https://docs.gitlab.com/ee/api/notes.html#list-all-merge-request-notes}List
all merge request notes}.
*)

val by_id :
?token:Token.t ->
project_id:int ->
merge_request_iid:string ->
note_id:int ->
unit ->
Gitlab_t.note Response.t Monad.t
(** [by_id ?token ~project_id ~merge_request_iid ~note_id]
Get a single note for a given merge request. See
{{:https://docs.gitlab.com/ee/api/notes.html#get-single-merge-request-note}Get
single merge request note}.
*)

val create :
token:Token.t ->
project_id:int ->
merge_request_iid:string ->
create_note:Gitlab_t.create_note ->
unit ->
Gitlab_t.note Response.t Monad.t
(** [create ?token ~project_id ~merge_request_iid ~body]
Creates a new note. See
{{:https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note}Create
new merge request note}.
*)
end
end
end

(** The [Group] module provides access to {{:https://docs.gitlab.com/ee/api/groups.html}Group API}. *)
Expand Down

0 comments on commit b8a67f0

Please sign in to comment.