Skip to content

Commit

Permalink
* list orgs hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
feraxhp committed Sep 29, 2024
1 parent 1a2fa37 commit bece9d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
[package]
name = "grp"
version = "0.3.0-alpha"
version = "0.3.1-alpha"
edition = "2021"
license = "MIT"
authors = ["feraxhp"]
Expand Down
14 changes: 11 additions & 3 deletions src/girep/repos/common/utype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use color_print::cformat;
use serde::Deserialize;
use serde_json::Value;
use crate::girep::config::Config;
use crate::girep::errors::error::Error;
use crate::girep::errors::types::ErrorType;
Expand All @@ -11,7 +12,7 @@ use crate::girep::repos::common::supported::Platform;

pub(crate) enum UserType {
Logged, // User that is logged in
Organization, // Organization that bellongs to the logged user
Organization, // Organization that belongs to the logged user
Free, // User that is not logged in
}

Expand All @@ -21,6 +22,13 @@ struct Transpiler {
}

impl Platform {
pub fn get_org_name(&self, json: Value) -> String {
match self {
Platform::Github => json["login"].as_str().unwrap().to_string(),
Platform::Gitea => json["name"].as_str().unwrap().to_string(),
}
}

pub async fn get_user_type(&self, name: &str, conf: Config) -> Result<UserType, Error> {
match self.is_logged_user(name, conf.clone()).await {
Ok(true) => Ok(UserType::Logged),
Expand Down Expand Up @@ -113,7 +121,7 @@ impl Platform {
"Failed while fetching user type".to_string()
).await?;

let transpilers: Vec<Transpiler> = serde_json::from_str(&text.clone())
let transpilers: Vec<Value> = serde_json::from_str(&text.clone())
.map_err(
|e|
Error::new(
Expand All @@ -125,6 +133,6 @@ impl Platform {
)
)?;

Ok(transpilers.iter().any(|t| t.login == name))
Ok(transpilers.iter().any(|t| self.get_org_name(t.clone()) == name))
}
}

0 comments on commit bece9d8

Please sign in to comment.