diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 57533be..ee39228 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -5,9 +5,6 @@ on: branches: [ main ] pull_request: -env: - CARGO_TERM_COLOR: always - jobs: build: runs-on: macos-latest @@ -26,4 +23,6 @@ jobs: - run: cargo build --manifest-path ./src-tauri/Cargo.toml --verbose - - run: cargo test --manifest-path ./src-tauri/Cargo.toml --verbose \ No newline at end of file + - run: cargo test --manifest-path ./src-tauri/Cargo.toml --verbose + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} \ No newline at end of file diff --git a/src-tauri/src/console/api.rs b/src-tauri/src/console/api.rs index 8e33f75..d11ed19 100644 --- a/src-tauri/src/console/api.rs +++ b/src-tauri/src/console/api.rs @@ -45,16 +45,7 @@ pub async fn repos(conf: ConfigData) -> Result, anyhow::Error> { #[allow(clippy::unused_unit)] pub async fn orgs(conf: ConfigData) -> Result, 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 - let request = client - .get(api.orgs()) - .header("Authorization", format!("Bearer {}", conf.token)) - .header("Accept", "application/vnd.github.v3+json") - .header("User-Agent", "Awesome-Octocat-App") - .build()?; - let organizations: Vec = client.execute(request).await?.json().await?; - Ok(organizations) + Ok(client::>(api.orgs(), api.headers(conf.token.as_str())).await?) } #[tauri::command] @@ -70,14 +61,25 @@ pub async fn org_repos(conf: ConfigData) -> Result, anyhow::Error> { #[cfg(test)] mod test { + use std::env; + use crate::conf::config::{ConfigData, Owner}; - use crate::console::api::{org_repos, repos}; + use crate::console::api::{org_repos, orgs, repos}; + + fn token() -> String { + env::var("GITHUB_TOKEN").expect("TOKEN environment variable not found") + } + + #[test] + fn test_token() { + assert_ne!(token().len(), 0); + } #[tokio::test] async fn test_repos() { let result = repos(ConfigData::new_owner( "github", - "", + token().as_str(), Owner { name: "baerwang".to_string(), repos: Vec::new(), @@ -88,22 +90,18 @@ mod test { assert_ne!(result.unwrap().len(), 0); } - /*#[tokio::test] + #[tokio::test] async fn test_orgs() { - let result = orgs(ConfigData::new( - "github", - env::var("TOKEN").unwrap().as_str(), - )) - .await; + let result = orgs(ConfigData::new("github", token().as_str())).await; 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", - "", + token().as_str(), Owner { name: "Suzaku-APIX".to_string(), repos: Vec::new(),