Skip to content

feat: remove qa feature #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2024
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
78 changes: 1 addition & 77 deletions src/filters.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::utils::{issue_code, ver_rel};
use itertools::Itertools;
use serde_json::Value;
use crate::utils::ver_rel;
use std::fmt::Display;

macro_rules! bail {
Expand Down Expand Up @@ -58,10 +56,6 @@ pub fn strftime_i32(timestamp: &i32, s: &str) -> ::askama::Result<String> {
}
}

pub fn calc_color_ratio(ratio: &f64, max: &f64) -> ::askama::Result<f64> {
Ok(100.0 - 100.0 / 3.0 * (*ratio) / (*max))
}

pub fn sizeof_fmt(size: &i64) -> ::askama::Result<String> {
let size = size::Size::from_bytes(*size);
Ok(size.to_string())
Expand All @@ -80,10 +74,6 @@ pub fn fmt_pkg_status(status: &i32) -> ::askama::Result<&'static str> {
})
}

pub fn fmt_issue_code(code: &i32) -> ::askama::Result<&'static str> {
Ok(issue_code(*code).unwrap_or("unknown"))
}

pub fn sizeof_fmt_ls(num: &i64) -> ::askama::Result<String> {
if num.abs() < 1024 {
return Ok(num.to_string());
Expand Down Expand Up @@ -123,76 +113,10 @@ pub fn ls_perm(perm: &i32, ftype: &i16) -> ::askama::Result<String> {
Ok(format!("{ftype}{perm}"))
}

pub fn ls_perm_str(perm: &i32, ftype: &str) -> ::askama::Result<String> {
let ftype = match ftype {
"lnk" => 'l',
"sock" => 's',
"chr" => 'c',
"blk" => 'b',
"dir" => 'd',
"fifo" => 'p',
_ => '-',
};

let perm: String = format!("{perm:b}")
.chars()
.zip("rwxrwxrwx".chars())
.map(|(a, b)| if a == '1' { b } else { '-' })
.collect();

Ok(format!("{ftype}{perm}"))
}

pub fn fmt_default<T: Display + Default>(x: &Option<T>) -> ::askama::Result<String> {
if let Some(x) = x {
Ok(format!("{x}"))
} else {
Ok(format!("{}", T::default()))
}
}

/// get json value and convert it to string
pub fn value_string(json: &Value, key: &str) -> ::askama::Result<String> {
Ok(json
.get(key)
.map(|v| v.as_str().map(|s| s.to_string()).unwrap_or_default())
.unwrap_or_default())
}

pub fn value_array_string(json: &Value, key: &str) -> ::askama::Result<Vec<String>> {
Ok(json
.get(key)
.map(|v| {
v.as_array()
.map(|v| {
v.iter()
.map(|v| v.as_str().unwrap_or_default().to_string())
.collect_vec()
})
.unwrap_or_default()
})
.unwrap_or_default())
}

pub fn len<T>(v: &Vec<T>) -> ::askama::Result<usize> {
Ok(v.len())
}
pub fn value_array<'a>(json: &'a Value, key: &'a str) -> ::askama::Result<&'a Vec<serde_json::Value>> {
if let Some(v) = json.get(key) {
if let Some(v) = v.as_array() {
Ok(v)
} else {
bail!("value `{v:?}` is not array type")
}
} else {
bail!("no such key `{key}` in {json:?}")
}
}

pub fn value_i64(json: &Value, key: &str) -> ::askama::Result<i64> {
Ok(json.get(key).map(|v| v.as_i64().unwrap_or(0)).unwrap_or(0))
}

pub fn value_i32(json: &Value, key: &str) -> ::askama::Result<i32> {
Ok(json.get(key).map(|v| v.as_i64().unwrap_or(0) as i32).unwrap_or(0))
}
5 changes: 0 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ async fn main() -> Result<()> {
.typed_get(repo)
.typed_get(packages)
.typed_get(files)
.typed_get(qa)
.typed_get(qa_index)
.typed_get(qa_code)
.typed_get(qa_repo)
.typed_get(qa_package)
.typed_get(cleanmirror)
.typed_get(revdep)
.typed_get(license)
Expand Down
157 changes: 0 additions & 157 deletions src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,163 +595,6 @@ ORDER BY
ver
";

pub const SQL_ISSUES_STATS: &str = "
SELECT
q1.repo,
q1.errno,
q1.cnt,
round(
(q1.cnt :: float8 / coalesce(q2.total, s.cnt)) :: numeric,
5
) :: float8 ratio
FROM
(
SELECT
repo,
errno,
count(DISTINCT package) cnt
FROM
pv_package_issues
GROUP BY
GROUPING SETS ((repo, errno), ())
) q1
LEFT JOIN (
SELECT
repo,
count(package) cnt
FROM
v_packages_new
GROUP BY
repo
) s ON s.repo = q1.repo
LEFT JOIN (
SELECT
b.name repo,
count(DISTINCT p.name) total
FROM
package_versions v
INNER JOIN packages p ON v.package = p.name
INNER JOIN tree_branches b ON b.tree = p.tree
AND b.branch = v.branch
GROUP BY
GROUPING SETS ((b.name), ())
) q2 ON q2.repo IS NOT DISTINCT
FROM
q1.repo
";

pub const SQL_ISSUES_RECENT: &str = "
SELECT
package,
version,
array_agg(
DISTINCT errno
ORDER BY
errno
) errs
FROM
pv_package_issues
WHERE
errno != 311
GROUP BY
package,
version
ORDER BY
max(mtime) DESC
LIMIT
10
";

pub const SQL_ISSUES_CODE: &str = r#"
SELECT
package "name",
array_agg(DISTINCT "version") versions,
array_agg(DISTINCT branch) branches,
(array_agg(filename)) [1] filename,
max(filecount) filecount
FROM
(
SELECT
package,
"version",
substring(
repo
from
position('/' in repo) + 1
) branch,
max("level") "level",
(array_agg(filename)) [1] filename,
count(filename) filecount
FROM
pv_package_issues
WHERE
errno = $1
AND coalesce(repo = $2, TRUE)
GROUP BY
package,
version,
repo
) q1
GROUP BY
package
ORDER BY
package
"#;

pub const SQL_ISSUES_PACKAGE: &str = "
SELECT
errno,
version,
repo,
filecount,
level,
filename,
detail
FROM
(
SELECT
errno,
version,
repo,
level,
filename,
detail,
max(rowid) OVER (PARTITION BY errno, version, repo) filecount,
rowid
FROM
(
SELECT
errno,
version,
repo,
level,
filename,
detail,
count(*) OVER (PARTITION BY errno, version, repo) filecount,
row_number() OVER (
PARTITION BY errno,
version,
repo
ORDER BY
level,
filename
) rowid
FROM
pv_package_issues
WHERE
package = $1
) q1
) q2
WHERE
rowid <= 500
ORDER BY
errno,
version DESC,
repo,
level,
filename
";

pub const SQL_GET_DEB_LIST_HASARCH: &str = "
SELECT
dp.filename,
Expand Down
51 changes: 0 additions & 51 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,44 +142,6 @@ pub async fn fallback(uri: Uri) -> impl IntoResponse {
crate::utils::Error::NotFound(format!("No route for {}", uri))
}

pub fn issue_code(code: i32) -> Option<&'static str> {
match code {
100 => Some("Metadata"),
101 => Some("Syntax error(s) in spec"),
102 => Some("Syntax error(s) in defines"),
103 => Some("Package name is not valid"),
111 => Some("Package may be out-dated"),
112 => Some("SRCTBL uses HTTP"),
121 => Some("The last commit message was badly formatted"),
122 => Some("Multiple packages changed in the last commit"),
123 => Some("Force-pushed recently (last N commit - TBD)"),
200 => Some("Build Process"),
201 => Some("Failed to get source"),
202 => Some("Failed to get dependencies"),
211 => Some("Failed to build from source (FTBFS)"),
221 => Some("Failed to launch packaged executable(s)"),
222 => Some("Feature(s) non-functional, or unit test(s) failed"),
300 => Some("Payload (.deb Package)"),
301 => Some("Bad or corrupted .deb file"),
302 => Some(".deb file too small"),
303 => Some("Bad .deb filename or storage path"),
311 => Some("Bad .deb Maintainer metadata"),
321 => Some("File(s) stored in unexpected path(s) in .deb"),
322 => Some("Zero-byte file(s) found in .deb"),
323 => Some("File(s) with bad owner/group found in .deb"),
324 => Some("File(s) with bad permission found in .deb"),
400 => Some("Dependencies"),
401 => Some("BUILDDEP unmet"),
402 => Some("Duplicate package in tree"),
411 => Some("PKGDEP unmet"),
412 => Some("Duplicate package in repository"),
421 => Some("File collision(s)"),
431 => Some("Library version (sover) dependency unmet"),
432 => Some("Library dependency without PKGDEP"),
_ => None,
}
}

pub type Query = QueryExtractor;

#[derive(Deserialize, Debug, Clone, Default)]
Expand Down Expand Up @@ -448,19 +410,6 @@ impl std::fmt::Display for SrcType {
}
}

macro_rules! skip_none {
($res:expr) => {
match $res {
Some(val) => val,
None => {
tracing::debug!("skip none");
continue;
}
}
};
}
pub(crate) use skip_none;

pub const REPO_CAT: [(&str, &str); 3] = [("base", ""), ("bsp", "BSP"), ("overlay", "Overlay")];
const DEP_REL: [(&str, &str); 8] = [
("PKGDEP", "Depends"),
Expand Down
2 changes: 0 additions & 2 deletions src/views/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
mod index;
mod misc;
mod package;
mod qa;
mod repo;
mod search;

pub use index::{index, license, updates};
pub use misc::{cleanmirror, pkglist, pkgtrie, static_files};
pub use package::{changelog, files, packages, revdep};
pub use qa::{qa, qa_code, qa_index, qa_package, qa_repo};
pub use repo::{ghost, lagging, missing, repo};
pub use search::search;
Loading