diff --git a/.github/workflows/copyrights.yml b/.github/workflows/copyrights.yml index 7c7fc004..5f0eff7c 100644 --- a/.github/workflows/copyrights.yml +++ b/.github/workflows/copyrights.yml @@ -30,3 +30,6 @@ jobs: steps: - uses: actions/checkout@v4 - uses: yegor256/copyrights-action@0.0.4 + with: + ignore: >- + server/resources/report.tex diff --git a/.gitignore b/.gitignore index e27a6dd4..0aa15dbd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target +/out ### Rust template # Generated by Cargo # will have compiled files and executables diff --git a/.github/workflows/license.yml b/.rustfmt.toml similarity index 59% rename from .github/workflows/license.yml rename to .rustfmt.toml index 2dbdfb75..917a45d4 100644 --- a/.github/workflows/license.yml +++ b/.rustfmt.toml @@ -19,34 +19,4 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. ---- -name: license -on: - push: - pull_request: -jobs: - license: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - run: | - set -e - find . -type f \( \ - -name "LICENSE.*" \ - -o -name "*.yml" \ - -o -name "*.xml" \ - -o -name "*.rs" \ - -o -name "*.toml" \) > files.txt - header="Copyright (c) 2024 Aliaksei Bialiauski" - failed="false" - while IFS= read -r file; do - if ! grep -q "$header" "$file"; then - failed="true" - echo "No license in: $file" - fi - done < files.txt - if [ "${failed}" == "true" ]; then - exit 1 - fi +max_width = 90 diff --git a/cli/src/args.rs b/cli/src/args.rs index f318fc80..1a2297f9 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -25,6 +25,10 @@ use clap::Parser; // We should process the port argument and // pass it to the server on `start` command. // Start command should be added also with clap +// @todo #41:15min Add --report argument. +// Let's add --report option for generating reports in desired formats: +// We should support following formats: xml, tex, and txt. User should have +// ability to generate report in multiple formats as well: --report tex,xml,txt. #[derive(Parser, Debug)] pub(crate) struct Args { /// The port to run diff --git a/server/resources/report.tex b/server/resources/report.tex new file mode 100644 index 00000000..b4df993b --- /dev/null +++ b/server/resources/report.tex @@ -0,0 +1,7 @@ +\usepackage{to-be-determined} +\documentclass[12pt]{article} +\begin{document} + +\section*{Fakehub report} +\tbd{History: TBD} +\end{document} diff --git a/server/src/lib.rs b/server/src/lib.rs index 5cf132ee..10bcefd1 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -29,6 +29,7 @@ use tokio::net::TcpListener; use crate::routes::home; use crate::xml::storage::touch_storage; +pub mod report; mod routes; mod xml; diff --git a/server/src/report/latex.rs b/server/src/report/latex.rs new file mode 100644 index 00000000..74148575 --- /dev/null +++ b/server/src/report/latex.rs @@ -0,0 +1,73 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Aliaksei Bialiauski +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +use std::fs; +use std::path::Path; + +/// Read LaTeX template. +/// @todo #41:60min Add function for appending new content into the template. +/// We need to create new function that will append input into the template, +/// thus it will build a detailed report. +/// # Arguments +/// +/// * `path`: Template path +/// +/// returns: String +/// +/// # Examples +/// +/// ``` +/// use crate::server::report::latex::template; +/// let content = template("resources/report.tex"); +/// print!("{content}") +/// ``` +pub fn template(path: &str) -> String { + return fs::read_to_string(Path::new(path)).expect("template should be read from"); +} + +#[cfg(test)] +mod tests { + use anyhow::Result; + + use crate::report::latex::template; + + #[test] + // @todo #41:60min Add support of @ExtendsWith from JUnit in order to pass expected as test parameter. + // We should use extensions in order to pass expected as parameters into + // test. If there is no crate with such functionality - let's develop and + // release one. + fn returns_template_content() -> Result<()> { + let content = template("resources/report.tex"); + let expected = r"\usepackage{to-be-determined} +\documentclass[12pt]{article} +\begin{document} + +\section*{Fakehub report} +\tbd{History: TBD} +\end{document} +"; + assert_eq!( + content, expected, + "Template content '{content}' does not match with '{expected}'" + ); + Ok(()) + } +} diff --git a/server/src/report/mod.rs b/server/src/report/mod.rs new file mode 100644 index 00000000..d320dffa --- /dev/null +++ b/server/src/report/mod.rs @@ -0,0 +1,25 @@ +// The MIT License (MIT) +// +// Copyright (c) 2024 Aliaksei Bialiauski +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// @todo #41:45min Create similar to latex.rs functions for XML and TXT formats. +// Let's create similar to latex.rs functions for generating reports in XML and TXT. +// Don't forget to remove this puzzle. +pub mod latex;