Commit 3d8ff538 authored by Ben Boeckel's avatar Ben Boeckel
Browse files

gitlab: use an IssueReference type for MR close references

parent e4a062c9
......@@ -289,8 +289,7 @@ impl Gitlab {
/// 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<Issue>> {
// FIXME: this will fail with external issue references (ExternalIssue).
-> GitlabResult<Vec<IssueReference>> {
self._get_paged(&format!("projects/{}/merge_requests/{}/closes_issues",
project,
merge_request))
......
......@@ -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