Commit 864568a1 authored by Brad King's avatar Brad King
Browse files

types: update for 9.5

Issues and projects gained a `_links` field containing URLs of related
APIs (see gitlab-ce MR 10491, commit v9.5.0-rc1~301^2).  We model it
but do not expose it publicly since our clients won't need it.

Notes gained a `noteable_iid` when attached to issues and merge
requests (see gitlab-ce MR 13265, commit v9.5.0-rc1~14^2).
parent cee71d06
{"due_date": null, "downvotes": 0, "subscribed": true, "web_url": "https://gitlab.kitware.com/utils/rust-gitlab/issues/6", "description": "", "confidential": false, "title": "fix documentation warnings", "created_at": "2016-10-30T14:54:28.954-04:00", "labels": [], "updated_at": "2017-07-07T02:31:03.757-04:00", "iid": 6, "state": "closed", "user_notes_count": 0, "assignee": {"username": "ben.boeckel", "web_url": "https://gitlab.kitware.com/ben.boeckel", "name": "Ben Boeckel", "state": "active", "avatar_url": "https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon", "id": 13}, "author": {"username": "ben.boeckel", "web_url": "https://gitlab.kitware.com/ben.boeckel", "name": "Ben Boeckel", "state": "active", "avatar_url": "https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon", "id": 13}, "milestone": null, "upvotes": 0, "assignees": [{"username": "ben.boeckel", "web_url": "https://gitlab.kitware.com/ben.boeckel", "name": "Ben Boeckel", "state": "active", "avatar_url": "https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon", "id": 13}], "project_id": 855, "id": 69328}
{"_links": {"project": "http://gitlab.kitware.com/api/v4/projects/855", "self": "http://gitlab.kitware.com/api/v4/projects/855/issues/6", "notes": "http://gitlab.kitware.com/api/v4/projects/855/issues/6/notes", "award_emoji": "http://gitlab.kitware.com/api/v4/projects/855/issues/6/award_emoji"}, "due_date": null, "downvotes": 0, "subscribed": true, "web_url": "https://gitlab.kitware.com/utils/rust-gitlab/issues/6", "description": "", "confidential": false, "title": "fix documentation warnings", "created_at": "2016-10-30T14:54:28.954-04:00", "labels": [], "updated_at": "2017-07-07T02:31:03.757-04:00", "iid": 6, "state": "closed", "user_notes_count": 0, "assignee": {"username": "ben.boeckel", "web_url": "https://gitlab.kitware.com/ben.boeckel", "name": "Ben Boeckel", "state": "active", "avatar_url": "https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon", "id": 13}, "author": {"username": "ben.boeckel", "web_url": "https://gitlab.kitware.com/ben.boeckel", "name": "Ben Boeckel", "state": "active", "avatar_url": "https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon", "id": 13}, "milestone": null, "upvotes": 0, "assignees": [{"username": "ben.boeckel", "web_url": "https://gitlab.kitware.com/ben.boeckel", "name": "Ben Boeckel", "state": "active", "avatar_url": "https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon", "id": 13}], "project_id": 855, "id": 69328}
{"body": "Mentioned in commit 47d475d8625424bd37efd27f7097354306842b93", "author": {"username": "brad.king", "web_url": "https://gitlab.kitware.com/brad.king", "name": "Brad King", "state": "active", "avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon", "id": 10}, "created_at": "2016-10-04T16:18:57.786-04:00", "updated_at": "2016-10-04T16:18:57.786-04:00", "noteable_type": "MergeRequest", "system": true, "attachment": null, "noteable_id": 20215, "id": 177371}
{"body": "Mentioned in commit 47d475d8625424bd37efd27f7097354306842b93", "author": {"username": "brad.king", "web_url": "https://gitlab.kitware.com/brad.king", "name": "Brad King", "state": "active", "avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon", "id": 10}, "created_at": "2016-10-04T16:18:57.786-04:00", "updated_at": "2016-10-04T16:18:57.786-04:00", "noteable_type": "MergeRequest", "system": true, "attachment": null, "noteable_id": 20215, "noteable_iid": 35, "id": 177371}
{"lfs_enabled": true, "request_access_enabled": true, "import_error": null, "only_allow_merge_if_all_discussions_are_resolved": null, "container_registry_enabled": true, "shared_runners_enabled": true, "wiki_enabled": true, "id": 855, "merge_requests_enabled": true, "archived": false, "snippets_enabled": false, "http_url_to_repo": "https://gitlab.kitware.com/utils/rust-gitlab.git", "namespace": {"kind": "group", "name": "Utils", "members_count_with_descendants": 3, "parent_id": null, "path": "utils", "id": 498, "full_path": "utils"}, "star_count": 0, "avatar_url": null, "issues_enabled": true, "path_with_namespace": "utils/rust-gitlab", "ci_config_path": null, "shared_with_groups": [], "description": "Rust library for communicating with a Gitlab instance.", "forks_count": 5, "default_branch": "master", "visibility": "public", "ssh_url_to_repo": "git@gitlab.kitware.com:utils/rust-gitlab.git", "path": "rust-gitlab", "import_status": "none", "only_allow_merge_if_pipeline_succeeds": false, "open_issues_count": 4, "last_activity_at": "2017-08-03T12:11:16.279-04:00", "name": "rust-gitlab", "printing_merge_request_link_enabled": true, "name_with_namespace": "Utils / rust-gitlab", "created_at": "2016-06-29T13:35:12.495-04:00", "creator_id": 13, "web_url": "https://gitlab.kitware.com/utils/rust-gitlab", "permissions": {"group_access": {"notification_level": 3, "access_level": 50}, "project_access": null}, "tag_list": [], "jobs_enabled": false, "public_jobs": true}
{"lfs_enabled": true, "request_access_enabled": true, "forks_count": 5, "only_allow_merge_if_all_discussions_are_resolved": null, "container_registry_enabled": true, "web_url": "https://gitlab.kitware.com/utils/rust-gitlab", "wiki_enabled": true, "id": 855, "merge_requests_enabled": true, "archived": false, "snippets_enabled": false, "http_url_to_repo": "https://gitlab.kitware.com/utils/rust-gitlab.git", "namespace": {"kind": "group", "name": "Utils", "members_count_with_descendants": 3, "parent_id": null, "path": "utils", "id": 498, "full_path": "utils"}, "star_count": 0, "avatar_url": null, "_links": {"repo_branches": "http://gitlab.kitware.com/api/v4/projects/855/repository/branches", "merge_requests": "http://gitlab.kitware.com/api/v4/projects/855/merge_requests", "self": "http://gitlab.kitware.com/api/v4/projects/855", "labels": "http://gitlab.kitware.com/api/v4/projects/855/labels", "members": "http://gitlab.kitware.com/api/v4/projects/855/members", "events": "http://gitlab.kitware.com/api/v4/projects/855/events", "issues": "http://gitlab.kitware.com/api/v4/projects/855/issues"}, "issues_enabled": true, "path_with_namespace": "utils/rust-gitlab", "ci_config_path": null, "shared_with_groups": [], "description": "Rust library for communicating with a Gitlab instance.", "import_error": null, "default_branch": "master", "visibility": "public", "ssh_url_to_repo": "git@gitlab.kitware.com:utils/rust-gitlab.git", "path": "rust-gitlab", "import_status": "none", "only_allow_merge_if_pipeline_succeeds": false, "open_issues_count": 4, "last_activity_at": "2017-08-03T12:11:16.279-04:00", "name": "rust-gitlab", "printing_merge_request_link_enabled": true, "name_with_namespace": "Utils / rust-gitlab", "created_at": "2016-06-29T13:35:12.495-04:00", "creator_id": 13, "shared_runners_enabled": true, "permissions": {"group_access": {"notification_level": 3, "access_level": 50}, "project_access": null}, "tag_list": [], "jobs_enabled": false, "public_jobs": true}
......@@ -158,6 +158,7 @@ fn test_read_issue() {
assert_eq!(issue.confidential, false);
assert_eq!(issue.web_url,
"https://gitlab.kitware.com/utils/rust-gitlab/issues/6");
assert!(issue.has_links());
}
#[test]
......@@ -309,6 +310,8 @@ fn test_read_note() {
assert_eq!(note.system, true);
assert_eq!(note.noteable_id(),
Some(NoteableId::MergeRequest(MergeRequestId::new(20215))));
assert_eq!(note.noteable_iid(),
Some(NoteableInternalId::MergeRequest(MergeRequestInternalId::new(35))));
assert_eq!(note.noteable_type, NoteType::MergeRequest);
}
......@@ -378,6 +381,7 @@ fn test_read_project() {
panic!("expected to have group access on the permissions");
}
assert!(permissions.project_access.is_none());
assert!(project.has_links());
} else {
panic!("expected to have permissions available");
}
......
......@@ -476,6 +476,26 @@ pub struct ProjectNamespaceAvatar {
pub url: Option<String>,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
struct ProjectLinks {
#[serde(rename="self")]
/// API URL of project itself.
self_: String,
/// API URL of project issues, if enabled.
issues: Option<String>,
/// API URL of project merge requests, if enabled.
merge_requests: Option<String>,
/// API URL of project repository branches.
repo_branches: String,
/// API URL of project labels.
labels: String,
/// API URL of project events.
events: String,
/// API URL of project members.
members: String,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Project information.
......@@ -569,6 +589,18 @@ pub struct Project {
/// If this is present, it is `ProjectWithAccess`, but since it is so similar, just have it be
/// optional here.
pub permissions: Option<Permissions>,
/// Links to related API URLs provided by GitLab in response to
/// direct project lookup. We do not expose this because our
/// clients do not need them.
_links: Option<ProjectLinks>,
}
#[cfg(test)]
impl Project {
pub fn has_links(&self) -> bool {
self._links.is_some()
}
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
......@@ -1093,6 +1125,20 @@ enum_serialize!(IssueState -> "issue type",
Reopened => "reopened",
);
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
struct IssueLinks {
#[serde(rename="self")]
/// API URL of issue itself.
self_: String,
/// API URL of issue notes.
notes: String,
/// API URL of issue award emoji.
award_emoji: String,
/// API URL of issue project.
project: String,
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// An issue on a project.
......@@ -1139,6 +1185,18 @@ pub struct Issue {
pub confidential: bool,
/// The URL of the issue.
pub web_url: String,
/// Links to related API URLs provided by GitLab in response to
/// direct issue lookup. We do not expose this because our
/// clients do not need them.
_links: Option<IssueLinks>,
}
#[cfg(test)]
impl Issue {
pub fn has_links(&self) -> bool {
self._links.is_some()
}
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
......@@ -1493,6 +1551,16 @@ pub enum NoteableId {
Snippet(SnippetId),
}
#[derive(Debug, Clone, PartialEq, Eq)]
/// The internal ID of an entity a note is attached to (internal to a project).
/// GitLab only has this for notes attached to issues and merge requests.
pub enum NoteableInternalId {
/// The internal ID of the issue for an issue note.
Issue(IssueInternalId),
/// The internal ID of the merge request for a merge request note.
MergeRequest(MergeRequestInternalId),
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
/// Type-safe note (comment) ID.
......@@ -1522,6 +1590,8 @@ pub struct Note {
pub system: bool,
// Keep as JSON because its type depends on what `noteable_type` is.
noteable_id: Value,
// Keep as JSON because its type depends on what `noteable_type` is.
noteable_iid: Option<Value>,
/// The type of entity the note is attached to.
pub noteable_type: NoteType,
}
......@@ -1552,6 +1622,31 @@ impl Note {
},
}
}
/// The internal ID of the entity the note is attached to (internal to a project).
/// This is available only for notes attached to issues and merge requests.
pub fn noteable_iid(&self) -> Option<NoteableInternalId> {
match self.noteable_type {
NoteType::Commit => {
None
},
NoteType::Issue => {
self.noteable_iid
.as_ref()
.and_then(|value| value.as_u64())
.map(|id| NoteableInternalId::Issue(IssueInternalId::new(id)))
},
NoteType::MergeRequest => {
self.noteable_iid
.as_ref()
.and_then(|value| value.as_u64())
.map(|id| NoteableInternalId::MergeRequest(MergeRequestInternalId::new(id)))
},
NoteType::Snippet => {
None
},
}
}
}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
......
Markdown is supported
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