Skip to main content

ironflow_ops_gitlab/endpoints/
merge_requests.rs

1//! Merge request discussion routes missing from the `gitlab` crate:
2//! `POST /projects/:id/merge_requests/:iid/discussions/:discussion_id/notes` and
3//! `PUT /projects/:id/merge_requests/:iid/discussions/:discussion_id`.
4
5use std::borrow::Cow;
6
7use gitlab::api::common::NameOrId;
8use gitlab::api::endpoint_prelude::{BodyError, Endpoint, FormParams, Method};
9
10/// Add a note (reply) to an existing merge request discussion.
11///
12/// Maps to `POST /projects/:id/merge_requests/:merge_request/discussions/:discussion_id/notes`.
13///
14/// # Examples
15///
16/// ```no_run
17/// use ironflow_ops_gitlab::GitLab;
18/// use ironflow_ops_gitlab::endpoints::merge_requests::CreateMergeRequestDiscussionNote;
19/// use gitlab::api::common::NameOrId;
20///
21/// # async fn example() -> Result<(), ironflow_core::error::OperationError> {
22/// let gitlab = GitLab::new("glpat-xxxx", "gitlab.com").await?;
23/// let endpoint = CreateMergeRequestDiscussionNote {
24///     project: NameOrId::from(42),
25///     merge_request: 7,
26///     discussion_id: "abcd1234".to_string(),
27///     body: "Looks good, thanks!".to_string(),
28/// };
29/// let op = gitlab.op(endpoint);
30/// # Ok(())
31/// # }
32/// ```
33///
34/// # Errors
35///
36/// Returns an error if the request fails or the response cannot be deserialized (e.g. the
37/// project, merge request or discussion does not exist).
38pub struct CreateMergeRequestDiscussionNote {
39    /// The project the merge request belongs to.
40    pub project: NameOrId<'static>,
41    /// The internal ID (`iid`) of the merge request.
42    pub merge_request: u64,
43    /// The ID of the discussion thread to reply to.
44    pub discussion_id: String,
45    /// The text of the note.
46    pub body: String,
47}
48
49impl Endpoint for CreateMergeRequestDiscussionNote {
50    fn method(&self) -> Method {
51        Method::POST
52    }
53
54    fn endpoint(&self) -> Cow<'static, str> {
55        format!(
56            "projects/{}/merge_requests/{}/discussions/{}/notes",
57            self.project, self.merge_request, self.discussion_id,
58        )
59        .into()
60    }
61
62    fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, BodyError> {
63        let mut params = FormParams::default();
64        params.push("body", self.body.as_str());
65        params.into_body()
66    }
67}
68
69/// Resolve or unresolve an existing merge request discussion.
70///
71/// Maps to `PUT /projects/:id/merge_requests/:merge_request/discussions/:discussion_id`.
72///
73/// # Examples
74///
75/// ```no_run
76/// use ironflow_ops_gitlab::GitLab;
77/// use ironflow_ops_gitlab::endpoints::merge_requests::ResolveMergeRequestDiscussion;
78/// use gitlab::api::common::NameOrId;
79///
80/// # async fn example() -> Result<(), ironflow_core::error::OperationError> {
81/// let gitlab = GitLab::new("glpat-xxxx", "gitlab.com").await?;
82/// let endpoint = ResolveMergeRequestDiscussion {
83///     project: NameOrId::from(42),
84///     merge_request: 7,
85///     discussion_id: "abcd1234".to_string(),
86///     resolved: true,
87/// };
88/// let op = gitlab.op(endpoint);
89/// # Ok(())
90/// # }
91/// ```
92///
93/// # Errors
94///
95/// Returns an error if the request fails or the response cannot be deserialized (e.g. the
96/// project, merge request or discussion does not exist).
97pub struct ResolveMergeRequestDiscussion {
98    /// The project the merge request belongs to.
99    pub project: NameOrId<'static>,
100    /// The internal ID (`iid`) of the merge request.
101    pub merge_request: u64,
102    /// The ID of the discussion thread to resolve or unresolve.
103    pub discussion_id: String,
104    /// Whether the discussion should be marked resolved.
105    pub resolved: bool,
106}
107
108impl Endpoint for ResolveMergeRequestDiscussion {
109    fn method(&self) -> Method {
110        Method::PUT
111    }
112
113    fn endpoint(&self) -> Cow<'static, str> {
114        format!(
115            "projects/{}/merge_requests/{}/discussions/{}",
116            self.project, self.merge_request, self.discussion_id,
117        )
118        .into()
119    }
120
121    fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, BodyError> {
122        let mut params = FormParams::default();
123        params.push("resolved", self.resolved);
124        params.into_body()
125    }
126}