Skip to content

Migrate to Tera #887

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 30 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3c92d36
Builds
Kixiron Jul 3, 2020
d83cccd
Error, ctry! and cexpect!
Kixiron Jul 3, 2020
5ee1178
Crate Details
Kixiron Jul 3, 2020
884b8aa
Source
Kixiron Jul 3, 2020
efac685
Rustdoc
Kixiron Jul 3, 2020
f68d7be
Release Activity
Kixiron Jul 3, 2020
cd53bc7
Build Queue
Kixiron Jul 3, 2020
efdb5fc
Deleted Handlebars and renamed tera-templates to templates
Kixiron Jul 3, 2020
377f383
Don't let release activity panic with zero releases
Kixiron Jul 4, 2020
f33e06a
Rustfmt
Kixiron Jul 4, 2020
f6340fd
Renamed build_log and made the builds page use comments over shell cmds
Kixiron Jul 5, 2020
d865d87
Don't re-eval req in cexpect!
Kixiron Jul 5, 2020
fcb76a8
Remove useless Default for ErrorPage
Kixiron Jul 5, 2020
cffe56f
Don't use a Cow for BuildQueuePage
Kixiron Jul 5, 2020
d837b48
Removed accidental file
Kixiron Jul 5, 2020
db4e428
Added TODO to crate details
Kixiron Jul 5, 2020
d056442
Grammar
Kixiron Jul 5, 2020
db62438
Spelling
Kixiron Jul 5, 2020
5d308f4
Grammar
Kixiron Jul 5, 2020
ad50f68
Don't escape the description
Kixiron Jul 5, 2020
6a53a71
Macro'd out the release list, uncow'd some things
Kixiron Jul 7, 2020
b874002
Untangled JS
Kixiron Jul 7, 2020
72949ae
Clippy
Kixiron Jul 7, 2020
cd6172c
Missing macro import
Kixiron Jul 7, 2020
bc7775b
Fixed bugs
Kixiron Jul 7, 2020
a04dc34
Add test for missing dependency kind
jyn514 Jul 12, 2020
ef32706
Add test that readme is rendered
jyn514 Jul 13, 2020
a35262a
Add test case for build status
jyn514 Jul 13, 2020
6364945
Added newline to page.html
Kixiron Jul 13, 2020
171d4f4
Update templates/macros.html
Kixiron Jul 13, 2020
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
110 changes: 0 additions & 110 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ serde_json = "1.0"
# iron dependencies
iron = "0.5"
router = "0.5"
handlebars-iron = "0.25"
params = "0.8"
staticfile = { version = "0.4", features = [ "cache" ] }
tempfile = "3.1.0"
Expand Down
1 change: 0 additions & 1 deletion dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ RUN mkdir -p /opt/docsrs/prefix
COPY --from=build /build/target/release/cratesfyi /usr/local/bin
COPY static /opt/docsrs/prefix/public_html
COPY templates /opt/docsrs/templates
COPY tera-templates /opt/docsrs/tera-templates
COPY dockerfiles/entrypoint.sh /opt/docsrs/

WORKDIR /opt/docsrs
Expand Down
2 changes: 1 addition & 1 deletion src/build_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::db::Pool;
use crate::error::Result;
use log::error;

#[derive(Debug, Eq, PartialEq, serde::Serialize)]
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize)]
pub(crate) struct QueuedCrate {
#[serde(skip)]
id: i32,
Expand Down
100 changes: 1 addition & 99 deletions src/docbuilder/limits.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error::Result;
use postgres::Connection;
use serde::Serialize;
use std::{collections::BTreeMap, time::Duration};
use std::time::Duration;

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub(crate) struct Limits {
Expand Down Expand Up @@ -67,52 +67,6 @@ impl Limits {
pub(crate) fn targets(&self) -> usize {
self.targets
}

pub(crate) fn for_website(&self) -> BTreeMap<String, String> {
let mut res = BTreeMap::new();
res.insert("Available RAM".into(), SIZE_SCALE(self.memory));
res.insert(
"Maximum rustdoc execution time".into(),
TIME_SCALE(self.timeout.as_secs() as usize),
);
res.insert(
"Maximum size of a build log".into(),
SIZE_SCALE(self.max_log_size),
);
if self.networking {
res.insert("Network access".into(), "allowed".into());
} else {
res.insert("Network access".into(), "blocked".into());
}
res.insert(
"Maximum number of build targets".into(),
self.targets.to_string(),
);
res
}
}

const TIME_SCALE: fn(usize) -> String = |v| scale(v, 60, &["seconds", "minutes", "hours"]);
const SIZE_SCALE: fn(usize) -> String = |v| scale(v, 1024, &["bytes", "KB", "MB", "GB"]);

fn scale(value: usize, interval: usize, labels: &[&str]) -> String {
let (mut value, interval) = (value as f64, interval as f64);
let mut chosen_label = &labels[0];
for label in &labels[1..] {
if value / interval >= 1.0 {
chosen_label = label;
value /= interval;
} else {
break;
}
}
// 2.x
let mut value = format!("{:.1}", value);
// 2.0 -> 2
if value.ends_with(".0") {
value.truncate(value.len() - 2);
}
format!("{} {}", value, chosen_label)
}

#[cfg(test)]
Expand Down Expand Up @@ -161,56 +115,4 @@ mod test {
Ok(())
});
}

