Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify diff entry models #624

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/api/pulls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,16 @@ impl<'octo> PullRequestHandler<'octo> {
self.crab.delete(route, Some(&map)).await
}

/// List all `FileDiff`s associated with the pull request.
/// List all `DiffEntry`s associated with the pull request.
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let files = octocrab::instance().pulls("owner", "repo").list_files(101).await?;
/// # Ok(())
/// # }
pub async fn list_files(&self, pr: u64) -> crate::Result<Page<crate::models::pulls::FileDiff>> {
pub async fn list_files(
&self,
pr: u64,
) -> crate::Result<Page<crate::models::repos::DiffEntry>> {
let route = format!(
"/repos/{owner}/{repo}/pulls/{pr}/files",
owner = self.owner,
Expand Down
37 changes: 6 additions & 31 deletions src/models/commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct CommitComparison {
pub behind_by: i64,
pub commits: Vec<Commit>,
pub diff_url: String,
pub files: Option<Vec<CommitFile>>,
pub files: Option<Vec<repos::DiffEntry>>,
pub html_url: String,
/// Commit
pub merge_base_commit: Commit,
Expand Down Expand Up @@ -91,37 +91,12 @@ pub struct Verification {
pub verified: bool,
}

/// Diff Entry
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FileStatus {
Added,
Changed,
Copied,
Modified,
Removed,
Renamed,
Unchanged,
}
#[deprecated(note = "use repos::DiffEntryStatus instead")]
pub type FileStatus = repos::DiffEntryStatus;

/// Commit
/// Diff Entry
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommitFile {
pub additions: i64,
// unlike the schema online, this can be null
pub blob_url: Option<String>,
pub changes: i64,
pub contents_url: String,
pub deletions: i64,
pub filename: String,
pub patch: Option<String>,
pub previous_filename: Option<String>,
// unlike the schema online, this can be null
pub raw_url: Option<String>,
pub sha: String,
pub status: FileStatus,
}
#[deprecated(note = "use repos::DiffEntry instead")]
pub type CommitFile = repos::DiffEntry;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommitParent {
Expand All @@ -144,7 +119,7 @@ pub struct Commit {
pub comments_url: String,
pub commit: CommitElement,
pub committer: Option<Author>,
pub files: Option<Vec<CommitFile>>,
pub files: Option<Vec<repos::DiffEntry>>,
pub html_url: String,
pub node_id: String,
pub parents: Vec<CommitParent>,
Expand Down
31 changes: 4 additions & 27 deletions src/models/pulls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,34 +383,11 @@ pub enum MergeableState {
Unstable,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct FileDiff {
pub sha: String,
pub filename: String,
pub status: FileDiffStatus,
pub additions: u64,
pub deletions: u64,
pub changes: u64,
pub blob_url: Url,
pub raw_url: Url,
pub contents_url: Url,
pub patch: Option<String>,
pub previous_filename: Option<String>,
}
#[deprecated(note = "use repos::DiffEntry instead")]
pub type FileDiff = repos::DiffEntry;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum FileDiffStatus {
Added,
Removed,
Modified,
Renamed,
Copied,
Changed,
Unchanged,
}
#[deprecated(note = "use repos::DiffEntryStatus instead")]
pub type FileDiffStatus = repos::DiffEntryStatus;

#[cfg(test)]
mod test {
Expand Down
7 changes: 5 additions & 2 deletions src/models/repos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ pub struct DiffEntry {
pub additions: u64,
pub deletions: u64,
pub changes: u64,
pub blob_url: Url,
pub raw_url: Url,
// unlike the schema online, this can be null
pub blob_url: Option<String>,
// unlike the schema online, this can be null
pub raw_url: Option<String>,
// never null
pub contents_url: Url,

#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
Loading