Skip to content

Commit

Permalink
Fix PullRequestReviewEvent model (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuaKT authored Feb 12, 2023
1 parent 64f22ab commit fb2eaed
Show file tree
Hide file tree
Showing 2 changed files with 435 additions and 487 deletions.
17 changes: 3 additions & 14 deletions src/models/events/payload/pull_request_review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,14 @@ pub struct PullRequestReviewEventPayload {
pub pull_request: PullRequest,
/// The review that was affected.
pub review: Review,
/// The changes to body or title if this event is of type [`PullRequestReviewEventAction::Edited`].
pub changes: Option<PullRequestReviewChanges>,
/// The repository where the event occurred.
pub repository: Repository,
/// The user that triggered the event.
pub sender: User,
}

/// The action on a pull request review this event corresponds to.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum PullRequestReviewEventAction {
Submitted,
Edited,
Dismissed,
Created,
}

/// The change which occurred in an event of type [`PullRequestReviewEventAction::Edited`].
Expand Down Expand Up @@ -60,9 +52,7 @@ mod test {
#[test]
fn should_deserialize_action_from_lowercase() {
let actions = vec![
(r#""submitted""#, PullRequestReviewEventAction::Submitted),
(r#""edited""#, PullRequestReviewEventAction::Edited),
(r#""dismissed""#, PullRequestReviewEventAction::Dismissed),
(r#""created""#, PullRequestReviewEventAction::Created),
];
for (action_str, action) in actions {
let deserialized = serde_json::from_str(&action_str).unwrap();
Expand Down Expand Up @@ -91,8 +81,7 @@ mod test {
let json = include_str!("../../../../tests/resources/pull_request_review_event.json");
let event: Event = serde_json::from_str(json).unwrap();
if let Some(EventPayload::PullRequestReviewEvent(payload)) = event.payload {
assert_eq!(payload.action, PullRequestReviewEventAction::Submitted);
assert_eq!(payload.pull_request.id.0, 279147437);
assert_eq!(payload.pull_request.id.0, 1237933052);
} else {
panic!("unexpected event payload encountered: {:#?}", event.payload);
}
Expand Down
Loading

0 comments on commit fb2eaed

Please sign in to comment.