diff --git a/src/cli.rs b/src/cli.rs index 28b73e6..8a0acdc 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -42,7 +42,7 @@ impl Cli { Clone::clone_repos(true).await?; } Some(Command::Pr) => { - PullRequests::pull_requests_open().await?; + PullRequests::list_open().await?; } None => { println!("Run {}", "heroesofcode --help".blue()); diff --git a/src/pull_requests.rs b/src/pull_requests.rs index 0cc98d1..e58d69d 100644 --- a/src/pull_requests.rs +++ b/src/pull_requests.rs @@ -7,8 +7,9 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct PullRequestItems { - /// Array of all open pull requests + /// Pull requests returned in the current page of results pub items: Vec, + /// Total number of matching open pull requests across all pages pub total_count: usize, } @@ -18,12 +19,12 @@ pub struct PullRequestResponse { pub html_url: String, /// PR title pub title: String, - /// User information who opened the PR - pub user: User, + /// User information for the user who opened the PR + pub user: PullRequestUser, } #[derive(Debug, Serialize, Deserialize)] -pub struct User { +pub struct PullRequestUser { /// Username of the user who opened the PR pub login: String, } @@ -31,7 +32,8 @@ pub struct User { pub struct PullRequests; impl PullRequests { - pub async fn pull_requests_open() -> Result<(), reqwest::Error> { + /// Fetch open pull requests (first page of paginated results) + pub async fn list_open() -> Result<(), reqwest::Error> { match Self::response().await { Ok(result) => { println!(); diff --git a/tests/network_tests.rs b/tests/network_tests.rs index bc4787b..37faba4 100644 --- a/tests/network_tests.rs +++ b/tests/network_tests.rs @@ -62,16 +62,7 @@ async fn test_get_pull_requests() { ); let result = network.get_json::(url).await; - match &result { - Ok(prs) => { - assert_eq!(prs.total_count, 2); - assert_eq!(prs.items.len(), 2); - assert_eq!(prs.items[0].title, "Test PR 1"); - assert_eq!(prs.items[0].user.login, "testuser1"); - } - Err(e) => { - eprintln!("Error: {}", e); - panic!("Request failed: {}", e); - } - } + let prs = result.expect("Failed to get pull requests"); + assert_eq!(prs.total_count, 2); + assert_eq!(prs.items.len(), 2); }