Skip to content

Commit

Permalink
Fix API base URL (#1340)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal authored Dec 19, 2024
1 parent 4638c24 commit f505da6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion qlty-check/src/llm/fixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl Fixer {
}

if let Some(path) = issue.path() {
let client = Client::new(None);
let client = Client::default();
let content = self.staging_area.read(issue.path().unwrap().into())?;
let response = client.post("/fixes").send_json(ureq::json!(&FixRequest {
issue: issue.clone(),
Expand Down
20 changes: 15 additions & 5 deletions qlty-cloud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,28 @@ use ureq::Request;
const QLTY_API_URL: &str = "https://api.qlty.sh";
const USER_AGENT_PREFIX: &str = "qlty";

#[derive(Default, Debug, Clone)]
#[derive(Debug, Clone)]
pub struct Client {
pub base_url: String,
pub token: Option<String>,
}

impl Default for Client {
fn default() -> Self {
Self::new(None, None)
}
}

impl Client {
pub fn new(token: Option<String>) -> Self {
pub fn new(base_url: Option<&str>, token: Option<String>) -> Self {
Self {
base_url: match std::env::var("QLTY_API_URL") {
Ok(url) => url,
Err(_) => QLTY_API_URL.to_string(),
base_url: if let Some(url) = base_url {
url.to_string()
} else {
match std::env::var("QLTY_API_URL") {
Ok(url) => url,
Err(_) => QLTY_API_URL.to_string(),
}
},
token,
}
Expand Down
4 changes: 3 additions & 1 deletion qlty-coverage/src/publish/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use anyhow::{Context, Result};
use qlty_cloud::{export::CoverageExport, Client as QltyClient};
use std::path::PathBuf;

const LEGACY_API_URL: &str = "https://qlty.sh/api";

#[derive(Default, Clone, Debug)]
pub struct Upload {
pub id: String,
Expand All @@ -14,7 +16,7 @@ pub struct Upload {

impl Upload {
pub fn prepare(token: &str, report: &mut Report) -> Result<Self> {
let client = QltyClient::new(Some(token.into()));
let client = QltyClient::new(Some(LEGACY_API_URL), Some(token.into()));

let response = client
.post("/coverage")
Expand Down

0 comments on commit f505da6

Please sign in to comment.