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
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tokio = { version = "1.48.0", features = ["full"] }
serde = { version = "1.0.228", features = ["derive"] }
clap = { version = "4.5.53", features = ["derive"] }
comfy-table = "7.2.1"
demand = "2.0.0"
demand = "1.8.2"
console = "0.16.2"
colored = "3.0.0"
httpmock = "0.8.2"
Expand Down
6 changes: 4 additions & 2 deletions src/repos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{cli_output::CliOutput, network::Network};
pub struct RepoResponse {
pub name: String,
pub html_url: String,
pub archived: bool,
}

/// Repository operations handler
Expand Down Expand Up @@ -37,11 +38,12 @@ impl Repos {
}
}

/// Requests the repository list from the API
/// Requests the repository list from the API, excluding archived repositories
pub async fn response() -> Result<Vec<RepoResponse>, reqwest::Error> {
let network = Network::new();
let url = format!("{}/orgs/heroesofcode/repos", network.base_url());
network.get_json(&url).await
let repos: Vec<RepoResponse> = network.get_json(&url).await?;
Ok(repos.into_iter().filter(|r| !r.archived).collect())
}

/// Renders repository data in a terminal table
Expand Down
6 changes: 4 additions & 2 deletions tests/network_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ async fn test_get_json_success() {
then.status(200).json_body_obj(&vec![
serde_json::json!({
"name": "ViewState",
"html_url": "https://github.com/heroesofcode/ViewState"
"html_url": "https://github.com/heroesofcode/ViewState",
"archived": false
}),
serde_json::json!({
"name": "DataLife",
"html_url": "https://github.com/heroesofcode/DataLife"
"html_url": "https://github.com/heroesofcode/DataLife",
"archived": false
}),
]);
});
Expand Down
9 changes: 5 additions & 4 deletions tests/repos_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use httpmock::MockServer;
fn test_repo_response_deserialization() {
let json = r#"{
"name": "test-repo",
"html_url": "https://github.com/heroesofcode/test-repo"
"html_url": "https://github.com/heroesofcode/test-repo",
"archived": false
}"#;

let repo: RepoResponse = serde_json::from_str(json).unwrap();
Expand Down Expand Up @@ -38,9 +39,9 @@ async fn test_repos_multiple_items() {
server.mock(|when, then| {
when.method(GET).path("/orgs/heroesofcode/repos");
then.status(200).json_body_obj(&vec![
serde_json::json!({"name": "repo1", "html_url": "https://github.com/heroesofcode/repo1"}),
serde_json::json!({"name": "repo2", "html_url": "https://github.com/heroesofcode/repo2"}),
serde_json::json!({"name": "repo3", "html_url": "https://github.com/heroesofcode/repo3"}),
serde_json::json!({"name": "repo1", "html_url": "https://github.com/heroesofcode/repo1", "archived": false}),
serde_json::json!({"name": "repo2", "html_url": "https://github.com/heroesofcode/repo2", "archived": false}),
serde_json::json!({"name": "repo3", "html_url": "https://github.com/heroesofcode/repo3", "archived": false}),
]);
});

Expand Down
Loading