Skip to content

Commit

Permalink
Add Public and Release events (XAMPPRocky#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuaKT authored and dmgorsky committed Mar 6, 2024
1 parent ae93e91 commit ee1c893
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/models/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use crate::models::events::payload::EventInstallation;
use self::payload::{
CommitCommentEventPayload, CreateEventPayload, DeleteEventPayload, EventPayload,
ForkEventPayload, GollumEventPayload, IssueCommentEventPayload, IssuesEventPayload,
PullRequestEventPayload, PullRequestReviewCommentEventPayload, PullRequestReviewEventPayload,
PushEventPayload, WatchEventPayload, WorkflowRunEventPayload, WrappedEventPayload,
PublicEventPayload, PullRequestEventPayload, PullRequestReviewCommentEventPayload,
PullRequestReviewEventPayload, PushEventPayload, ReleaseEventPayload, WatchEventPayload,
WorkflowRunEventPayload, WrappedEventPayload,
};
use super::{ActorId, OrgId, RepositoryId};
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -82,9 +83,11 @@ event_type! {
(ForkEvent, ForkEventPayload),
(GollumEvent, GollumEventPayload),
(MemberEvent, MemberEventPayload),
(PublicEvent, PublicEventPayload),
(PullRequestEvent, PullRequestEventPayload),
(PullRequestReviewEvent, PullRequestReviewEventPayload),
(PullRequestReviewCommentEvent, PullRequestReviewCommentEventPayload),
(ReleaseEvent, ReleaseEventPayload),
(WatchEvent, WatchEventPayload),
(WorkflowRunEvent, WorkflowRunEventPayload)
}
Expand Down Expand Up @@ -225,6 +228,13 @@ mod test {
assert_eq!(event.r#type, EventType::PullRequestReviewCommentEvent);
}

#[test]
fn should_deserialize_release_event() {
let json = include_str!("../../tests/resources/release_event.json");
let event: Event = serde_json::from_str(json).unwrap();
assert_eq!(event.r#type, EventType::ReleaseEvent);
}

#[test]
fn should_deserialize_workflow_run_event() {
let json = include_str!("../../tests/resources/workflow_run_event.json");
Expand Down Expand Up @@ -363,6 +373,10 @@ mod test {
"PullRequestReviewCommentEvent",
include_str!("../../tests/resources/pull_request_review_comment_event.json"),
),
(
"ReleaseEvent",
include_str!("../../tests/resources/release_event.json"),
),
(
"CommitCommentEvent",
include_str!("../../tests/resources/commit_comment_event.json"),
Expand Down
8 changes: 8 additions & 0 deletions src/models/events/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ mod installation_target;
mod issue_comment;
mod issues;
mod member;
mod public;
mod pull_request;
mod pull_request_review;
mod pull_request_review_comment;
mod push;
mod release;
mod watch;
mod workflow_run;

Expand All @@ -27,10 +29,12 @@ pub use installation_target::*;
pub use issue_comment::*;
pub use issues::*;
pub use member::*;
pub use public::*;
pub use pull_request::*;
pub use pull_request_review::*;
pub use pull_request_review_comment::*;
pub use push::*;
pub use release::*;
pub use watch::*;
pub use workflow_run::*;

Expand Down Expand Up @@ -88,9 +92,11 @@ pub enum EventPayload {
ForkEvent(Box<ForkEventPayload>),
GollumEvent(Box<GollumEventPayload>),
MemberEvent(Box<MemberEventPayload>),
PublicEvent(Box<PublicEventPayload>),
PullRequestEvent(Box<PullRequestEventPayload>),
PullRequestReviewEvent(Box<PullRequestReviewEventPayload>),
PullRequestReviewCommentEvent(Box<PullRequestReviewCommentEventPayload>),
ReleaseEvent(Box<ReleaseEventPayload>),
WatchEvent(Box<WatchEventPayload>),
WorkflowRunEvent(Box<WorkflowRunEventPayload>),
UnknownEvent(Box<serde_json::Value>),
Expand Down Expand Up @@ -169,9 +175,11 @@ mod tests {
| EventPayload::ForkEvent(_)
| EventPayload::GollumEvent(_)
| EventPayload::MemberEvent(_)
| EventPayload::PublicEvent(_)
| EventPayload::PullRequestEvent(_)
| EventPayload::PullRequestReviewEvent(_)
| EventPayload::PullRequestReviewCommentEvent(_)
| EventPayload::ReleaseEvent(_)
| EventPayload::WorkflowRunEvent(_)
| EventPayload::WatchEvent(_)
| EventPayload::UnknownEvent(_) => {
Expand Down
6 changes: 6 additions & 0 deletions src/models/events/payload/public.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use serde::{Deserialize, Serialize};

/// The payload in a [`super::EventPayload::PublicEvent`] type.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PublicEventPayload {}
61 changes: 61 additions & 0 deletions src/models/events/payload/release.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use crate::models::repos::Release;
use serde::{Deserialize, Serialize};

/// The payload in a [`super::EventPayload::ReleaseEvent`] type.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ReleaseEventPayload {
/// The action this event represents.
pub action: ReleaseEventAction,
/// The release this event corresponds to.
pub release: Release,
/// The changes to body or name if this event is of type [`ReleaseEventAction::Edited`].
pub changes: Option<ReleaseEventChanges>,
}

/// The change which occurred in an event of type [`ReleaseEventAction::Edited`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ReleaseEventChanges {
Body(ReleaseEventChangesFrom),
Name(ReleaseEventChangesFrom),
}

/// The previous value of the item (either the body or title) of a release which has changed. Only
/// available in an event of type [`ReleaseEventAction::Edited`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ReleaseEventChangesFrom {
pub from: String,
}

/// The action on a release this event corresponds to.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ReleaseEventAction {
Published,
Edited,
}

#[cfg(test)]
mod test {
use crate::models::events::{
payload::{EventPayload, ReleaseEventAction},
Event,
};

#[test]
fn should_deserialize_with_correct_payload() {
let json = include_str!("../../../../tests/resources/release_event.json");
let event: Event = serde_json::from_str(json).unwrap();
if let Some(EventPayload::ReleaseEvent(ref payload)) =
event.payload.as_ref().unwrap().specific
{
assert_eq!(payload.action, ReleaseEventAction::Published);
} else {
panic!("unexpected event payload encountered: {:#?}", event.payload);
}
}
}
1 change: 1 addition & 0 deletions tests/resources/public_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
72 changes: 72 additions & 0 deletions tests/resources/release_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"id": "36029458403",
"type": "ReleaseEvent",
"actor": {
"id": 41898282,
"login": "github-actions[bot]",
"display_login": "github-actions",
"gravatar_id": "",
"url": "https://api.github.com/users/github-actions[bot]",
"avatar_url": "https://avatars.githubusercontent.com/u/41898282?"
},
"repo": {
"id": 5390641,
"name": "open-watcom/open-watcom-v2",
"url": "https://api.github.com/repos/open-watcom/open-watcom-v2"
},
"payload": {
"action": "published",
"release": {
"url": "https://api.github.com/repos/open-watcom/open-watcom-v2/releases/143718142",
"assets_url": "https://api.github.com/repos/open-watcom/open-watcom-v2/releases/143718142/assets",
"upload_url": "https://uploads.github.com/repos/open-watcom/open-watcom-v2/releases/143718142/assets{?name,label}",
"html_url": "https://github.com/open-watcom/open-watcom-v2/releases/tag/Last-CI-build",
"id": 143718142,
"author": {
"login": "github-actions[bot]",
"id": 41898282,
"node_id": "MDM6Qm90NDE4OTgyODI=",
"avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github-actions%5Bbot%5D",
"html_url": "https://github.com/apps/github-actions",
"followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
"following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
"gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
"organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
"repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
"events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
"received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
"type": "Bot",
"site_admin": false
},
"node_id": "RE_kwDOAFJBMc4IkPb-",
"tag_name": "Last-CI-build",
"target_commitish": "master",
"name": "Last-CI-build",
"draft": false,
"prerelease": true,
"created_at": "2024-02-26T23:17:41Z",
"published_at": "2024-02-26T23:17:44Z",
"assets": [

],
"tarball_url": "https://api.github.com/repos/open-watcom/open-watcom-v2/tarball/Last-CI-build",
"zipball_url": "https://api.github.com/repos/open-watcom/open-watcom-v2/zipball/Last-CI-build",
"body": "Last updated 2024-02-26 23:17:34 UTC",
"short_description_html": "<p>Last updated 2024-02-26 23:17:34 UTC</p>",
"is_short_description_html_truncated": false
}
},
"public": true,
"created_at": "2024-02-26T23:17:44Z",
"org": {
"id": 2045606,
"login": "open-watcom",
"gravatar_id": "",
"url": "https://api.github.com/orgs/open-watcom",
"avatar_url": "https://avatars.githubusercontent.com/u/2045606?"
}
}

0 comments on commit ee1c893

Please sign in to comment.