mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-10-08 03:10:26 +00:00
parent
b869509f50
commit
d2303d4d1e
4 changed files with 635 additions and 11 deletions
File diff suppressed because one or more lines are too long
182
nodes/simplify_gpt/prompt.md
Normal file
182
nodes/simplify_gpt/prompt.md
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
Goal: # Plan: Merge fabro-linear and GitHub tracker into fabro-tracker
|
||||
|
||||
## Context
|
||||
|
||||
The tracker ecosystem currently has three crates:
|
||||
- **fabro-tracker** — trait-only (57 lines): `Tracker` trait, `Issue`, `BlockerRef`
|
||||
- **fabro-linear** — standalone Linear functions that duplicate the `Issue`/`BlockerRef` types and don't implement the `Tracker` trait. Entirely unused.
|
||||
- **fabro-github** — mixed crate: GitHub App auth/PRs/branches (~70%) + `GitHubTracker` implementing `Tracker` (~30%). The `GitHubTracker` is also unused by consumers.
|
||||
|
||||
Goal: consolidate both tracker implementations into `fabro-tracker`, keeping non-tracker GitHub code in `fabro-github`, and deleting `fabro-linear`.
|
||||
|
||||
## Dependency Direction Change
|
||||
|
||||
**Current:** `fabro-github → fabro-tracker` (for trait re-export)
|
||||
**After:** `fabro-tracker → fabro-github` (for auth primitives: `GitHubAppCredentials`, `sign_app_jwt`, `create_installation_access_token_for_projects`)
|
||||
|
||||
`fabro-github` no longer depends on `fabro-tracker`. No circular dependency.
|
||||
|
||||
## Steps
|
||||
|
||||
### 1. Update `lib/crates/fabro-tracker/Cargo.toml`
|
||||
|
||||
Add dependencies needed by both implementations:
|
||||
```toml
|
||||
[dependencies]
|
||||
fabro-github = { path = "../fabro-github" }
|
||||
async-trait.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
reqwest.workspace = true
|
||||
tracing.workspace = true
|
||||
tokio = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
mockito = "1"
|
||||
tokio = { workspace = true, features = ["test-util", "macros"] }
|
||||
```
|
||||
|
||||
### 2. Update `lib/crates/fabro-github/Cargo.toml`
|
||||
|
||||
Remove:
|
||||
- `fabro-tracker = { path = "../fabro-tracker" }`
|
||||
- `async-trait.workspace = true`
|
||||
|
||||
### 3. Remove tracker code from `lib/crates/fabro-github/src/lib.rs`
|
||||
|
||||
Remove these items (keep everything else):
|
||||
- `use async_trait::async_trait;` (line 1)
|
||||
- `use tokio::sync::OnceCell;` (line 3)
|
||||
- `pub use fabro_tracker::{BlockerRef, Issue, Tracker};` (line 5)
|
||||
- `execute_github_graphql()` fn (~line 796)
|
||||
- `GitHubTracker` struct, `impl GitHubTracker`, `impl Tracker for GitHubTracker` (~line 866-1315)
|
||||
- `normalize_github_item()` fn (~line 981)
|
||||
- `fetch_project_items_page()` fn (~line 1035)
|
||||
- All tracker-related tests (~line 2172-2841): `execute_github_graphql` tests, tracker helpers (`mock_github_tracker`, `make_test_issue`, etc.), and all `GitHubTracker` method tests
|
||||
|
||||
**Keep** `create_installation_access_token_for_projects()` — it stays in fabro-github as a public function alongside the other `create_installation_access_token_*` variants.
|
||||
|
||||
### 4. Create `lib/crates/fabro-tracker/src/linear.rs`
|
||||
|
||||
Adapt `fabro-linear/src/lib.rs` code:
|
||||
- **Remove** the duplicate `Issue` and `BlockerRef` struct definitions — use `crate::Issue` and `crate::BlockerRef`
|
||||
- **Adapt** `normalize_issue()` to return `crate::Issue` with `project_item_id: None`
|
||||
- **Create** `LinearTracker` struct wrapping `LinearConfig`, `reqwest::Client`, and `project_slug: String`
|
||||
- **Implement** `Tracker for LinearTracker` by delegating to the existing functions
|
||||
- **Keep** private: `execute_graphql`, `normalize_issue`, `extract_issues`, `ISSUE_FIELDS`, `BLOCKS_RELATION_TYPE`
|
||||
- **Keep** public: `LinearConfig`, `LinearTracker`, `LINEAR_API_ENDPOINT`
|
||||
- **Move** all tests, updating assertions for the added `project_item_id` field
|
||||
|
||||
### 5. Create `lib/crates/fabro-tracker/src/github.rs`
|
||||
|
||||
Move tracker code from fabro-github:
|
||||
- Import from fabro-github: `GitHubAppCredentials`, `sign_app_jwt`, `create_installation_access_token_for_projects`
|
||||
- Contains: `GitHubTracker` struct + impls, `execute_github_graphql`, `normalize_github_item`, `fetch_project_items_page`
|
||||
- Uses `crate::Issue` and `crate::BlockerRef` (same types, just different import path)
|
||||
- Move all GitHubTracker tests (duplicate `test_rsa_key()` helper since test code isn't importable across crates)
|
||||
|
||||
### 6. Update `lib/crates/fabro-tracker/src/lib.rs`
|
||||
|
||||
Add module declarations and re-exports:
|
||||
```rust
|
||||
pub mod github;
|
||||
pub mod linear;
|
||||
|
||||
pub use github::GitHubTracker;
|
||||
pub use linear::{LinearConfig, LinearTracker, LINEAR_API_ENDPOINT};
|
||||
```
|
||||
|
||||
### 7. Delete `lib/crates/fabro-linear/`
|
||||
|
||||
Remove entire directory. Workspace glob `members = ["lib/crates/*"]` handles the rest.
|
||||
|
||||
## Verification
|
||||
|
||||
```bash
|
||||
cargo build --workspace
|
||||
cargo test --workspace
|
||||
cargo clippy --workspace -- -D warnings
|
||||
cargo fmt --check --all
|
||||
```
|
||||
|
||||
Key things to verify:
|
||||
- No circular dependency (fabro-tracker → fabro-github, fabro-github has no fabro-tracker dep)
|
||||
- Linear `normalize_issue` sets `project_item_id: None`
|
||||
- All moved tests pass in their new home
|
||||
- `test_rsa_key()` helper is duplicated in fabro-tracker's github test module
|
||||
|
||||
|
||||
## Completed stages
|
||||
- **toolchain**: success
|
||||
- Script: `command -v cargo >/dev/null || { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && sudo ln -sf $HOME/.cargo/bin/* /usr/local/bin/; }; cargo --version 2>&1`
|
||||
- Stdout:
|
||||
```
|
||||
cargo 1.94.0 (85eff7c80 2026-01-15)
|
||||
```
|
||||
- Stderr: (empty)
|
||||
- **preflight_compile**: success
|
||||
- Script: `cargo check -q --workspace 2>&1`
|
||||
- Stdout: (empty)
|
||||
- Stderr: (empty)
|
||||
- **preflight_lint**: success
|
||||
- Script: `cargo clippy -q --workspace -- -D warnings 2>&1`
|
||||
- Stdout: (empty)
|
||||
- Stderr: (empty)
|
||||
- **implement**: success
|
||||
- Model: claude-opus-4-6, 113.7k tokens in / 38.3k out
|
||||
- Files: /home/daytona/workspace/lib/crates/fabro-github/Cargo.toml, /home/daytona/workspace/lib/crates/fabro-github/src/lib.rs, /home/daytona/workspace/lib/crates/fabro-tracker/Cargo.toml, /home/daytona/workspace/lib/crates/fabro-tracker/src/github.rs, /home/daytona/workspace/lib/crates/fabro-tracker/src/lib.rs, /home/daytona/workspace/lib/crates/fabro-tracker/src/linear.rs
|
||||
- **simplify_opus**: success
|
||||
- Model: claude-opus-4-6, 96.2k tokens in / 12.1k out
|
||||
- Files: /home/daytona/workspace/lib/crates/fabro-tracker/Cargo.toml, /home/daytona/workspace/lib/crates/fabro-tracker/src/github.rs, /home/daytona/workspace/lib/crates/fabro-tracker/src/lib.rs, /home/daytona/workspace/lib/crates/fabro-tracker/src/linear.rs
|
||||
|
||||
|
||||
# Simplify: Code Review and Cleanup
|
||||
|
||||
Review all changed files for reuse, quality, and efficiency. Fix any issues found.
|
||||
|
||||
## Phase 1: Identify Changes
|
||||
|
||||
Run git diff (or git diff HEAD if there are staged changes) to see what changed. If there are no git changes, review the most recently modified files that the user mentioned or that you edited earlier in this conversation.
|
||||
|
||||
## Phase 2: Launch Three Review Agents in Parallel
|
||||
|
||||
Use the Agent tool to launch all three agents concurrently in a single message. Pass each agent the full diff so it has the complete context.
|
||||
|
||||
### Agent 1: Code Reuse Review
|
||||
|
||||
For each change:
|
||||
|
||||
1. Search for existing utilities and helpers that could replace newly written code. Use Grep to find similar patterns elsewhere in the codebase — common locations are utility directories, shared modules, and files adjacent to the changed ones.
|
||||
2. Flag any new function that duplicates existing functionality. Suggest the existing function to use instead.
|
||||
3. Flag any inline logic that could use an existing utility — hand-rolled string manipulation, manual path handling, custom environment checks, ad-hoc type guards, and similar patterns are common candidates.
|
||||
|
||||
Note: This is a greenfield app, so focus on maximizing simplicity and don't worry about changing things to achieve it.
|
||||
|
||||
### Agent 2: Code Quality Review
|
||||
|
||||
Review the same changes for hacky patterns:
|
||||
|
||||
1. Redundant state: state that duplicates existing state, cached values that could be derived, observers/effects that could be direct calls
|
||||
2. Parameter sprawl: adding new parameters to a function instead of generalizing or restructuring existing ones
|
||||
3. Copy-paste with slight variation: near-duplicate code blocks that should be unified with a shared abstraction
|
||||
4. Leaky abstractions: exposing internal details that should be encapsulated, or breaking existing abstraction boundaries
|
||||
5. Stringly-typed code: using raw strings where constants, enums (string unions), or branded types already exist in the codebase
|
||||
|
||||
Note: This is a greenfield app, so be aggressive in optimizing quality.
|
||||
|
||||
### Agent 3: Efficiency Review
|
||||
|
||||
Review the same changes for efficiency:
|
||||
|
||||
1. Unnecessary work: redundant computations, repeated file reads, duplicate network/API calls, N+1 patterns
|
||||
2. Missed concurrency: independent operations run sequentially when they could run in parallel
|
||||
3. Hot-path bloat: new blocking work added to startup or per-request/per-render hot paths
|
||||
4. Unnecessary existence checks: pre-checking file/resource existence before operating (TOCTOU anti-pattern) — operate directly and handle the error
|
||||
5. Memory: unbounded data structures, missing cleanup, event listener leaks
|
||||
6. Overly broad operations: reading entire files when only a portion is needed, loading all items when filtering for one
|
||||
|
||||
## Phase 3: Fix Issues
|
||||
|
||||
Wait for all three agents to complete. Aggregate their findings and fix each issue directly. If a finding is a false positive or not worth addressing, note it and move on — do not argue with the finding, just skip it.
|
||||
|
||||
When done, briefly summarize what was fixed (or confirm the code was already clean).
|
||||
6
nodes/simplify_gpt/status.json
Normal file
6
nodes/simplify_gpt/status.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"status": "fail",
|
||||
"notes": null,
|
||||
"failure_reason": "LLM error: Not found on anthropic: model: gpt-54",
|
||||
"timestamp": "2026-03-20T00:27:05.046671+00:00"
|
||||
}
|
||||
419
nodes/simplify_opus/diff.patch
Normal file
419
nodes/simplify_opus/diff.patch
Normal file
|
|
@ -0,0 +1,419 @@
|
|||
diff --git a/Cargo.lock b/Cargo.lock
|
||||
index 5a17acb2..ecba92ce 100644
|
||||
--- a/Cargo.lock
|
||||
+++ b/Cargo.lock
|
||||
@@ -1723,7 +1723,6 @@ dependencies = [
|
||||
"fabro-github",
|
||||
"mockito",
|
||||
"reqwest 0.12.28",
|
||||
- "serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tracing",
|
||||
diff --git a/lib/crates/fabro-github/Cargo.toml b/lib/crates/fabro-github/Cargo.toml
|
||||
index 6bfbe579..25a67241 100644
|
||||
--- a/lib/crates/fabro-github/Cargo.toml
|
||||
+++ b/lib/crates/fabro-github/Cargo.toml
|
||||
@@ -20,4 +20,4 @@ tokio = { workspace = true }
|
||||
[dev-dependencies]
|
||||
mockito = "1"
|
||||
tokio = { workspace = true, features = ["test-util", "macros"] }
|
||||
-base64.workspace = true
|
||||
\ No newline at end of file
|
||||
+base64.workspace = true
|
||||
diff --git a/lib/crates/fabro-tracker/Cargo.toml b/lib/crates/fabro-tracker/Cargo.toml
|
||||
index f3861748..459189ba 100644
|
||||
--- a/lib/crates/fabro-tracker/Cargo.toml
|
||||
+++ b/lib/crates/fabro-tracker/Cargo.toml
|
||||
@@ -11,7 +11,6 @@ doctest = false
|
||||
[dependencies]
|
||||
fabro-github = { path = "../fabro-github" }
|
||||
async-trait.workspace = true
|
||||
-serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
reqwest.workspace = true
|
||||
tracing.workspace = true
|
||||
@@ -19,4 +18,4 @@ tokio = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
mockito = "1"
|
||||
-tokio = { workspace = true, features = ["test-util", "macros"] }
|
||||
+tokio = { workspace = true, features = ["test-util", "macros"] }
|
||||
\ No newline at end of file
|
||||
diff --git a/lib/crates/fabro-tracker/src/github.rs b/lib/crates/fabro-tracker/src/github.rs
|
||||
index 0a9c437d..5e0e15f8 100644
|
||||
--- a/lib/crates/fabro-tracker/src/github.rs
|
||||
+++ b/lib/crates/fabro-tracker/src/github.rs
|
||||
@@ -5,7 +5,7 @@ use fabro_github::{
|
||||
create_installation_access_token_for_projects, sign_app_jwt, GitHubAppCredentials,
|
||||
};
|
||||
|
||||
-use crate::{Issue, Tracker};
|
||||
+use crate::{execute_graphql_request, Issue, Tracker};
|
||||
|
||||
/// Execute a GitHub GraphQL request and return the response JSON.
|
||||
async fn execute_github_graphql(
|
||||
@@ -15,47 +15,15 @@ async fn execute_github_graphql(
|
||||
query: &str,
|
||||
variables: serde_json::Value,
|
||||
) -> Result<serde_json::Value, String> {
|
||||
- let body = serde_json::json!({
|
||||
- "query": query,
|
||||
- "variables": variables,
|
||||
- });
|
||||
-
|
||||
- let resp = client
|
||||
- .post(endpoint)
|
||||
- .header("Authorization", format!("Bearer {token}"))
|
||||
- .header("Content-Type", "application/json")
|
||||
- .header("User-Agent", "fabro")
|
||||
- .timeout(std::time::Duration::from_secs(30))
|
||||
- .json(&body)
|
||||
- .send()
|
||||
- .await
|
||||
- .map_err(|e| format!("GitHub GraphQL request failed: {e}"))?;
|
||||
-
|
||||
- let status = resp.status();
|
||||
- if !status.is_success() {
|
||||
- let body_text = resp.text().await.unwrap_or_default();
|
||||
- tracing::warn!(status = %status, "GitHub GraphQL API error");
|
||||
- return Err(format!(
|
||||
- "GitHub GraphQL API returned HTTP {status}: {body_text}"
|
||||
- ));
|
||||
- }
|
||||
-
|
||||
- let response: serde_json::Value = resp
|
||||
- .json()
|
||||
- .await
|
||||
- .map_err(|e| format!("Failed to parse GitHub GraphQL response: {e}"))?;
|
||||
-
|
||||
- if let Some(errors) = response["errors"].as_array() {
|
||||
- if !errors.is_empty() {
|
||||
- let messages: Vec<&str> = errors
|
||||
- .iter()
|
||||
- .filter_map(|e| e["message"].as_str())
|
||||
- .collect();
|
||||
- return Err(format!("GitHub GraphQL errors: {}", messages.join("; ")));
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- Ok(response)
|
||||
+ execute_graphql_request(
|
||||
+ client,
|
||||
+ endpoint,
|
||||
+ &format!("Bearer {token}"),
|
||||
+ "GitHub",
|
||||
+ query,
|
||||
+ variables,
|
||||
+ )
|
||||
+ .await
|
||||
}
|
||||
|
||||
/// A `Tracker` implementation backed by GitHub Projects V2.
|
||||
@@ -272,17 +240,22 @@ async fn fetch_project_items_page(
|
||||
"cursor": cursor,
|
||||
});
|
||||
|
||||
- let resp = execute_github_graphql(client, token, graphql_url, query, variables).await?;
|
||||
+ let mut resp = execute_github_graphql(client, token, graphql_url, query, variables).await?;
|
||||
|
||||
- let items_node = &resp["data"]["node"]["items"];
|
||||
- let nodes = items_node["nodes"].as_array().cloned().unwrap_or_default();
|
||||
- let has_next = items_node["pageInfo"]["hasNextPage"]
|
||||
+ let has_next = resp["data"]["node"]["items"]["pageInfo"]["hasNextPage"]
|
||||
.as_bool()
|
||||
.unwrap_or(false);
|
||||
- let end_cursor = items_node["pageInfo"]["endCursor"]
|
||||
+ let end_cursor = resp["data"]["node"]["items"]["pageInfo"]["endCursor"]
|
||||
.as_str()
|
||||
.map(|s| s.to_string());
|
||||
|
||||
+ // Take ownership of the nodes array in-place instead of deep-cloning it.
|
||||
+ let nodes = resp
|
||||
+ .pointer_mut("/data/node/items/nodes")
|
||||
+ .and_then(|v| v.as_array_mut())
|
||||
+ .map(std::mem::take)
|
||||
+ .unwrap_or_default();
|
||||
+
|
||||
Ok((nodes, has_next, end_cursor))
|
||||
}
|
||||
|
||||
@@ -476,7 +449,7 @@ impl Tracker for GitHubTracker {
|
||||
|
||||
let id_set: std::collections::HashSet<&str> = ids.iter().copied().collect();
|
||||
let mut issue_map: std::collections::HashMap<String, Issue> =
|
||||
- std::collections::HashMap::new();
|
||||
+ std::collections::HashMap::with_capacity(ids.len());
|
||||
let mut cursor: Option<String> = None;
|
||||
|
||||
loop {
|
||||
@@ -497,6 +470,10 @@ impl Tracker for GitHubTracker {
|
||||
}
|
||||
}
|
||||
|
||||
+ if issue_map.len() == id_set.len() {
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
if has_next {
|
||||
cursor = end_cursor;
|
||||
} else {
|
||||
diff --git a/lib/crates/fabro-tracker/src/lib.rs b/lib/crates/fabro-tracker/src/lib.rs
|
||||
index d2bc5677..fa7df360 100644
|
||||
--- a/lib/crates/fabro-tracker/src/lib.rs
|
||||
+++ b/lib/crates/fabro-tracker/src/lib.rs
|
||||
@@ -6,6 +6,65 @@ pub mod linear;
|
||||
pub use github::GitHubTracker;
|
||||
pub use linear::{LinearConfig, LinearTracker, LINEAR_API_ENDPOINT};
|
||||
|
||||
+/// Shared GraphQL execution used by both provider modules.
|
||||
+///
|
||||
+/// Posts a query + variables to `endpoint`, attaches the given `auth_header`
|
||||
+/// as the `Authorization` value, and returns the parsed JSON response.
|
||||
+/// Provider-specific error messages use `provider` as a label.
|
||||
+pub(crate) async fn execute_graphql_request(
|
||||
+ client: &reqwest::Client,
|
||||
+ endpoint: &str,
|
||||
+ auth_header: &str,
|
||||
+ provider: &str,
|
||||
+ query: &str,
|
||||
+ variables: serde_json::Value,
|
||||
+) -> Result<serde_json::Value, String> {
|
||||
+ let body = serde_json::json!({
|
||||
+ "query": query,
|
||||
+ "variables": variables,
|
||||
+ });
|
||||
+
|
||||
+ let resp = client
|
||||
+ .post(endpoint)
|
||||
+ .header("Authorization", auth_header)
|
||||
+ .header("Content-Type", "application/json")
|
||||
+ .header("User-Agent", "fabro")
|
||||
+ .timeout(std::time::Duration::from_secs(30))
|
||||
+ .json(&body)
|
||||
+ .send()
|
||||
+ .await
|
||||
+ .map_err(|e| format!("{provider} GraphQL request failed: {e}"))?;
|
||||
+
|
||||
+ let status = resp.status();
|
||||
+ if !status.is_success() {
|
||||
+ let body_text = resp.text().await.unwrap_or_default();
|
||||
+ tracing::warn!(status = %status, provider, "GraphQL API error");
|
||||
+ return Err(format!(
|
||||
+ "{provider} GraphQL API returned HTTP {status}: {body_text}"
|
||||
+ ));
|
||||
+ }
|
||||
+
|
||||
+ let response: serde_json::Value = resp
|
||||
+ .json()
|
||||
+ .await
|
||||
+ .map_err(|e| format!("Failed to parse {provider} GraphQL response: {e}"))?;
|
||||
+
|
||||
+ if let Some(errors) = response["errors"].as_array() {
|
||||
+ if !errors.is_empty() {
|
||||
+ let messages: Vec<&str> = errors
|
||||
+ .iter()
|
||||
+ .filter_map(|e| e["message"].as_str())
|
||||
+ .collect();
|
||||
+ return Err(format!(
|
||||
+ "{provider} GraphQL errors: {}",
|
||||
+ messages.join("; ")
|
||||
+ ));
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ Ok(response)
|
||||
+}
|
||||
+
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BlockerRef {
|
||||
pub id: String,
|
||||
diff --git a/lib/crates/fabro-tracker/src/linear.rs b/lib/crates/fabro-tracker/src/linear.rs
|
||||
index 2dc211b8..1238af46 100644
|
||||
--- a/lib/crates/fabro-tracker/src/linear.rs
|
||||
+++ b/lib/crates/fabro-tracker/src/linear.rs
|
||||
@@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||
use async_trait::async_trait;
|
||||
use serde_json::Value;
|
||||
|
||||
-use crate::{BlockerRef, Issue, Tracker};
|
||||
+use crate::{execute_graphql_request, BlockerRef, Issue, Tracker};
|
||||
|
||||
pub const LINEAR_API_ENDPOINT: &str = "https://api.linear.app/graphql";
|
||||
|
||||
@@ -123,44 +123,15 @@ async fn execute_graphql(
|
||||
query: &str,
|
||||
variables: Value,
|
||||
) -> Result<Value, String> {
|
||||
- let body = serde_json::json!({
|
||||
- "query": query,
|
||||
- "variables": variables,
|
||||
- });
|
||||
-
|
||||
- let resp = client
|
||||
- .post(&config.endpoint)
|
||||
- .header("Authorization", &config.api_key)
|
||||
- .header("Content-Type", "application/json")
|
||||
- .timeout(std::time::Duration::from_secs(30))
|
||||
- .json(&body)
|
||||
- .send()
|
||||
- .await
|
||||
- .map_err(|e| format!("Linear API request failed: {e}"))?;
|
||||
-
|
||||
- let status = resp.status();
|
||||
- if !status.is_success() {
|
||||
- let body_text = resp.text().await.unwrap_or_default();
|
||||
- tracing::warn!(status = %status, "Linear API error");
|
||||
- return Err(format!("Linear API returned HTTP {status}: {body_text}"));
|
||||
- }
|
||||
-
|
||||
- let response: Value = resp
|
||||
- .json()
|
||||
- .await
|
||||
- .map_err(|e| format!("Failed to parse Linear API response: {e}"))?;
|
||||
-
|
||||
- if let Some(errors) = response["errors"].as_array() {
|
||||
- if !errors.is_empty() {
|
||||
- let messages: Vec<&str> = errors
|
||||
- .iter()
|
||||
- .filter_map(|e| e["message"].as_str())
|
||||
- .collect();
|
||||
- return Err(format!("Linear GraphQL errors: {}", messages.join("; ")));
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- Ok(response)
|
||||
+ execute_graphql_request(
|
||||
+ client,
|
||||
+ &config.endpoint,
|
||||
+ &config.api_key,
|
||||
+ "Linear",
|
||||
+ query,
|
||||
+ variables,
|
||||
+ )
|
||||
+ .await
|
||||
}
|
||||
|
||||
fn extract_issues(response: &Value) -> Result<Vec<Issue>, String> {
|
||||
@@ -380,6 +351,25 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
+ fn make_test_issue() -> Issue {
|
||||
+ Issue {
|
||||
+ id: "issue-1".to_string(),
|
||||
+ project_item_id: None,
|
||||
+ identifier: "T-1".to_string(),
|
||||
+ title: "Test".to_string(),
|
||||
+ description: None,
|
||||
+ priority: None,
|
||||
+ state: "Todo".to_string(),
|
||||
+ branch_name: None,
|
||||
+ url: "https://linear.app/t".to_string(),
|
||||
+ assignee_id: None,
|
||||
+ labels: vec![],
|
||||
+ blocked_by: vec![],
|
||||
+ created_at: None,
|
||||
+ updated_at: None,
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
fn complete_issue_json() -> Value {
|
||||
serde_json::json!({
|
||||
"id": "issue-1",
|
||||
@@ -753,22 +743,7 @@ mod tests {
|
||||
.await;
|
||||
|
||||
let tracker = LinearTracker::new(config, reqwest::Client::new(), "proj".to_string());
|
||||
- let issue = Issue {
|
||||
- id: "issue-1".to_string(),
|
||||
- project_item_id: None,
|
||||
- identifier: "T-1".to_string(),
|
||||
- title: "Test".to_string(),
|
||||
- description: None,
|
||||
- priority: None,
|
||||
- state: "Todo".to_string(),
|
||||
- branch_name: None,
|
||||
- url: "https://linear.app/t".to_string(),
|
||||
- assignee_id: None,
|
||||
- labels: vec![],
|
||||
- blocked_by: vec![],
|
||||
- created_at: None,
|
||||
- updated_at: None,
|
||||
- };
|
||||
+ let issue = make_test_issue();
|
||||
tracker.create_comment(&issue, "Hello world").await.unwrap();
|
||||
}
|
||||
|
||||
@@ -785,22 +760,7 @@ mod tests {
|
||||
.await;
|
||||
|
||||
let tracker = LinearTracker::new(config, reqwest::Client::new(), "proj".to_string());
|
||||
- let issue = Issue {
|
||||
- id: "issue-1".to_string(),
|
||||
- project_item_id: None,
|
||||
- identifier: "T-1".to_string(),
|
||||
- title: "Test".to_string(),
|
||||
- description: None,
|
||||
- priority: None,
|
||||
- state: "Todo".to_string(),
|
||||
- branch_name: None,
|
||||
- url: "https://linear.app/t".to_string(),
|
||||
- assignee_id: None,
|
||||
- labels: vec![],
|
||||
- blocked_by: vec![],
|
||||
- created_at: None,
|
||||
- updated_at: None,
|
||||
- };
|
||||
+ let issue = make_test_issue();
|
||||
let err = tracker.create_comment(&issue, "Hello").await.unwrap_err();
|
||||
assert!(err.contains("success: false"), "got: {err}");
|
||||
}
|
||||
@@ -833,22 +793,7 @@ mod tests {
|
||||
.await;
|
||||
|
||||
let tracker = LinearTracker::new(config, reqwest::Client::new(), "proj".to_string());
|
||||
- let issue = Issue {
|
||||
- id: "issue-1".to_string(),
|
||||
- project_item_id: None,
|
||||
- identifier: "T-1".to_string(),
|
||||
- title: "Test".to_string(),
|
||||
- description: None,
|
||||
- priority: None,
|
||||
- state: "Todo".to_string(),
|
||||
- branch_name: None,
|
||||
- url: "https://linear.app/t".to_string(),
|
||||
- assignee_id: None,
|
||||
- labels: vec![],
|
||||
- blocked_by: vec![],
|
||||
- created_at: None,
|
||||
- updated_at: None,
|
||||
- };
|
||||
+ let issue = make_test_issue();
|
||||
tracker.update_issue_state(&issue, "Done").await.unwrap();
|
||||
|
||||
resolve_mock.assert_async().await;
|
||||
@@ -868,22 +813,7 @@ mod tests {
|
||||
.await;
|
||||
|
||||
let tracker = LinearTracker::new(config, reqwest::Client::new(), "proj".to_string());
|
||||
- let issue = Issue {
|
||||
- id: "issue-1".to_string(),
|
||||
- project_item_id: None,
|
||||
- identifier: "T-1".to_string(),
|
||||
- title: "Test".to_string(),
|
||||
- description: None,
|
||||
- priority: None,
|
||||
- state: "Todo".to_string(),
|
||||
- branch_name: None,
|
||||
- url: "https://linear.app/t".to_string(),
|
||||
- assignee_id: None,
|
||||
- labels: vec![],
|
||||
- blocked_by: vec![],
|
||||
- created_at: None,
|
||||
- updated_at: None,
|
||||
- };
|
||||
+ let issue = make_test_issue();
|
||||
let err = tracker
|
||||
.update_issue_state(&issue, "Nonexistent")
|
||||
.await
|
||||
Loading…
Add table
Reference in a new issue