Skip to content
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
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
12 changes: 7 additions & 5 deletions src/pull_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PullRequestResponse>,
/// Total number of matching open pull requests across all pages
pub total_count: usize,
}

Expand All @@ -18,20 +19,21 @@ 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,
}

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!();
Expand Down
15 changes: 3 additions & 12 deletions tests/network_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,7 @@ async fn test_get_pull_requests() {
);
let result = network.get_json::<PullRequestItems>(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);
}
Loading