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

types: Expose the event target from resource label events

This will expose the merge issue id or the issue id of the MR/issue on
which the resource label event was created.
parent e0312dcf
......@@ -786,6 +786,14 @@ fn test_read_resoruce_label_events() {
assert_eq!(, LabelEventId::new(10945));
assert_eq!(, UserId::new(10));
assert_eq!(event.user.username, "brad.king");
match &event.event_target() {
Some(ResourceLabelEventTarget::Issue(id)) if id.value() == 69328 => {
// this is the expected value
x => panic!("Unexpected resource_target: {:?}", x)
let label = event.label.unwrap();
assert_eq!(, LabelId::new(1720));
assert_eq!(, "area:doc");
......@@ -2489,6 +2489,29 @@ pub struct ResourceLabelEvent {
pub action: String
impl ResourceLabelEvent {
/// Returns the id of the merge request or issue that this event is from
pub fn event_target(&self) -> Option<ResourceLabelEventTarget> {
match self.resource_type.as_ref() {
"MergeRequest" => Some(ResourceLabelEventTarget::MergeRequest(MergeRequestId::new(self.resource_id))),
"Issue" => Some(ResourceLabelEventTarget::Issue(IssueId::new(self.resource_id))),
_ => None
#[derive(Debug, Clone, PartialEq, Eq)]
/// The type of object that on which the resource label event was created
pub enum ResourceLabelEventTarget {
/// The ID of an issue event target.
/// The ID of a merge request event target.
#[cfg_attr(feature = "strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// An label on a project.
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