Commit cb198172 authored by Brad King's avatar Brad King 💬 Committed by Kitware Robot
Browse files

Merge topic 'add-mr-closes-issue-method'

3d8ff538 gitlab: use an IssueReference type for MR close references
e4a062c9

 gitlab: add an endpoint for issues closed by an MR
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Brad King's avatarBrad King <brad.king@kitware.com>
Merge-request: !27
parents ca36d627 3d8ff538
......@@ -287,6 +287,14 @@ impl Gitlab {
self._get(&format!("projects/{}/merge_requests/{}", project, merge_request))
}
/// Get the issues that will be closed when a merge request is merged.
pub fn merge_request_closes_issues(&self, project: ProjectId, merge_request: MergeRequestId)
-> GitlabResult<Vec<IssueReference>> {
self._get_paged(&format!("projects/{}/merge_requests/{}/closes_issues",
project,
merge_request))
}
/// Get the notes from a merge request.
pub fn merge_request_notes(&self, project: ProjectId, merge_request: MergeRequestId)
-> GitlabResult<Vec<Note>> {
......
......@@ -14,7 +14,7 @@ use self::serde::{Deserialize, Deserializer, Serialize, Serializer};
use self::serde::de::Error;
extern crate serde_json;
use self::serde_json::Value;
use self::serde_json::{from_value, Value};
use std::fmt::{self, Display, Formatter};
......@@ -812,6 +812,36 @@ pub struct ExternalIssue {
pub title: String,
}
pub enum IssueReference {
Internal(Issue),
External(ExternalIssue),
}
impl Serialize for IssueReference {
fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
match *self {
IssueReference::Internal(ref issue) => issue.serialize(serializer),
IssueReference::External(ref issue) => issue.serialize(serializer),
}
}
}
impl Deserialize for IssueReference {
fn deserialize<D: Deserializer>(deserializer: &mut D) -> Result<Self, D::Error> {
let val = try!(Value::deserialize(deserializer));
from_value::<Issue>(val.clone())
.map(IssueReference::Internal)
.or_else(|_| {
from_value::<ExternalIssue>(val)
.map(IssueReference::External)
})
.map_err(|err| {
D::Error::invalid_value(&format!("{:?}", err))
})
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
pub struct MergeRequestId(u64);
impl_id!(MergeRequestId);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment