Skip to content

Commit

Permalink
feat: console add org repos
Browse files Browse the repository at this point in the history
  • Loading branch information
baerwang committed Apr 20, 2024
1 parent 132513a commit f6b7df0
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src-tauri/src/console/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
* limitations under the License.
*/

use crate::conf::config::ConfigData;
use crate::console::model::{Org, Repo};
use crate::dispatch;
use crate::plugins::{client, get_api};
use crate::{conf, dispatch};

#[tauri::command]
pub async fn create(conf: conf::config::ConfigData) -> String {
pub async fn create(conf: ConfigData) -> String {
match conf.valid() {
"" => {
_ = dispatch::execute(conf).await;
Expand All @@ -31,7 +32,7 @@ pub async fn create(conf: conf::config::ConfigData) -> String {
}

#[tauri::command]
pub async fn repos(conf: conf::config::ConfigData) -> Result<Vec<Repo>, anyhow::Error> {
pub async fn repos(conf: ConfigData) -> Result<Vec<Repo>, anyhow::Error> {
let api = get_api(
conf.plugin.as_str(),
conf.owners.name.clone(),
Expand All @@ -42,7 +43,7 @@ pub async fn repos(conf: conf::config::ConfigData) -> Result<Vec<Repo>, anyhow::

#[tauri::command]
#[allow(clippy::unused_unit)]
pub async fn orgs(conf: conf::config::ConfigData) -> Result<Vec<Org>, anyhow::Error> {
pub async fn orgs(conf: ConfigData) -> Result<Vec<Org>, anyhow::Error> {
let api = get_api(conf.plugin.as_str(), "".to_string(), conf.reviews());
let client = reqwest::Client::new();
// todo request There is a problem with populating access with headers
Expand All @@ -58,12 +59,19 @@ pub async fn orgs(conf: conf::config::ConfigData) -> Result<Vec<Org>, anyhow::Er

#[tauri::command]
#[allow(clippy::unused_unit)]
pub fn org_repos(_org: &str) -> () {}
pub async fn org_repos(conf: ConfigData) -> Result<Vec<Repo>, anyhow::Error> {
let api = get_api(
conf.plugin.as_str(),
conf.owners.name.clone(),
conf.reviews(),
);
Ok(client::<Vec<Repo>>(api.org_repos(), api.headers(conf.token.as_str())).await?)
}

#[cfg(test)]
mod test {
use crate::conf::config::{ConfigData, Owner};
use crate::console::api::repos;
use crate::console::api::{org_repos, repos};

#[tokio::test]
async fn test_repos() {
Expand All @@ -90,4 +98,19 @@ mod test {
assert!(result.is_ok());
assert_ne!(result.unwrap().len(), 0);
}*/

#[tokio::test]
async fn test_org_repos() {
let result = org_repos(ConfigData::new_owner(
"github",
"",
Owner {
name: "Suzaku-APIX".to_string(),
repos: Vec::new(),
},
))
.await;
assert!(result.is_ok());
assert_ne!(result.unwrap().len(), 0);
}
}

0 comments on commit f6b7df0

Please sign in to comment.