From 6c8c640707369add069f6ce6d53d226084384538 Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Tue, 24 Jan 2023 20:57:56 -0500 Subject: [PATCH] Fix the model for parsing responses to a specific commit sha. The response from Github to something like: https://api.github.com/repos/[owner]/[repo]/commits/[sha], has two type of Authors. Prior to these changes the "author" key in the root level has different fields than the "author" key from the praent "commit" key. This commit fixes the problem by properly naming the fields so the parser don't mix the two "author" keys. --- src/api/current.rs | 2 +- src/api/issues.rs | 2 +- src/api/orgs/list_members.rs | 2 +- src/api/repos/file.rs | 26 +++++++++---------- src/api/search.rs | 2 +- src/api/teams/members.rs | 2 +- src/models.rs | 22 ++++++++-------- src/models/apps.rs | 2 +- src/models/events/payload.rs | 4 +-- src/models/events/payload/issues.rs | 4 +-- src/models/events/payload/member.rs | 4 +-- .../events/payload/pull_request_review.rs | 4 +-- src/models/events/payload/push.rs | 4 +-- src/models/events/payload/workflow_run.rs | 4 +-- src/models/gists.rs | 2 +- src/models/issues.rs | 8 +++--- src/models/orgs.rs | 2 +- src/models/pulls.rs | 16 ++++++------ src/models/reactions.rs | 2 +- src/models/repos.rs | 16 ++++++------ src/models/teams.rs | 4 +-- src/models/workflows.rs | 4 +-- tests/org_members_tests.rs | 4 +-- tests/team_members_tests.rs | 4 +-- 24 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/api/current.rs b/src/api/current.rs index 877d4765..0c3b634e 100644 --- a/src/api/current.rs +++ b/src/api/current.rs @@ -21,7 +21,7 @@ impl<'octo> CurrentAuthHandler<'octo> { } /// Fetches information about the current user. - pub async fn user(&self) -> Result { + pub async fn user(&self) -> Result { self.crab.get("user", None::<&()>).await } diff --git a/src/api/issues.rs b/src/api/issues.rs index 172c7ed2..c0a757e0 100644 --- a/src/api/issues.rs +++ b/src/api/issues.rs @@ -304,7 +304,7 @@ impl<'octo, 'r> ListAssigneesBuilder<'octo, 'r> { } /// Send the actual request. - pub async fn send(self) -> Result> { + pub async fn send(self) -> Result> { let route = format!( "repos/{owner}/{repo}/assignees", owner = self.handler.owner, diff --git a/src/api/orgs/list_members.rs b/src/api/orgs/list_members.rs index 20f149d2..993ea367 100644 --- a/src/api/orgs/list_members.rs +++ b/src/api/orgs/list_members.rs @@ -31,7 +31,7 @@ impl<'octo, 'r> ListOrgMembersBuilder<'octo, 'r> { self } - pub async fn send(self) -> crate::Result> { + pub async fn send(self) -> crate::Result> { let url = format!("orgs/{org}/members", org = self.handler.owner); self.handler.crab.get(url, Some(&self)).await } diff --git a/src/api/repos/file.rs b/src/api/repos/file.rs index 4ad8eed4..eeda0e7c 100644 --- a/src/api/repos/file.rs +++ b/src/api/repos/file.rs @@ -58,9 +58,9 @@ pub struct UpdateFileBuilder<'octo, 'r> { #[serde(skip_serializing_if = "Option::is_none")] branch: Option, #[serde(skip_serializing_if = "Option::is_none")] - commiter: Option, + commiter: Option, #[serde(skip_serializing_if = "Option::is_none")] - author: Option, + author: Option, } impl<'octo, 'r> UpdateFileBuilder<'octo, 'r> { @@ -90,13 +90,13 @@ impl<'octo, 'r> UpdateFileBuilder<'octo, 'r> { } /// The person that commited the file. - pub fn commiter(mut self, commiter: impl Into) -> Self { + pub fn commiter(mut self, commiter: impl Into) -> Self { self.commiter = Some(commiter.into()); self } /// The author of the file. - pub fn author(mut self, author: impl Into) -> Self { + pub fn author(mut self, author: impl Into) -> Self { self.author = Some(author.into()); self } @@ -124,9 +124,9 @@ pub struct DeleteFileBuilder<'octo, 'r> { #[serde(skip_serializing_if = "Option::is_none")] branch: Option, #[serde(skip_serializing_if = "Option::is_none")] - commiter: Option, + commiter: Option, #[serde(skip_serializing_if = "Option::is_none")] - author: Option, + author: Option, } impl<'octo, 'r> DeleteFileBuilder<'octo, 'r> { @@ -154,13 +154,13 @@ impl<'octo, 'r> DeleteFileBuilder<'octo, 'r> { } /// The person that commited the file. - pub fn commiter(mut self, commiter: impl Into) -> Self { + pub fn commiter(mut self, commiter: impl Into) -> Self { self.commiter = Some(commiter.into()); self } /// The author of the file. - pub fn author(mut self, author: impl Into) -> Self { + pub fn author(mut self, author: impl Into) -> Self { self.author = Some(author.into()); self } @@ -179,7 +179,7 @@ impl<'octo, 'r> DeleteFileBuilder<'octo, 'r> { #[cfg(test)] mod tests { - use crate::models::repos::GitUser; + use crate::models::repos::CommitAuthor; #[test] fn serialize() { @@ -193,11 +193,11 @@ mod tests { "testsha", ) .branch("not-master") - .commiter(GitUser { + .commiter(CommitAuthor { name: "Octocat".to_string(), email: "octocat@github.com".to_string(), }) - .author(GitUser { + .author(CommitAuthor { name: "Ferris".to_string(), email: "ferris@rust-lang.org".to_string(), }); @@ -228,11 +228,11 @@ mod tests { let builder = repo .delete_file("tests/test.txt", "Update test.txt", "testsha") .branch("not-master") - .commiter(GitUser { + .commiter(CommitAuthor { name: "Octocat".to_string(), email: "octocat@github.com".to_string(), }) - .author(GitUser { + .author(CommitAuthor { name: "Ferris".to_string(), email: "ferris@rust-lang.org".to_string(), }); diff --git a/src/api/search.rs b/src/api/search.rs index cfb4de36..4f5625fb 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -70,7 +70,7 @@ impl<'octo> SearchHandler<'octo> { pub fn users<'query>( self, query: &'query (impl AsRef + ?Sized), - ) -> QueryHandler<'octo, 'query, models::User> { + ) -> QueryHandler<'octo, 'query, models::Author> { QueryHandler::new(self.crab, "users", query.as_ref()) } diff --git a/src/api/teams/members.rs b/src/api/teams/members.rs index 3d94a7fc..ce61b60e 100644 --- a/src/api/teams/members.rs +++ b/src/api/teams/members.rs @@ -36,7 +36,7 @@ impl<'octo, 'r> ListTeamMembersBuilder<'octo, 'r> { } /// Sends the actual request. - pub async fn send(self) -> Result> { + pub async fn send(self) -> Result> { let url = format!( "orgs/{org}/teams/{team}/members", org = self.handler.owner, diff --git a/src/models.rs b/src/models.rs index 51d3d6a2..3738d5b4 100644 --- a/src/models.rs +++ b/src/models.rs @@ -208,13 +208,13 @@ pub struct IssueEvent { pub node_id: Option, #[serde(skip_serializing_if = "Option::is_none")] pub url: Option, - pub actor: User, + pub actor: Author, #[serde(skip_serializing_if = "Option::is_none")] - pub assignee: Option, + pub assignee: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub assignees: Option>, + pub assignees: Option>, #[serde(skip_serializing_if = "Option::is_none")] - pub assigner: Option, + pub assigner: Option, #[serde(skip_serializing_if = "Option::is_none")] pub labels: Option>, #[serde(skip_serializing_if = "Option::is_none")] @@ -259,7 +259,7 @@ pub struct Project { pub number: u32, #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, - pub creator: User, + pub creator: Author, pub created_at: DateTime, #[serde(skip_serializing_if = "Option::is_none")] pub updated_at: Option>, @@ -301,7 +301,7 @@ pub struct IssuePullRequest { #[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] #[non_exhaustive] -pub struct User { +pub struct Author { pub login: String, pub id: UserId, pub node_id: String, @@ -326,7 +326,7 @@ pub struct User { #[non_exhaustive] pub struct StarGazer { pub starred_at: Option>, - pub user: Option, + pub user: Option, } #[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] @@ -358,7 +358,7 @@ pub struct Milestone { #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub creator: Option, + pub creator: Option, #[serde(skip_serializing_if = "Option::is_none")] pub open_issues: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -382,7 +382,7 @@ pub struct Repository { #[serde(skip_serializing_if = "Option::is_none")] pub full_name: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub owner: Option, + pub owner: Option, #[serde(skip_serializing_if = "Option::is_none")] pub private: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -682,7 +682,7 @@ pub struct Status { pub updated_at: Option>, pub state: StatusState, #[serde(skip_serializing_if = "Option::is_none")] - pub creator: Option, + pub creator: Option, #[serde(skip_serializing_if = "Option::is_none")] pub context: Option, } @@ -709,7 +709,7 @@ pub struct InstallationRepositories { #[non_exhaustive] pub struct Installation { pub id: InstallationId, - pub account: User, + pub account: Author, #[serde(skip_serializing_if = "Option::is_none")] pub access_tokens_url: Option, #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/models/apps.rs b/src/models/apps.rs index 21b109d0..ea07c557 100644 --- a/src/models/apps.rs +++ b/src/models/apps.rs @@ -8,7 +8,7 @@ pub struct App { #[serde(skip_serializing_if = "Option::is_none")] pub slug: Option, pub node_id: String, - pub owner: User, + pub owner: Author, pub name: String, #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, diff --git a/src/models/events/payload.rs b/src/models/events/payload.rs index be322b4a..461366f9 100644 --- a/src/models/events/payload.rs +++ b/src/models/events/payload.rs @@ -12,7 +12,7 @@ mod pull_request_review_comment; mod push; mod workflow_run; -use crate::models::repos::GitUser; +use crate::models::repos::CommitAuthor; pub use commit_comment::*; pub use create::*; pub use delete::*; @@ -60,7 +60,7 @@ pub enum EventPayload { #[non_exhaustive] pub struct Commit { pub sha: String, - pub author: GitUser, + pub author: CommitAuthor, pub message: String, pub distinct: bool, pub url: Url, diff --git a/src/models/events/payload/issues.rs b/src/models/events/payload/issues.rs index 86fd07aa..6ce08929 100644 --- a/src/models/events/payload/issues.rs +++ b/src/models/events/payload/issues.rs @@ -1,4 +1,4 @@ -use crate::models::{issues::Issue, Label, User}; +use crate::models::{issues::Issue, Label, Author}; use serde::{Deserialize, Serialize}; /// The payload in a [`super::EventPayload::IssuesEvent`] type. @@ -15,7 +15,7 @@ pub struct IssuesEventPayload { /// /// Set when they type is [`IssuesEventAction::Assigned`] or /// [`IssuesEventAction::Unassigned`]. - pub assignee: Option, + pub assignee: Option, /// The optional label added or removed from the issue. /// /// Set when the type is [`IssuesEventAction::Labeled`] or diff --git a/src/models/events/payload/member.rs b/src/models/events/payload/member.rs index cc5a2c85..eec764bf 100644 --- a/src/models/events/payload/member.rs +++ b/src/models/events/payload/member.rs @@ -1,4 +1,4 @@ -use crate::models::User; +use crate::models::Author; use serde::{Deserialize, Serialize}; /// The payload in a [`super::EventPayload::MemberEvent`] type. @@ -8,7 +8,7 @@ pub struct MemberEventPayload { /// The action this event represents. pub action: MemberEventAction, /// The user this event corresponds to. - pub member: User, + pub member: Author, /// Only available on webhooks. /// /// Changes to the collaborator permissions. diff --git a/src/models/events/payload/pull_request_review.rs b/src/models/events/payload/pull_request_review.rs index 148f0ee1..222ce30a 100644 --- a/src/models/events/payload/pull_request_review.rs +++ b/src/models/events/payload/pull_request_review.rs @@ -1,6 +1,6 @@ use crate::models::{ pulls::{PullRequest, Review}, - Repository, User, + Repository, Author, }; use serde::{Deserialize, Serialize}; @@ -19,7 +19,7 @@ pub struct PullRequestReviewEventPayload { /// The repository where the event occurred. pub repository: Repository, /// The user that triggered the event. - pub sender: User, + pub sender: Author, } /// The action on a pull request review this event corresponds to. diff --git a/src/models/events/payload/push.rs b/src/models/events/payload/push.rs index 1179547f..3812b346 100644 --- a/src/models/events/payload/push.rs +++ b/src/models/events/payload/push.rs @@ -20,7 +20,7 @@ pub struct PushEventPayload { mod test { use crate::models::{ events::{payload::EventPayload, Event}, - repos::GitUser, + repos::CommitAuthor, }; use reqwest::Url; @@ -43,7 +43,7 @@ mod test { assert_eq!(commit.sha, "eb1a60c03544dcea290f2d57bb66ae188ce25778"); assert_eq!( commit.author, - GitUser { + CommitAuthor { name: "readme-bot".to_string(), email: "readme-bot@example.com".to_string() } diff --git a/src/models/events/payload/workflow_run.rs b/src/models/events/payload/workflow_run.rs index 970b42d3..34fc570a 100644 --- a/src/models/events/payload/workflow_run.rs +++ b/src/models/events/payload/workflow_run.rs @@ -1,7 +1,7 @@ use crate::models::{ orgs::Organization, workflows::{Run, WorkFlow}, - Repository, User, + Repository, Author, }; use serde::{Deserialize, Serialize}; @@ -14,7 +14,7 @@ pub struct WorkflowRunEventPayload { pub workflow: WorkFlow, pub organization: Option, pub repository: Repository, - pub sender: User, + pub sender: Author, } /// The action on a pull request this event corresponds to. diff --git a/src/models/gists.rs b/src/models/gists.rs index 3f9411a9..f1b7ff8e 100644 --- a/src/models/gists.rs +++ b/src/models/gists.rs @@ -35,7 +35,7 @@ pub struct GistFile { #[non_exhaustive] #[derive(Debug, Deserialize)] pub struct GistCommit { - pub user: Option, + pub user: Option, pub version: String, pub committed_at: DateTime, pub change_status: GistChangeStatus, diff --git a/src/models/issues.rs b/src/models/issues.rs index 0bb0b5d0..fdfb227f 100644 --- a/src/models/issues.rs +++ b/src/models/issues.rs @@ -20,11 +20,11 @@ pub struct Issue { pub body_text: Option, #[serde(skip_serializing_if = "Option::is_none")] pub body_html: Option, - pub user: User, + pub user: Author, pub labels: Vec