Skip to content

Commit

Permalink
webapp: Handle maintainers with 5 fields in per_repo counts
Browse files Browse the repository at this point in the history
Sixth field (num_projects_vulnerable) was added later than the column, and wasn't yet
filled for maintainers which have no counter updates since then.
  • Loading branch information
AMDmi3 committed Nov 25, 2024
1 parent 0d35e8b commit cfb362a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
35 changes: 14 additions & 21 deletions repology-webapp/src/views/maintainer/maintainer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct Maintainer {
pub num_projects_problematic: i32,
pub num_projects_vulnerable: i32,

pub counts_per_repo: sqlx::types::Json<HashMap<String, (i32, i32, i32, i32, i32, i32)>>,
pub counts_per_repo: sqlx::types::Json<HashMap<String, Vec<i32>>>,

pub num_projects_per_category: sqlx::types::Json<HashMap<String, i32>>,

Expand Down Expand Up @@ -190,29 +190,22 @@ pub async fn maintainer(
.then_with(|| a.name.cmp(&b.name))
})
.collect();

let maintainer_repositories: Vec<_> = std::mem::take(&mut maintainer.counts_per_repo.0)
.into_iter()
.map(
|(
name,
(
num_packages,
num_projects,
num_projects_newest,
num_projects_outdated,
num_projects_problematic,
num_projects_vulnerable,
),
)| MaintainerRepository {
.map(|(name, fields)| {
// there may be 5 or 6 fields - vulnerable projects count was added at some
// point and there are still maintainers which do not have it filled
MaintainerRepository {
name,
num_packages: num_packages as usize,
num_projects: num_projects as usize,
num_projects_newest: num_projects_newest as usize,
num_projects_outdated: num_projects_outdated as usize,
num_projects_problematic: num_projects_problematic as usize,
num_projects_vulnerable: num_projects_vulnerable as usize,
},
)
num_packages: fields[0] as usize,
num_projects: fields[1] as usize,
num_projects_newest: fields[2] as usize,
num_projects_outdated: fields[3] as usize,
num_projects_problematic: fields[4] as usize,
num_projects_vulnerable: *fields.get(5).unwrap_or(&0) as usize,
}
})
.sorted_by(|a, b| {
a.num_projects_newest
.cmp(&b.num_projects_newest)
Expand Down
3 changes: 2 additions & 1 deletion repology-webapp/tests/fixtures/maintainer_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ INSERT INTO maintainers(id, maintainer, orphaned_at) VALUES

INSERT INTO maintainers(id, maintainer, num_packages, num_projects, counts_per_repo, num_projects_per_category) VALUES
(2, '[email protected]', 10, 10, '{"freebsd":[10,11,12,13,14,15]}'::jsonb, '{"games":10}'::jsonb),
(3, 'fallback-mnt-foo@repology', 1, 1, '{"freebsd":[1,1,1,1,1,1]}'::jsonb, '{"games":10}'::jsonb);
(3, 'fallback-mnt-foo@repology', 1, 1, '{"freebsd":[1,1,1,1,1,1]}'::jsonb, '{"games":10}'::jsonb),
(4, '[email protected]', 10, 10, '{"freebsd":[10,11,12,13,14]}'::jsonb, '{"games":10}'::jsonb);
8 changes: 8 additions & 0 deletions repology-webapp/tests/maintainer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ async fn test_maintainer(pool: PgPool) {
// contact section
contains_not "mailto:[email protected]",
);
check_response!(
pool,
"/maintainer/[email protected]",
status OK,
content_type "text/html",
html_ok "allow_empty_tags,warnings_fatal",
// enough to just be deserialized without errors
);
}

0 comments on commit cfb362a

Please sign in to comment.