Skip to content
Open
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
2 changes: 1 addition & 1 deletion crates/tokf-cli/filters/gh/issue/list.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
command = "gh issue list"
description = "Structured JSON extraction of issue number, title, state, and labels"
run = "gh issue list --json number,title,state,labels {args}"
passthrough_args = ["--web", "-w"]
passthrough_args = ["--web", "-w", "--json", "-q", "--jq"]

[json]

Expand Down
2 changes: 1 addition & 1 deletion crates/tokf-cli/filters/gh/issue/view.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
command = "gh issue view *"
description = "Structured JSON extraction of issue details with body"
run = "gh issue view {args} --json number,title,state,author,labels,assignees,milestone,body"
passthrough_args = ["--web", "-w"]
passthrough_args = ["--web", "-w", "--json", "-q", "--jq"]

[json]

Expand Down
2 changes: 1 addition & 1 deletion crates/tokf-cli/filters/gh/pr/checks.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
command = "gh pr checks *"
description = "Structured JSON extraction of CI check names and status"
run = "gh pr checks {args} --json name,state,workflow"
passthrough_args = ["--watch", "--web", "-w"]
passthrough_args = ["--watch", "--web", "-w", "--json", "-q", "--jq"]

[json]

Expand Down
2 changes: 1 addition & 1 deletion crates/tokf-cli/filters/gh/pr/list.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
command = "gh pr list"
description = "Structured JSON extraction of PR number, title, state, and branch"
run = "gh pr list --json number,title,state,headRefName {args}"
passthrough_args = ["--web", "-w"]
passthrough_args = ["--web", "-w", "--json", "-q", "--jq"]

[json]

Expand Down
2 changes: 1 addition & 1 deletion crates/tokf-cli/filters/gh/pr/view.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
command = "gh pr view *"
description = "Structured JSON extraction of PR details with review status and body"
run = "gh pr view {args} --json number,title,state,author,headRefName,baseRefName,reviewDecision,labels,assignees,milestone,body"
passthrough_args = ["--web", "-w"]
passthrough_args = ["--web", "-w", "--json", "-q", "--jq"]

[json]

Expand Down
70 changes: 70 additions & 0 deletions crates/tokf-cli/tests/cli_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,73 @@ output = "CHILD_FILTERED"
"expected parent filter when no args variant matches, got: {stdout}"
);
}

// Regression test for https://github.com/nicholasgasior/tokf/issues/381:
// gh filters with a `run` override that injects --json must passthrough when
// the user already supplies their own --json / -q / --jq, otherwise the
// template renders an empty stub.
#[test]
fn gh_json_flag_triggers_passthrough() {
let dir = tempfile::TempDir::new().unwrap();
let filters_dir = dir.path().join(".tokf/filters/gh/pr");
std::fs::create_dir_all(&filters_dir).unwrap();
// Mimic the bundled gh/pr/view filter (command + run + json extract + template)
std::fs::write(
filters_dir.join("view.toml"),
r#"command = "gh pr view *"
run = "echo INJECTED_JSON_SCHEMA"
passthrough_args = ["--web", "-w", "--json", "-q", "--jq"]

[on_success]
output = "FILTERED_TEMPLATE"
"#,
)
.unwrap();

// Without --json: filter applies, we get the template
let output = tokf()
.args(["run", "gh", "pr", "view", "1"])
.current_dir(dir.path())
.output()
.unwrap();
assert!(output.status.success());
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
stdout.contains("FILTERED_TEMPLATE"),
"expected filter template without --json, got: {stdout}"
);

// With --json: passthrough — original args forwarded, no template rendered
let output = tokf()
.args([
"run", "gh", "pr", "view", "1", "--json", "isDraft", "-q", ".isDraft",
])
.current_dir(dir.path())
.output()
.unwrap();
assert!(output.status.success());
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
!stdout.contains("FILTERED_TEMPLATE"),
"filter template must not appear when --json is passed, got: {stdout}"
);
assert!(
!stdout.contains("INJECTED_JSON_SCHEMA"),
"run override must not execute when --json is passed, got: {stdout}"
);

// With --jq: same passthrough behaviour
let output = tokf()
.args([
"run", "gh", "pr", "view", "1", "--json", "isDraft", "--jq", ".isDraft",
])
.current_dir(dir.path())
.output()
.unwrap();
assert!(output.status.success());
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
!stdout.contains("FILTERED_TEMPLATE"),
"filter template must not appear when --jq is passed, got: {stdout}"
);
}