Skip to content

Commit

Permalink
Merge pull request #11 from tofubert/cleanups
Browse files Browse the repository at this point in the history
Cleanups
  • Loading branch information
tofubert authored Aug 28, 2024
2 parents b2f2387 + 7930d6d commit e63e6f1
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 64 deletions.
100 changes: 78 additions & 22 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,94 @@
name: Rust
name: Continuous Integration

on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
push:
branches: [ "main" ]
branches:
- main
pull_request:
branches: [ "main" ]
branches:
- main
merge_group:

# ensure that the workflow is only triggered once per PR, subsequent pushes to the PR will cancel
# and restart the workflow. See https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
build:
rustfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose

test:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@cargo-make
- uses: Swatinem/rust-cache@v2
- run: cargo make lint-format

typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: cargo test --verbose
- name: Install and run tarpaulin
run: cargo install cargo-tarpaulin && cargo tarpaulin --ignore-tests

lint:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@cargo-make
- uses: Swatinem/rust-cache@v2
- run: cargo make lint-typos

dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v2

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@cargo-make
- uses: Swatinem/rust-cache@v2
- run: cargo make clippy

check:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@cargo-make
- uses: Swatinem/rust-cache@v2
- run: cargo make check
env:
RUST_BACKTRACE: full

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools
- uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov,cargo-make
- uses: Swatinem/rust-cache@v2
- run: cargo make coverage
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: lint
run: rustup component add clippy && cargo clippy -- -D warnings
- name: format
run: rustup component add rustfmt && cargo fmt -- --check
- name: audit
run: cargo install cargo-audit && cargo audit
- uses: taiki-e/install-action@v2
with:
tool: cargo-make
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo make build
env:
RUST_BACKTRACE: full
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ devlogs
config_*.toml
CONFIG_*.toml
.vscode/settings.json
.pre-commit-config.yaml
13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ authors = ["tofu <sechat@tofuli.de>"]
documentation = "https://github.com/tofubert/sechat-rs"
repository = "https://github.com/tofubert/sechat-rs"
homepage = "https://github.com/tofubert/sechat-rs"
exclude = [
"assets/*",
".github",
"Makefile.toml",
"CONTRIBUTING.md",
"*.log",
"tags",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build]
target = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]