#[test]
fn display_limits() {
let limits = Limits {
memory: 102_400,
timeout: Duration::from_secs(300),
targets: 1,
..Limits::default()
};
let display = limits.for_website();
assert_eq!(display.get("Network access"), Some(&"blocked".into()));
assert_eq!(
display.get("Maximum size of a build log"),
Some(&"100 KB".into())
);
assert_eq!(
display.get("Maximum number of build targets"),
Some(&limits.targets.to_string())
);
assert_eq!(
display.get("Maximum rustdoc execution time"),
Some(&"5 minutes".into())
);
assert_eq!(display.get("Available RAM"), Some(&"100 KB".into()));
}

#[test]
fn scale_limits() {
// time
assert_eq!(TIME_SCALE(300), "5 minutes");
assert_eq!(TIME_SCALE(1), "1 seconds");
assert_eq!(TIME_SCALE(7200), "2 hours");

// size
assert_eq!(SIZE_SCALE(1), "1 bytes");
assert_eq!(SIZE_SCALE(100), "100 bytes");
assert_eq!(SIZE_SCALE(1024), "1 KB");
assert_eq!(SIZE_SCALE(10240), "10 KB");
assert_eq!(SIZE_SCALE(1_048_576), "1 MB");
assert_eq!(SIZE_SCALE(10_485_760), "10 MB");
assert_eq!(SIZE_SCALE(1_073_741_824), "1 GB");
assert_eq!(SIZE_SCALE(10_737_418_240), "10 GB");
assert_eq!(SIZE_SCALE(std::u32::MAX as usize), "4 GB");

// fractional sizes
assert_eq!(TIME_SCALE(90), "1.5 minutes");
assert_eq!(TIME_SCALE(5400), "1.5 hours");

assert_eq!(SIZE_SCALE(1_288_490_189), "1.2 GB");
assert_eq!(SIZE_SCALE(3_758_096_384), "3.5 GB");
assert_eq!(SIZE_SCALE(1_048_051_712), "999.5 MB");
}
}
18 changes: 16 additions & 2 deletions src/test/fakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub(crate) struct FakeRelease<'a> {
registry_crate_data: RegistryCrateData,
has_docs: bool,
has_examples: bool,
/// This stores the content, while `package.readme` stores the filename
readme: Option<&'a str>,
}

impl<'a> FakeRelease<'a> {
Expand Down Expand Up @@ -62,6 +64,7 @@ impl<'a> FakeRelease<'a> {
},
has_docs: true,
has_examples: false,
readme: None,
}
}

Expand Down Expand Up @@ -92,7 +95,7 @@ impl<'a> FakeRelease<'a> {
self
}

pub fn author(mut self, author: &str) -> Self {
pub(crate) fn author(mut self, author: &str) -> Self {
self.package.authors = vec![author.into()];
self
}
Expand Down Expand Up @@ -153,6 +156,13 @@ impl<'a> FakeRelease<'a> {
self
}

/// NOTE: this should be markdown. It will be rendered as HTML when served.
pub(crate) fn readme(mut self, content: &'a str) -> Self {
self.readme = Some(content);
self.source_file("README.md", content.as_bytes())
}

/// Returns the release_id
pub(crate) fn create(self) -> Result<i32, Error> {
use std::collections::HashSet;
use std::fs;
Expand Down Expand Up @@ -222,10 +232,14 @@ impl<'a> FakeRelease<'a> {
}
}

let crate_dir = tempdir.path();
if let Some(markdown) = self.readme {
fs::write(crate_dir.join("README.md"), markdown)?;
}
let release_id = crate::db::add_package_into_database(
&db.conn(),
&package,
tempdir.path(),
crate_dir,
&self.build_result,
self.default_target.unwrap_or("x86_64-unknown-linux-gnu"),
source_meta,
Expand Down
Loading