Skip to content
Merged
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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -68,13 +70,14 @@ jobs:
run: cargo llvm-cov --lib --codecov --output-path codecov.json

- name: Upload coverage to Codecov
if: ${{ env.CODECOV_TOKEN != '' }}
uses: codecov/codecov-action@v4
with:
files: ./codecov.json
flags: unittests
name: code-coverage
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ env.CODECOV_TOKEN }}

lint:
name: Lint
Expand Down
80 changes: 28 additions & 52 deletions src/app/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,16 @@ fn handle_new_task_dialog_key(
KeyCode::Right if state.focused_field == NewTaskField::UseExistingDirectory => {
state.use_existing_directory = true;
}
KeyCode::Left if state.focused_field == NewTaskField::Repo => {
if !repos.is_empty() {
state.repo_idx = state.repo_idx.saturating_sub(1);
if let Some(repo) = repos.get(state.repo_idx) {
state.base_input = repo_default_base(repo);
}
KeyCode::Left if state.focused_field == NewTaskField::Repo && !repos.is_empty() => {
state.repo_idx = state.repo_idx.saturating_sub(1);
if let Some(repo) = repos.get(state.repo_idx) {
state.base_input = repo_default_base(repo);
}
}
KeyCode::Right if state.focused_field == NewTaskField::Repo => {
if !repos.is_empty() {
state.repo_idx = (state.repo_idx + 1).min(repos.len() - 1);
if let Some(repo) = repos.get(state.repo_idx) {
state.base_input = repo_default_base(repo);
}
KeyCode::Right if state.focused_field == NewTaskField::Repo && !repos.is_empty() => {
state.repo_idx = (state.repo_idx + 1).min(repos.len() - 1);
if let Some(repo) = repos.get(state.repo_idx) {
state.base_input = repo_default_base(repo);
}
}
KeyCode::Left if state.focused_field == NewTaskField::Create => {
Expand Down Expand Up @@ -700,21 +696,17 @@ fn handle_new_project_dialog_key(
KeyCode::Right if state.focused_field == NewProjectField::Cancel => {
state.focused_field = NewProjectField::Create;
}
KeyCode::Backspace => {
if state.focused_field == NewProjectField::Name {
state.name_input.pop();
}
KeyCode::Backspace if state.focused_field == NewProjectField::Name => {
state.name_input.pop();
}
KeyCode::Enter => {
*follow_up = Some(match state.focused_field {
NewProjectField::Cancel => Message::DismissDialog,
_ => Message::CreateProject,
});
}
KeyCode::Char(ch) => {
if state.focused_field == NewProjectField::Name {
state.name_input.push(ch);
}
KeyCode::Char(ch) if state.focused_field == NewProjectField::Name => {
state.name_input.push(ch);
}
_ => {}
}
Expand Down Expand Up @@ -760,21 +752,17 @@ fn handle_category_input_dialog_key(
KeyCode::Right if state.focused_field == CategoryInputField::Cancel => {
state.focused_field = CategoryInputField::Confirm;
}
KeyCode::Backspace => {
if state.focused_field == CategoryInputField::Name {
state.name_input.pop();
}
KeyCode::Backspace if state.focused_field == CategoryInputField::Name => {
state.name_input.pop();
}
KeyCode::Enter => {
*follow_up = Some(match state.focused_field {
CategoryInputField::Cancel => Message::DismissDialog,
_ => Message::SubmitCategoryInput,
});
}
KeyCode::Char(ch) => {
if state.focused_field == CategoryInputField::Name {
state.name_input.push(ch);
}
KeyCode::Char(ch) if state.focused_field == CategoryInputField::Name => {
state.name_input.push(ch);
}
_ => {}
}
Expand Down Expand Up @@ -967,21 +955,17 @@ fn handle_edit_task_dialog_key(
KeyCode::Right if state.focused_field == EditTaskField::Cancel => {
state.focused_field = EditTaskField::Save;
}
KeyCode::Backspace => {
if state.focused_field == EditTaskField::Title {
state.title_input.pop();
}
KeyCode::Backspace if state.focused_field == EditTaskField::Title => {
state.title_input.pop();
}
KeyCode::Enter => {
*follow_up = Some(match state.focused_field {
EditTaskField::Cancel => Message::DismissDialog,
_ => Message::ConfirmEditTask,
});
}
KeyCode::Char(ch) => {
if state.focused_field == EditTaskField::Title {
state.title_input.push(ch);
}
KeyCode::Char(ch) if state.focused_field == EditTaskField::Title => {
state.title_input.push(ch);
}
_ => {}
}
Expand Down Expand Up @@ -1127,21 +1111,17 @@ fn handle_rename_project_dialog_key(
KeyCode::Right if state.focused_field == RenameProjectField::Cancel => {
state.focused_field = RenameProjectField::Confirm;
}
KeyCode::Backspace => {
if state.focused_field == RenameProjectField::Name {
state.name_input.pop();
}
KeyCode::Backspace if state.focused_field == RenameProjectField::Name => {
state.name_input.pop();
}
KeyCode::Enter => {
*follow_up = Some(match state.focused_field {
RenameProjectField::Cancel => Message::DismissDialog,
_ => Message::ConfirmRenameProject,
});
}
KeyCode::Char(ch) => {
if state.focused_field == RenameProjectField::Name {
state.name_input.push(ch);
}
KeyCode::Char(ch) if state.focused_field == RenameProjectField::Name => {
state.name_input.push(ch);
}
_ => {}
}
Expand Down Expand Up @@ -1187,21 +1167,17 @@ fn handle_rename_repo_dialog_key(
KeyCode::Right if state.focused_field == RenameRepoField::Cancel => {
state.focused_field = RenameRepoField::Confirm;
}
KeyCode::Backspace => {
if state.focused_field == RenameRepoField::Name {
state.name_input.pop();
}
KeyCode::Backspace if state.focused_field == RenameRepoField::Name => {
state.name_input.pop();
}
KeyCode::Enter => {
*follow_up = Some(match state.focused_field {
RenameRepoField::Cancel => Message::DismissDialog,
_ => Message::ConfirmRenameRepo,
});
}
KeyCode::Char(ch) => {
if state.focused_field == RenameRepoField::Name {
state.name_input.push(ch);
}
KeyCode::Char(ch) if state.focused_field == RenameRepoField::Name => {
state.name_input.push(ch);
}
_ => {}
}
Expand Down
26 changes: 9 additions & 17 deletions src/app/input/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,11 @@ impl App {
KeyAction::OpenArchiveView => {
self.update(Message::OpenArchiveView)?;
}
KeyAction::ProjectNext => {
if self.current_view == View::Board {
self.update(Message::SwitchToNextProject)?;
}
KeyAction::ProjectNext if self.current_view == View::Board => {
self.update(Message::SwitchToNextProject)?;
}
KeyAction::ProjectPrev => {
if self.current_view == View::Board {
self.update(Message::SwitchToPrevProject)?;
}
KeyAction::ProjectPrev if self.current_view == View::Board => {
self.update(Message::SwitchToPrevProject)?;
}
_ => {}
}
Expand All @@ -116,11 +112,9 @@ impl App {
self.cycle_detail_focus();
return Ok(());
}
KeyCode::Enter | KeyCode::Char('e') => {
if self.detail_focus == DetailFocus::Log {
self.toggle_selected_log_entry(false);
return Ok(());
}
KeyCode::Enter | KeyCode::Char('e') if self.detail_focus == DetailFocus::Log => {
self.toggle_selected_log_entry(false);
return Ok(());
}
KeyCode::Char('f') => {
if self.detail_focus == DetailFocus::Log {
Expand Down Expand Up @@ -351,10 +345,8 @@ impl App {
self.update(Message::DismissDialog)?;
}
}
KeyAction::ToggleCategoryEditMode => {
if self.active_dialog == ActiveDialog::None {
self.category_edit_mode = !self.category_edit_mode;
}
KeyAction::ToggleCategoryEditMode if self.active_dialog == ActiveDialog::None => {
self.category_edit_mode = !self.category_edit_mode;
}
_ => {}
}
Expand Down
7 changes: 4 additions & 3 deletions src/app/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::git::{
git_check_branch_up_to_date, git_create_worktree, git_detect_default_branch, git_fetch,
git_is_valid_repo, git_remove_worktree,
};
use crate::process::command;
use crate::tmux::{
PopupThemeStyle, sanitize_session_name_for_project, tmux_create_session, tmux_kill_session,
tmux_open_session_in_new_terminal, tmux_session_exists, tmux_show_popup, tmux_switch_client,
Expand Down Expand Up @@ -120,7 +121,7 @@ impl CreateTaskRuntime for RealCreateTaskRuntime {
}

fn git_resolve_repo_root(&self, path: &Path) -> Result<PathBuf> {
let output = std::process::Command::new("git")
let output = command("git")
.args(["rev-parse", "--show-toplevel"])
.current_dir(path)
.output()
Expand All @@ -144,7 +145,7 @@ impl CreateTaskRuntime for RealCreateTaskRuntime {
}

fn git_current_branch(&self, path: &Path) -> Result<String> {
let output = std::process::Command::new("git")
let output = command("git")
.args(["branch", "--show-current"])
.current_dir(path)
.output()
Expand All @@ -171,7 +172,7 @@ impl CreateTaskRuntime for RealCreateTaskRuntime {
}

fn git_validate_branch(&self, repo_path: &Path, branch_name: &str) -> Result<()> {
let output = std::process::Command::new("git")
let output = command("git")
.args(["check-ref-format", "--branch", branch_name])
.current_dir(repo_path)
.output()
Expand Down
4 changes: 2 additions & 2 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
fs,
future::Future,
path::{Path, PathBuf},
process::Command,
str::FromStr,
sync::OnceLock,
};
Expand All @@ -17,6 +16,7 @@ use sqlx::{Row, SqlitePool};
use tokio::runtime::{Builder as RuntimeBuilder, Handle, RuntimeFlavor};
use uuid::Uuid;

use crate::process::command;
use crate::types::{Category, CommandFrequency, Repo, Task};

const DEFAULT_TMUX_STATUS: &str = "unknown";
Expand Down Expand Up @@ -1238,7 +1238,7 @@ fn detect_remote_url(path: &Path) -> Option<String> {
}

fn run_git<const N: usize>(path: &Path, args: [&str; N]) -> Option<String> {
let output = Command::new("git")
let output = command("git")
.arg("-C")
.arg(path)
.args(args)
Expand Down
9 changes: 6 additions & 3 deletions src/git/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use std::process::Output;

use anyhow::{Context, Result, bail};

use crate::process::command;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Branch {
pub name: String,
Expand Down Expand Up @@ -198,7 +200,7 @@ pub fn git_delete_branch(repo_path: &Path, branch_name: &str) -> Result<()> {
}

pub fn git_is_valid_repo(path: &Path) -> bool {
Command::new("git")
command("git")
.args(["rev-parse", "--git-dir"])
.current_dir(path)
.output()
Expand Down Expand Up @@ -420,7 +422,7 @@ where
.into_iter()
.map(|arg| arg.as_ref().to_string())
.collect();
let output = Command::new("git")
let output = command("git")
.args(args_vec.iter().map(String::as_str))
.current_dir(repo_path)
.output()
Expand Down Expand Up @@ -451,6 +453,7 @@ where
mod tests {
use super::*;
use std::fs;
use std::process::Command;

use tempfile::TempDir;

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod logging;
pub mod matching;
pub mod notification;
pub mod opencode;
pub mod process;
pub mod projects;
pub mod realm;
pub mod settings;
Expand Down
26 changes: 14 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
io::{self, Write},
panic,
process::Command,
str::FromStr,
sync::{
Arc, Mutex,
Expand All @@ -27,6 +26,7 @@ use opencode_kanban::{
app::App,
cli::{self, RootCommand},
logging::{init_logging, print_log_location},
process::{command, launch_env, tmux_env_args},
realm::{RootId, apply_message, init_application, should_quit},
theme::ThemePreset,
tmux::{ensure_tmux_installed, tmux_session_exists},
Expand Down Expand Up @@ -100,6 +100,7 @@ async fn main() -> Result<()> {
}

fn run_app() -> Result<RunOutcome> {
let _ = launch_env();
let cli = Cli::parse();

if let Some(command) = cli.command {
Expand Down Expand Up @@ -177,24 +178,25 @@ fn validate_runtime_environment() -> Result<()> {
let exe_path = current_exe.to_string_lossy();

if tmux_session_exists(session_name) {
let status = Command::new("tmux")
let status = command("tmux")
.args(["attach-session", "-t", session_name])
.status()
.context("failed to attach to tmux session")?;
ensure_command_succeeded("tmux attach-session", status)?;
std::process::exit(0);
}

let status = Command::new("tmux")
.args([
"new-session",
"-A",
"-s",
session_name,
"-c",
".",
exe_path.as_ref(),
])
let mut args = vec!["new-session".to_string(), "-A".to_string()];
args.extend(tmux_env_args());
args.extend([
"-s".to_string(),
session_name.to_string(),
"-c".to_string(),
".".to_string(),
exe_path.to_string(),
]);
let status = command("tmux")
.args(args)
.status()
.context("failed to create tmux session")?;
ensure_command_succeeded("tmux new-session", status)?;
Expand Down
Loading
Loading