Commit e0312dcf authored by Andrew Chin's avatar Andrew Chin Committed by Brad King
Browse files

types: Add resource label events

Resource label events record are events that are recorded whenever a
label is added or removed to an issue/merge request.

This Gitlab API was added in 11.1, and so any labels added/removed
before this release will not appear in the data returned by this API.
parent 138b799b
......@@ -50,3 +50,4 @@ if __name__ == '__main__':
write_result(token, 'issue_reference', '/projects/%s/merge_requests/%d/closes_issues' % (REPO, MR_ID))
write_result(token, 'note', '/projects/%s/merge_requests/%d/notes' % (REPO, MR_ID))
write_result(token, 'award_emoji', '/projects/%s/merge_requests/%d/notes/%d/award_emoji' % (REPO, MR_ID, NOTE_ID))
write_result(token, 'resource_label_event', '/projects/%s/issues/%d/resource_label_events' % (REPO, ISSUE_ID))
{
"action": "add",
"created_at": "2019-07-17T13:53:48.937Z",
"id": 10945,
"label": {
"color": "#5843AD",
"description": "Documentation issues",
"id": 1720,
"name": "area:doc",
"text_color": "#FFFFFF"
},
"resource_id": 69328,
"resource_type": "Issue",
"user": {
"avatar_url": "https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon",
"id": 10,
"name": "Brad King",
"state": "active",
"username": "brad.king",
"web_url": "https://gitlab.kitware.com/brad.king"
}
}
......@@ -887,6 +887,21 @@ impl Gitlab {
self.post_with_param(path, &params)
}
/// Get the resource label events from an issue.
pub fn issue_label_events(
&self,
project: ProjectId,
issue: IssueInternalId,
) -> Result<Vec<ResourceLabelEvent>>
{
self.get_paged(
&format!(
"projects/{}/issues/{}/resource_label_events",
project, issue,
)
)
}
/// Create a note on a issue.
pub fn create_issue_note<C>(
&self,
......@@ -1166,6 +1181,21 @@ impl Gitlab {
)
}
/// Get the resource label events from a merge request.
pub fn merge_request_label_events(
&self,
project: ProjectId,
merge_request: MergeRequestInternalId,
) -> Result<Vec<ResourceLabelEvent>>
{
self.get_paged(
&format!(
"projects/{}/merge_requests/{}/resource_label_events",
project, merge_request,
)
)
}
/// Create a note on a merge request.
pub fn create_merge_request_note(
&self,
......
......@@ -778,3 +778,17 @@ fn test_read_user_public() {
assert_eq!(user_public.two_factor_enabled, true);
assert_eq!(user_public.external, false);
}
#[test]
fn test_read_resoruce_label_events() {
let event: ResourceLabelEvent = read_test_file("resource_label_event");
assert_eq!(event.id, LabelEventId::new(10945));
assert_eq!(event.user.id, UserId::new(10));
assert_eq!(event.user.username, "brad.king");
let label = event.label.unwrap();
assert_eq!(label.id, LabelId::new(1720));
assert_eq!(label.name, "area:doc");
assert_eq!(label.color, LabelColor::from_rgb(0x58, 0x43, 0xAD));
assert_eq!(label.description, Some("Documentation issues".to_string()));
}
......@@ -2462,3 +2462,45 @@ pub struct PipelineBasic {
/// The URL to the pipeline page.
pub web_url: String,
}
#[cfg_attr(feature = "strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
/// Type-safe label event ID.
pub struct LabelEventId(u64);
impl_id!(LabelEventId);
#[cfg_attr(feature = "strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A resource label event
///
/// Note that resource events were added in Gitlab 11.2. Any labels added or
/// removed before then will not be returned by the API.
pub struct ResourceLabelEvent {
/// The ID for the label event
pub id: LabelEventId,
pub user: UserBasic,
pub created_at: DateTime<Utc>,
/// The merge request id, or issue id (depending on the value of resource_type)
resource_id: u64,
/// Either "MergeRequest" or "Issue"
resource_type: String,
/// The label may be None if the label has been deleted.
pub label: Option<EventLabel>,
pub action: String
}
#[cfg_attr(feature = "strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// An label on a project.
///
/// This is like [Label], except that it doesn't have all the same fields
pub struct EventLabel {
/// The Id of the label.
pub id: LabelId,
/// The name of the label.
pub name: String,
/// The color of the label.
pub color: LabelColor,
/// The description of the label.
pub description: Option<String>,
}
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