forked from XAMPPRocky/octocrab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Public and Release events (XAMPPRocky#589)
- Loading branch information
Showing
6 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?" | ||
} | ||
} |