Skip to content

Commit

Permalink
feat: use pagination to fetch commits
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Nov 27, 2021
1 parent d4079a6 commit 3b84847
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/octo/commits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use octocrab::Octocrab;
use octocrab::{Octocrab, Page};
use rocket::serde::{Deserialize, Serialize};

#[async_trait::async_trait]
Expand All @@ -20,7 +20,16 @@ impl GetCommits for Octocrab {
pr_number: u64,
) -> octocrab::Result<Vec<CommitObjectDto>> {
let url = format!("/repos/{}/{}/pulls/{}/commits", owner, repo, pr_number);
self.get(url, None::<&()>).await
let mut current_page: Page<CommitObjectDto> = self.get(url, None::<&()>).await?;
let mut response = current_page.take_items();

while let Ok(Some(mut new_page)) = self.get_page(&current_page.next).await {
response.extend(new_page.take_items());

current_page = new_page;
}

Ok(response)
}
}

Expand Down

0 comments on commit 3b84847

Please sign in to comment.