Skip to content
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
5 changes: 5 additions & 0 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ on:

permissions: {}

# Only the build job checks out anything, so `gh` has no git remote to read the
# repository from and has to be told which one it is working in.
env:
GH_REPO: ${{ github.repository }}

jobs:
request:
name: Read the request
Expand Down
6 changes: 5 additions & 1 deletion crates/soar-cli/src/json2db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ pub fn json_to_db(input_path: &str, output_path: &str, repo_name: Option<&str>)
let packages: Vec<RemotePackage> = soar_registry::parse_index(json_content.as_bytes())
.map_err(|e| SoarError::Custom(format!("parsing JSON from {}: {}", input_path, e)))?;

info!(count = packages.len(), "Parsed JSON metadata");
// The count is both said and recorded: the message is what a reader sees,
// since info fields are the event stream's rather than the terminal's, and
// the field is what `--json` carries.
let count = packages.len();
info!(count, "Parsed JSON metadata for {count} packages");

if packages.is_empty() {
info!("No packages found in JSON file");
Expand Down
40 changes: 33 additions & 7 deletions crates/soar-cli/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,36 @@ use tracing_subscriber::{

use crate::{cli::Args, utils::Colored};

/// Collects an event's message and the fields recorded alongside it.
///
/// The fields are what say which repository or database a record is about, so a
/// log that drops them leaves every repetition of a message looking the same.
#[derive(Default)]
struct MessageVisitor {
message: Option<String>,
fields: Vec<(&'static str, String)>,
}

impl tracing::field::Visit for MessageVisitor {
fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn std::fmt::Debug) {
impl MessageVisitor {
fn record(&mut self, field: &tracing::field::Field, value: String) {
if field.name() == "message" {
self.message = Some(format!("{value:?}"));
self.message = Some(value);
} else {
self.fields.push((field.name(), value));
}
}
}

impl tracing::field::Visit for MessageVisitor {
fn record_str(&mut self, field: &tracing::field::Field, value: &str) {
self.record(field, value.to_string());
}

fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn std::fmt::Debug) {
self.record(field, format!("{value:?}"));
}
}

pub struct CustomFormatter;

impl<S, N> FormatEvent<S, N> for CustomFormatter
Expand All @@ -40,7 +57,8 @@ where
let mut visitor = MessageVisitor::default();
event.record(&mut visitor);

match *event.metadata().level() {
let level = *event.metadata().level();
match level {
Level::TRACE => write!(writer, "{} ", Colored(Magenta, "[TRACE]")),
Level::DEBUG => write!(writer, "{} ", Colored(Blue, "[DEBUG]")),
Level::INFO => write!(writer, ""),
Expand All @@ -49,10 +67,18 @@ where
}?;

if let Some(message) = visitor.message {
writeln!(writer, "{message}")
} else {
writeln!(writer)
write!(writer, "{message}")?;
}

// Info is soar's own output, where the fields carry what `--json` prints
// rather than anything a reader of the line needs appended to it.
if level != Level::INFO {
for (name, value) in visitor.fields {
write!(writer, " {}={value}", Colored(Blue, name))?;
}
}

writeln!(writer)
}
}

Expand Down
13 changes: 2 additions & 11 deletions crates/soar-db/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{collections::HashMap, path::Path};
use diesel::{sql_query, Connection, ConnectionError, RunQueryDsl, SqliteConnection};
use tracing::{debug, trace};

use crate::migration::{apply_migrations, migrate_json_to_jsonb, DbType};
use crate::migration::{apply_migrations, migrate_metadata_json_to_jsonb, DbType};

/// How long to wait for another process to let go of the database.
///
Expand Down Expand Up @@ -64,14 +64,6 @@ impl DbConnection {
.map_err(|e| ConnectionError::BadConnection(e.to_string()))?;
trace!("migrations applied");

// Migrate text JSON to JSONB for core database
// Metadata databases are generated externally and migrated on fetch
if matches!(db_type, DbType::Core) {
migrate_json_to_jsonb(&mut conn, db_type)
.map_err(|e| ConnectionError::BadConnection(e.to_string()))?;
trace!("JSON to JSONB migration completed");
}

debug!(path = %path_str, "database opened successfully");
Ok(Self {
conn,
Expand Down Expand Up @@ -134,8 +126,7 @@ impl DbConnection {

prepare(&mut conn)?;

// Migrate text JSON to JSONB binary format
migrate_json_to_jsonb(&mut conn, DbType::Metadata)
migrate_metadata_json_to_jsonb(&mut conn)
.map_err(|e| ConnectionError::BadConnection(e.to_string()))?;
trace!("JSON to JSONB migration completed");

Expand Down
Loading
Loading