Skip to content

Commit

Permalink
Fix the model for parsing responses to a specific commit sha.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
atilag committed Jan 25, 2023
1 parent cd77d72 commit 6c8c640
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/api/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'octo> CurrentAuthHandler<'octo> {
}

/// Fetches information about the current user.
pub async fn user(&self) -> Result<models::User> {
pub async fn user(&self) -> Result<models::Author> {
self.crab.get("user", None::<&()>).await
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl<'octo, 'r> ListAssigneesBuilder<'octo, 'r> {
}

/// Send the actual request.
pub async fn send(self) -> Result<crate::Page<models::User>> {
pub async fn send(self) -> Result<crate::Page<models::Author>> {
let route = format!(
"repos/{owner}/{repo}/assignees",
owner = self.handler.owner,
Expand Down
2 changes: 1 addition & 1 deletion src/api/orgs/list_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<'octo, 'r> ListOrgMembersBuilder<'octo, 'r> {
self
}

pub async fn send(self) -> crate::Result<crate::Page<crate::models::User>> {
pub async fn send(self) -> crate::Result<crate::Page<crate::models::Author>> {
let url = format!("orgs/{org}/members", org = self.handler.owner);
self.handler.crab.get(url, Some(&self)).await
}
Expand Down
26 changes: 13 additions & 13 deletions src/api/repos/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ pub struct UpdateFileBuilder<'octo, 'r> {
#[serde(skip_serializing_if = "Option::is_none")]
branch: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
commiter: Option<models::repos::GitUser>,
commiter: Option<models::repos::CommitAuthor>,
#[serde(skip_serializing_if = "Option::is_none")]
author: Option<models::repos::GitUser>,
author: Option<models::repos::CommitAuthor>,
}

impl<'octo, 'r> UpdateFileBuilder<'octo, 'r> {
Expand Down Expand Up @@ -90,13 +90,13 @@ impl<'octo, 'r> UpdateFileBuilder<'octo, 'r> {
}

/// The person that commited the file.
pub fn commiter(mut self, commiter: impl Into<models::repos::GitUser>) -> Self {
pub fn commiter(mut self, commiter: impl Into<models::repos::CommitAuthor>) -> Self {
self.commiter = Some(commiter.into());
self
}

/// The author of the file.
pub fn author(mut self, author: impl Into<models::repos::GitUser>) -> Self {
pub fn author(mut self, author: impl Into<models::repos::CommitAuthor>) -> Self {
self.author = Some(author.into());
self
}
Expand Down Expand Up @@ -124,9 +124,9 @@ pub struct DeleteFileBuilder<'octo, 'r> {
#[serde(skip_serializing_if = "Option::is_none")]
branch: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
commiter: Option<models::repos::GitUser>,
commiter: Option<models::repos::CommitAuthor>,
#[serde(skip_serializing_if = "Option::is_none")]
author: Option<models::repos::GitUser>,
author: Option<models::repos::CommitAuthor>,
}

impl<'octo, 'r> DeleteFileBuilder<'octo, 'r> {
Expand Down Expand Up @@ -154,13 +154,13 @@ impl<'octo, 'r> DeleteFileBuilder<'octo, 'r> {
}

/// The person that commited the file.
pub fn commiter(mut self, commiter: impl Into<models::repos::GitUser>) -> Self {
pub fn commiter(mut self, commiter: impl Into<models::repos::CommitAuthor>) -> Self {
self.commiter = Some(commiter.into());
self
}

/// The author of the file.
pub fn author(mut self, author: impl Into<models::repos::GitUser>) -> Self {
pub fn author(mut self, author: impl Into<models::repos::CommitAuthor>) -> Self {
self.author = Some(author.into());
self
}
Expand All @@ -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() {
Expand All @@ -193,11 +193,11 @@ mod tests {
"testsha",
)
.branch("not-master")
.commiter(GitUser {
.commiter(CommitAuthor {
name: "Octocat".to_string(),
email: "[email protected]".to_string(),
})
.author(GitUser {
.author(CommitAuthor {
name: "Ferris".to_string(),
email: "[email protected]".to_string(),
});
Expand Down Expand Up @@ -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: "[email protected]".to_string(),
})
.author(GitUser {
.author(CommitAuthor {
name: "Ferris".to_string(),
email: "[email protected]".to_string(),
});
Expand Down
2 changes: 1 addition & 1 deletion src/api/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'octo> SearchHandler<'octo> {
pub fn users<'query>(
self,
query: &'query (impl AsRef<str> + ?Sized),
) -> QueryHandler<'octo, 'query, models::User> {
) -> QueryHandler<'octo, 'query, models::Author> {
QueryHandler::new(self.crab, "users", query.as_ref())
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/teams/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'octo, 'r> ListTeamMembersBuilder<'octo, 'r> {
}

/// Sends the actual request.
pub async fn send(self) -> Result<Page<models::User>> {
pub async fn send(self) -> Result<Page<models::Author>> {
let url = format!(
"orgs/{org}/teams/{team}/members",
org = self.handler.owner,
Expand Down
22 changes: 11 additions & 11 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ pub struct IssueEvent {
pub node_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
pub actor: User,
pub actor: Author,
#[serde(skip_serializing_if = "Option::is_none")]
pub assignee: Option<User>,
pub assignee: Option<Author>,
#[serde(skip_serializing_if = "Option::is_none")]
pub assignees: Option<Vec<User>>,
pub assignees: Option<Vec<Author>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub assigner: Option<User>,
pub assigner: Option<Author>,
#[serde(skip_serializing_if = "Option::is_none")]
pub labels: Option<Vec<Label>>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -259,7 +259,7 @@ pub struct Project {
pub number: u32,
#[serde(skip_serializing_if = "Option::is_none")]
pub state: Option<String>,
pub creator: User,
pub creator: Author,
pub created_at: DateTime<Utc>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<DateTime<Utc>>,
Expand Down Expand Up @@ -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,
Expand All @@ -326,7 +326,7 @@ pub struct User {
#[non_exhaustive]
pub struct StarGazer {
pub starred_at: Option<DateTime<Utc>>,
pub user: Option<User>,
pub user: Option<Author>,
}

#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -358,7 +358,7 @@ pub struct Milestone {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub creator: Option<User>,
pub creator: Option<Author>,
#[serde(skip_serializing_if = "Option::is_none")]
pub open_issues: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -382,7 +382,7 @@ pub struct Repository {
#[serde(skip_serializing_if = "Option::is_none")]
pub full_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub owner: Option<User>,
pub owner: Option<Author>,
#[serde(skip_serializing_if = "Option::is_none")]
pub private: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -682,7 +682,7 @@ pub struct Status {
pub updated_at: Option<DateTime<Utc>>,
pub state: StatusState,
#[serde(skip_serializing_if = "Option::is_none")]
pub creator: Option<User>,
pub creator: Option<Author>,
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<String>,
}
Expand All @@ -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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion src/models/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct App {
#[serde(skip_serializing_if = "Option::is_none")]
pub slug: Option<String>,
pub node_id: String,
pub owner: User,
pub owner: Author,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions src/models/events/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/models/events/payload/issues.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,7 +15,7 @@ pub struct IssuesEventPayload {
///
/// Set when they type is [`IssuesEventAction::Assigned`] or
/// [`IssuesEventAction::Unassigned`].
pub assignee: Option<User>,
pub assignee: Option<Author>,
/// The optional label added or removed from the issue.
///
/// Set when the type is [`IssuesEventAction::Labeled`] or
Expand Down
4 changes: 2 additions & 2 deletions src/models/events/payload/member.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::models::User;
use crate::models::Author;
use serde::{Deserialize, Serialize};

/// The payload in a [`super::EventPayload::MemberEvent`] type.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/models/events/payload/pull_request_review.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::models::{
pulls::{PullRequest, Review},
Repository, User,
Repository, Author,
};
use serde::{Deserialize, Serialize};

Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/models/events/payload/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct PushEventPayload {
mod test {
use crate::models::{
events::{payload::EventPayload, Event},
repos::GitUser,
repos::CommitAuthor,
};
use reqwest::Url;

Expand All @@ -43,7 +43,7 @@ mod test {
assert_eq!(commit.sha, "eb1a60c03544dcea290f2d57bb66ae188ce25778");
assert_eq!(
commit.author,
GitUser {
CommitAuthor {
name: "readme-bot".to_string(),
email: "[email protected]".to_string()
}
Expand Down
4 changes: 2 additions & 2 deletions src/models/events/payload/workflow_run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::models::{
orgs::Organization,
workflows::{Run, WorkFlow},
Repository, User,
Repository, Author,
};
use serde::{Deserialize, Serialize};

Expand All @@ -14,7 +14,7 @@ pub struct WorkflowRunEventPayload {
pub workflow: WorkFlow,
pub organization: Option<Organization>,
pub repository: Repository,
pub sender: User,
pub sender: Author,
}

/// The action on a pull request this event corresponds to.
Expand Down
2 changes: 1 addition & 1 deletion src/models/gists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct GistFile {
#[non_exhaustive]
#[derive(Debug, Deserialize)]
pub struct GistCommit {
pub user: Option<User>,
pub user: Option<Author>,
pub version: String,
pub committed_at: DateTime<Utc>,
pub change_status: GistChangeStatus,
Expand Down
8 changes: 4 additions & 4 deletions src/models/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub struct Issue {
pub body_text: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub body_html: Option<String>,
pub user: User,
pub user: Author,
pub labels: Vec<Label>,
#[serde(skip_serializing_if = "Option::is_none")]
pub assignee: Option<User>,
pub assignees: Vec<User>,
pub assignee: Option<Author>,
pub assignees: Vec<Author>,
pub author_association: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub milestone: Option<Milestone>,
Expand Down Expand Up @@ -55,7 +55,7 @@ pub struct Comment {
pub body_text: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub body_html: Option<String>,
pub user: User,
pub user: Author,
pub created_at: chrono::DateTime<chrono::Utc>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
Expand Down
2 changes: 1 addition & 1 deletion src/models/orgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub struct MembershipInvitation {
pub role: String,
pub organization_url: Url,
pub organization: Organization,
pub user: User,
pub user: Author,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down
Loading

0 comments on commit 6c8c640

Please sign in to comment.