[dependencies]
reqwest = { version = "0.12", features = ["json"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
json = "*"
jzon = "*"
base64 = "*"
toml = "*"
toml-example = "0.11.1"
Expand Down
78 changes: 78 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# configuration for https://github.com/sagiegurari/cargo-make

[config]
skip_core_tasks = true

[tasks.default]
alias = "ci"

[tasks.ci]
description = "Run continuous integration tasks"
dependencies = ["lint", "clippy", "check", "test"]


[tasks.clippy]
description = "Run Clippy for linting"
command = "cargo"
args = [
"clippy",
"--all-targets",
"--all-features",
"--tests",
"--benches",
"--",
"-W",
"clippy::pedantic",
"-D",
"warnings",
]

[tasks.lint]
description = "Lint code style (formatting, typos, docs, markdown)"
dependencies = ["lint-format"]

[tasks.lint-format]
description = "Lint code formatting"
command = "cargo"
args = ["fmt", "--all", "--check"]

[tasks.format]
description = "Fix code formatting"
command = "cargo"
args = ["fmt", "--all"]

[tasks.lint-typos]
description = "Run typo checks"
install_crate = { crate_name = "typos-cli", binary = "typos", test_arg = "--version" }
command = "typos"

[tasks.audit]
command = "cargo"
install_crate = "cargo-audit"
args = ["audit", "-D", "warnings"]


[tasks.check]
description = "Check code for errors and warnings"
command = "cargo"
args = ["check", "--all-targets", "--all-features"]

[tasks.coverage]
description = "Generate code coverage report"
command = "cargo"
args = [
"llvm-cov",
"--lcov",
"--output-path",
"target/lcov.info",
]

[tasks.build]
command = "cargo"
args = ["build"]
dependencies = ["format", "clippy", "audit"]

[tasks.test]
command = "cargo"
args = ["test"]
dependencies = ["build"]
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

* run "cargo r" or "sechat-rs" and enjoy
* If no config is found a default config will be created, which you can fill in.
* a "-c" Option for console exists, if none is proveded it will default to XDG default paths.
* a "-c" Option for console exists, if none is proveded it will default to XDG default paths.
* Logs will be written to "dev.log". This is so we dont write log output into the terminal UI.

## Logs
Logs will stored in the related XDG data dir.
Logs will stored in the related XDG data dir.
You can suppress both app log output and json dumping of failed http requests through the config.
The chat history goes into the data dir as well.
Your full chat history is stored unencrypted on disk!
Expand All @@ -23,13 +23,13 @@ To switch to Editing use "e" or "i". To switch back to Reading use "ESC".
Sending Messages is done via "Enter", which also switches back to Reading.

#### Opening
When in Reading Mode Press "o" to enter the Openening screen.
Use the Arrow keys to select a Room. Use "Enter" to open the Room. Once Enter is pressed the Cleint fetches new messages for the Room, hence a short delay might ocure.
When in Reading Mode Press "o" to enter the Opening screen.
Use the Arrow keys to select a Room. Use "Enter" to open the Room. Once Enter is pressed the Client fetches new messages for the Room, hence a short delay might ocure.
Use "Esc" to exit back to the current chat.

#### Exiting
When in Reading Mode Press "q" to enter the Quiting Screen, confirm with "y" or abort with "n".
On Exit all log files are written to the folder choosen in the config file.
When in Reading Mode Press "q" to enter the Quitting Screen, confirm with "y" or abort with "n".
On Exit all log files are written to the folder chosen in the config file.

#### Help
Use "?" to get to the help screen.
Expand All @@ -39,5 +39,4 @@ Please open issues in the issue tracker.
A list of planned and requested freatures is also kept there.

## Sponsors
Thanks to [emlix gmbh](https://github.com/emlix) for allowing [@tofu](https://github.com/tofubert) and other so spend some of their work time to tinker with this.

Thanks to [emlix gmbh](https://github.com/emlix) for allowing [@tofu](https://github.com/tofubert) and other so spend some of their work time to tinker with this.
12 changes: 12 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
coverage: # https://docs.codecov.com/docs/codecovyml-reference#coverage
precision: 1 # e.g. 89.1%
round: down
range: 85..100 # https://docs.codecov.com/docs/coverage-configuration#section-range
status: # https://docs.codecov.com/docs/commit-status
project:
default:
threshold: 1% # Avoid false negatives

comment: # https://docs.codecov.com/docs/pull-request-comments
# make the comments less noisy
require_changes: true
16 changes: 16 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# configuration for https://github.com/EmbarkStudios/cargo-deny

[licenses]
confidence-threshold = 0.8
allow = [
"Apache-2.0",
"BSD-2-Clause",
"BSD-3-Clause",
"ISC",
"MIT",
"Unicode-DFS-2016",
"GPL-3.0",
]

[bans]
multiple-versions = "allow"
16 changes: 8 additions & 8 deletions src/backend/nc_notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use notify_rust::{Hint, Notification, Timeout};
#[derive(Debug, Clone)]
pub struct NCNotify {
app_name: String,
timout_ms: u32,
presistent: bool,
timeout_ms: u32,
persistent: bool,
silent: bool,
}

impl NCNotify {
pub fn new() -> Self {
NCNotify {
app_name: config::get().data.general.chat_server_name.clone(),
timout_ms: config::get().data.notifications.timeout_ms,
presistent: config::get().data.notifications.persistent,
timeout_ms: config::get().data.notifications.timeout_ms,
persistent: config::get().data.notifications.persistent,
silent: config::get().data.notifications.silent,
}
}
Expand All @@ -30,13 +30,13 @@ impl NCNotify {
.icon("dialog-information")
.appname(self.app_name.as_str())
.to_owned();
if self.presistent {
if self.persistent {
log::debug!("Persistent Message!");
notification
.hint(Hint::Resident(true)) // this is not supported by all implementations
.timeout(Timeout::Never); // this however is
} else {
notification.timeout(Timeout::Milliseconds(self.timout_ms));
notification.timeout(Timeout::Milliseconds(self.timeout_ms));
}
notification.hint(Hint::SuppressSound(self.silent));

Expand All @@ -51,12 +51,12 @@ impl NCNotify {
.icon("dialog-information")
.appname(self.app_name.as_str())
.to_owned();
if self.presistent {
if self.persistent {
notification
.hint(Hint::Resident(true)) // this is not supported by all implementations
.timeout(Timeout::Never); // this however is
} else {
notification.timeout(Timeout::Milliseconds(self.timout_ms));
notification.timeout(Timeout::Milliseconds(self.timeout_ms));
}
notification.hint(Hint::SuppressSound(self.silent));

Expand Down
10 changes: 5 additions & 5 deletions src/backend/nc_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![allow(dead_code)]

use base64::{prelude::BASE64_STANDARD, write::EncoderWriter};
use json;
use jzon;
use reqwest::header::HeaderMap;
use reqwest::{header, Client, Response, Url};
use serde::{Deserialize, Deserializer, Serialize};
Expand Down Expand Up @@ -375,7 +375,7 @@ impl NCRequest {
}
}

pub async fn fetch_rooms_inital(&self) -> Result<(Vec<NCReqDataRoom>, i64), Box<dyn Error>> {
pub async fn fetch_rooms_initial(&self) -> Result<(Vec<NCReqDataRoom>, i64), Box<dyn Error>> {
self.request_rooms(None).await
}

Expand Down Expand Up @@ -423,13 +423,13 @@ impl NCRequest {
}
}

pub async fn fetch_chat_inital(
pub async fn fetch_chat_initial(
&self,
token: &str,
maxMessage: i32,
) -> Result<Vec<NCReqDataMessage>, Box<dyn Error>> {
let response_result = self.request_chat(token, maxMessage, None).await;
// Inital results come last to first. And we want the latest message always to be at the end.
// Initial results come last to first. And we want the latest message always to be at the end.
match response_result {
Ok(Some(mut response)) => {
response.reverse();
Expand Down Expand Up @@ -542,7 +542,7 @@ impl NCRequest {
let mut name = path.clone();
name.push(url.replace('/', "_"));
let mut file = File::create(name)?;
let pretty_text = json::stringify_pretty(json::parse(text)?, 2);
let pretty_text = jzon::stringify_pretty(jzon::parse(text)?, 2);
file.write_all(pretty_text.as_bytes())?;
}
Ok(())
Expand Down
Loading

0 comments on commit e63e6f1

Please sign in to comment.