Skip to content

Commit 6d4b8a7

Browse files
[octocrab] Allow committer to be Author *or* GitUser
In some cases it seems the Compare Commits endpoint (`/repos/{owner}/{repo}/compare/{base}...{head}`) will return *either* a full Author object for committer and author of each commit *or* just the name, email, etc that are in GitUser. This appears to be the case when e.g. a bot does the commit that github cannot tie to a user specifically? In any case, this change allows us to deserialize that commit comparison endpoint's results while also allowing us to get full information if it's available.
1 parent f8cd359 commit 6d4b8a7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/models/commits.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ pub struct CommitComparison {
6161

6262
#[derive(Debug, Clone, Serialize, Deserialize)]
6363
pub struct CommitElement {
64-
pub author: Option<GitUser>,
64+
pub author: Option<CommitAuthor>,
6565
pub comment_count: i64,
66-
pub committer: Option<GitUser>,
66+
pub committer: Option<CommitAuthor>,
6767
pub message: String,
6868
pub tree: Tree,
6969
pub url: String,
@@ -113,13 +113,23 @@ pub struct CommitStats {
113113
pub total: Option<i64>,
114114
}
115115

116+
/// The 'author' and 'committer' fields can either be
117+
/// a full set of Author details *or* sometimes, if done
118+
/// by a bot, etc, just have the git information.
119+
#[derive(Debug, Clone, Serialize, Deserialize)]
120+
#[serde(untagged)]
121+
pub enum CommitAuthor {
122+
Author(Author),
123+
GitUser(GitUser),
124+
}
125+
116126
/// Commit
117127
#[derive(Debug, Clone, Serialize, Deserialize)]
118128
pub struct Commit {
119-
pub author: Option<Author>,
129+
pub author: Option<GitUser>,
120130
pub comments_url: String,
121131
pub commit: CommitElement,
122-
pub committer: Option<Author>,
132+
pub committer: Option<GitUser>,
123133
pub files: Option<Vec<repos::DiffEntry>>,
124134
pub html_url: String,
125135
pub node_id: String,

0 commit comments

Comments
 (0)