Skip to content
Draft
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
29 changes: 15 additions & 14 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/bin/sh
# Pre-commit hook to check Rust code formatting
# Pre-commit hook to format and lint Rust code automatically

echo "Running cargo fmt check..."
cargo fmt --check
if [ $? -ne 0 ]; then
echo ""
echo "ERROR: Code formatting issues found!"
echo "Please run 'cargo fmt' before committing."
exit 1
set -e

STAGED_RUST_FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.rs')

echo "Formatting Rust code (cargo fmt)..."
cargo fmt

if [ -n "$STAGED_RUST_FILES" ]; then
printf '%s\n' "$STAGED_RUST_FILES" | while IFS= read -r file; do
[ -n "$file" ] && git add "$file"
done
echo "Re-staged formatted Rust files."
else
echo "No staged Rust files detected; formatted workspace."
fi

echo "Running cargo clippy..."
cargo clippy -- -D warnings
if [ $? -ne 0 ]; then
echo ""
echo "ERROR: Clippy warnings found!"
echo "Please fix the issues before committing."
exit 1
fi

echo "Pre-commit checks passed!"
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ cargo clippy
### Code Style

- Follow Rust's official style guidelines
- Run `cargo fmt` before committing (enforced by pre-commit hook)
- Run `cargo clippy` to catch common mistakes (enforced by pre-commit hook)
- Enable repo hooks (`git config core.hooksPath .githooks`); pre-commit automatically runs `cargo fmt`, re-stages formatted Rust files, and runs `cargo clippy`
- Run `cargo fmt` / `cargo clippy` manually when you want fast feedback
- Write documentation for public APIs
- Use meaningful variable and function names

Expand Down
12 changes: 7 additions & 5 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,10 @@ pub fn delete_budget(account_id: &str) -> Result<()> {
let db = get_connection()?;
let conn = db.as_ref().unwrap();

conn.execute("DELETE FROM budgets WHERE account_id = ?", params![account_id])?;
conn.execute(
"DELETE FROM budgets WHERE account_id = ?",
params![account_id],
)?;

tracing::info!("Deleted budget for account {}", account_id);
Ok(())
Expand All @@ -750,11 +753,10 @@ pub fn get_budget_status(account_id: &str) -> Result<Option<BudgetStatus>> {
.ok_or_else(|| anyhow::anyhow!("Account not found"))?;

// Get cached cost summary
let cost_summary = get_cached_cost_summary_with_account(account_id, &account.name, &account.provider)?;
let cost_summary =
get_cached_cost_summary_with_account(account_id, &account.name, &account.provider)?;

let current_cost = cost_summary
.map(|cs| cs.current_month_cost)
.unwrap_or(0.0);
let current_cost = cost_summary.map(|cs| cs.current_month_cost).unwrap_or(0.0);

// Calculate metrics
let percentage_used = if budget.monthly_budget > 0.0 {
Expand Down
40 changes: 20 additions & 20 deletions src/ui/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,38 +104,38 @@ impl AccountsView {
// Update input placeholders based on cloud provider
match provider {
CloudProvider::AWS => {
self.ak_input.update(cx, |state, _cx| {
state.set_placeholder("Access Key ID");
self.ak_input.update(cx, |state, cx| {
state.set_placeholder("Access Key ID", window, cx);
});
self.sk_input.update(cx, |state, _cx| {
state.set_placeholder("Secret Access Key");
self.sk_input.update(cx, |state, cx| {
state.set_placeholder("Secret Access Key", window, cx);
});
self.region_input.update(cx, |state, _cx| {
state.set_placeholder("Region (optional, default us-east-1)");
state.set_default_value("us-east-1");
self.region_input.update(cx, |state, cx| {
state.set_placeholder("Region (optional, default us-east-1)", window, cx);
state.set_value("us-east-1", window, cx);
});
}
CloudProvider::Aliyun => {
self.ak_input.update(cx, |state, _cx| {
state.set_placeholder("AccessKey ID");
self.ak_input.update(cx, |state, cx| {
state.set_placeholder("AccessKey ID", window, cx);
});
self.sk_input.update(cx, |state, _cx| {
state.set_placeholder("AccessKey Secret");
self.sk_input.update(cx, |state, cx| {
state.set_placeholder("AccessKey Secret", window, cx);
});
self.region_input.update(cx, |state, _cx| {
state.set_placeholder("Region (optional, default cn-hangzhou)");
state.set_default_value("cn-hangzhou");
self.region_input.update(cx, |state, cx| {
state.set_placeholder("Region (optional, default cn-hangzhou)", window, cx);
state.set_value("cn-hangzhou", window, cx);
});
}
CloudProvider::DeepSeek => {
self.ak_input.update(cx, |state, _cx| {
state.set_placeholder("API Key");
self.ak_input.update(cx, |state, cx| {
state.set_placeholder("API Key", window, cx);
});
self.sk_input.update(cx, |state, _cx| {
state.set_placeholder("(Not required, leave empty)");
self.sk_input.update(cx, |state, cx| {
state.set_placeholder("(Not required, leave empty)", window, cx);
});
self.region_input.update(cx, |state, _cx| {
state.set_placeholder("(Not required)");
self.region_input.update(cx, |state, cx| {
state.set_placeholder("(Not required)", window, cx);
});
}

Expand Down
Loading