✨ 新增个人访问令牌、使用统计与配置校验功能
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use super::{AppConfig, GitProfile};
|
||||
use super::{AppConfig, GitProfile, TokenConfig, TokenType};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -75,12 +75,10 @@ impl ConfigManager {
|
||||
bail!("Profile '{}' does not exist", name);
|
||||
}
|
||||
|
||||
// Check if it's the default profile
|
||||
if self.config.default_profile.as_ref() == Some(&name.to_string()) {
|
||||
self.config.default_profile = None;
|
||||
}
|
||||
|
||||
// Remove from repo mappings
|
||||
self.config.repo_profiles.retain(|_, v| v != name);
|
||||
|
||||
self.config.profiles.remove(name);
|
||||
@@ -144,6 +142,56 @@ impl ConfigManager {
|
||||
self.config.default_profile.as_ref()
|
||||
}
|
||||
|
||||
/// Record profile usage
|
||||
pub fn record_profile_usage(&mut self, name: &str, repo_path: Option<String>) -> Result<()> {
|
||||
if let Some(profile) = self.config.profiles.get_mut(name) {
|
||||
profile.record_usage(repo_path);
|
||||
self.modified = true;
|
||||
Ok(())
|
||||
} else {
|
||||
bail!("Profile '{}' does not exist", name);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get profile usage statistics
|
||||
pub fn get_profile_usage(&self, name: &str) -> Option<&super::UsageStats> {
|
||||
self.config.profiles.get(name).map(|p| &p.usage)
|
||||
}
|
||||
|
||||
// Token management
|
||||
|
||||
/// Add a token to a profile
|
||||
pub fn add_token_to_profile(&mut self, profile_name: &str, service: String, token: TokenConfig) -> Result<()> {
|
||||
if let Some(profile) = self.config.profiles.get_mut(profile_name) {
|
||||
profile.add_token(service, token);
|
||||
self.modified = true;
|
||||
Ok(())
|
||||
} else {
|
||||
bail!("Profile '{}' does not exist", profile_name);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a token from a profile
|
||||
pub fn get_token_from_profile(&self, profile_name: &str, service: &str) -> Option<&TokenConfig> {
|
||||
self.config.profiles.get(profile_name)?.get_token(service)
|
||||
}
|
||||
|
||||
/// Remove a token from a profile
|
||||
pub fn remove_token_from_profile(&mut self, profile_name: &str, service: &str) -> Result<()> {
|
||||
if let Some(profile) = self.config.profiles.get_mut(profile_name) {
|
||||
profile.remove_token(service);
|
||||
self.modified = true;
|
||||
Ok(())
|
||||
} else {
|
||||
bail!("Profile '{}' does not exist", profile_name);
|
||||
}
|
||||
}
|
||||
|
||||
/// List all tokens in a profile
|
||||
pub fn list_profile_tokens(&self, profile_name: &str) -> Option<Vec<&String>> {
|
||||
self.config.profiles.get(profile_name).map(|p| p.tokens.keys().collect())
|
||||
}
|
||||
|
||||
// Repository profile management
|
||||
|
||||
/// Get profile for repository
|
||||
@@ -185,6 +233,13 @@ impl ConfigManager {
|
||||
self.default_profile()
|
||||
}
|
||||
|
||||
/// Check and compare profile with git configuration
|
||||
pub fn check_profile_config(&self, profile_name: &str, repo: &git2::Repository) -> Result<super::ProfileComparison> {
|
||||
let profile = self.get_profile(profile_name)
|
||||
.ok_or_else(|| anyhow::anyhow!("Profile '{}' not found", profile_name))?;
|
||||
profile.compare_with_git_config(repo)
|
||||
}
|
||||
|
||||
// LLM configuration
|
||||
|
||||
/// Get LLM provider
|
||||
|
||||
Reference in New Issue
Block a user