feat: implement fetch pipeline and e2e coverage
This commit is contained in:
+22
-3
@@ -1,3 +1,4 @@
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
|
||||
use clap::Parser;
|
||||
@@ -11,6 +12,8 @@ pub mod output;
|
||||
pub mod render;
|
||||
|
||||
use crate::cli::{Cli, Commands, OutputFormat};
|
||||
use crate::gitea::client::GiteaClient;
|
||||
use crate::normalize::normalize_bundle;
|
||||
use crate::output::write_output;
|
||||
use crate::render::json::{parse_json, render_json};
|
||||
use crate::render::markdown::render_markdown;
|
||||
@@ -25,11 +28,27 @@ pub fn run() -> anyhow::Result<()> {
|
||||
let md = render_markdown(&doc);
|
||||
write_output(args.out.as_deref().map(Path::new), &md)?;
|
||||
}
|
||||
Commands::Fetch(_args) => {
|
||||
let _ = OutputFormat::Markdown;
|
||||
let _ = render_json;
|
||||
Commands::Fetch(args) => {
|
||||
let token = required_env("GITEA_PR_CLI_API_TOKEN")?;
|
||||
let base_url = required_env("GITEA_PR_CLI_URL")?;
|
||||
let repo = required_env("GITEA_PR_CLI_REPO")?;
|
||||
|
||||
let client = GiteaClient::new(base_url, token);
|
||||
let bundle = client.fetch_pr_bundle(&repo, args.pr_index)?;
|
||||
let doc = normalize_bundle(&repo, bundle);
|
||||
|
||||
let rendered = match args.format {
|
||||
OutputFormat::Markdown => render_markdown(&doc),
|
||||
OutputFormat::Json => render_json(&doc)?,
|
||||
};
|
||||
|
||||
write_output(args.out.as_deref().map(Path::new), &rendered)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn required_env(name: &'static str) -> anyhow::Result<String> {
|
||||
env::var(name).map_err(|_| anyhow::anyhow!("missing required environment variable: {name}"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user