Skip to content
Open
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
23 changes: 20 additions & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use crate::db::Database;
use crate::events::Event;
use crate::events::{Event, MessageSource};
use crate::fetcher::FetchRequest;
use crate::settings::ServerSettings;
use axum::{
Expand Down Expand Up @@ -305,7 +305,7 @@ fn generate_synthetic_id(prefix: &str) -> String {
.expect("Time went backwards");
// e.g. sashiko-local-1715890000-12345
format!(
"sashiko-{}-{}-{}",
"sashiko-{}-{}-{}@sashiko.local",
prefix,
since_the_epoch.as_secs(),
fastrand::u32(..)
Expand Down Expand Up @@ -346,6 +346,8 @@ async fn submit_patch(

let event = Event::RawMboxSubmitted {
raw,
submission_id: id.clone(),
source: MessageSource::ApiInject,
group: "api-submit".to_string(),
baseline: base_commit,
skip_subjects,
Expand Down Expand Up @@ -385,7 +387,7 @@ async fn submit_patch(
if let Err(e) = state
.db
.create_fetching_patchset(
&id,
&format!("{}@sashiko.local", id),
&format!("Fetching {} from {}...", &sha, repo_display),
skip_subjects.as_ref(),
only_subjects.as_ref(),
Expand Down Expand Up @@ -444,6 +446,7 @@ async fn submit_patch(
.send(Event::IngestionFailed {
article_id: msgid_clone.clone(),
error: format!("Failed to fetch thread: {}", e),
source: MessageSource::ApiFetchThread,
})
.await;
}
Expand Down Expand Up @@ -487,6 +490,8 @@ async fn fetch_and_inject_thread(

let event = Event::RawMboxSubmitted {
raw,
submission_id: msgid.to_string(),
source: MessageSource::ApiFetchThread,
group: "api-submit".to_string(),
baseline: None,
skip_subjects: None,
Expand Down Expand Up @@ -1008,3 +1013,15 @@ async fn rerun_patch(

Ok(Json(serde_json::json!({ "status": "accepted" })))
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_generate_synthetic_id_format() {
let id = generate_synthetic_id("test");
assert!(id.starts_with("sashiko-test-"));
assert!(id.ends_with("@sashiko.local"));
}
}
19 changes: 4 additions & 15 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3296,7 +3296,7 @@ impl Database {

pub async fn create_fetching_patchset(
&self,
article_id: &str,
root_msg_id: &str,
subject: &str,
skip_filters: Option<&Vec<String>>,
only_filters: Option<&Vec<String>>,
Expand All @@ -3305,13 +3305,7 @@ impl Database {
.duration_since(std::time::UNIX_EPOCH)?
.as_secs() as i64;

let root_msg_id = if article_id.contains('@') {
article_id.to_string()
} else {
format!("{}@sashiko.local", article_id)
};

let clid_candidates = vec![article_id.to_string(), root_msg_id.clone()];
let clid_candidates = vec![root_msg_id.to_string()];

let skip_filters_json = skip_filters.map(|f| serde_json::to_string(f).unwrap_or_default());
let only_filters_json = only_filters.map(|f| serde_json::to_string(f).unwrap_or_default());
Expand Down Expand Up @@ -3343,7 +3337,7 @@ impl Database {
}

// 2. Ensure a placeholder thread and message exist to satisfy Foreign Key constraints
let thread_id = self.ensure_thread_for_message(&root_msg_id, now).await?;
let thread_id = self.ensure_thread_for_message(root_msg_id, now).await?;

// 3. Create the fetching patchset
let mut rows = self.conn
Expand All @@ -3360,12 +3354,7 @@ impl Database {
Err(anyhow::anyhow!("Failed to get patchset ID"))
}
}
pub async fn update_patchset_error(&self, article_id: &str, error: &str) -> Result<()> {
let root_msg_id = if article_id.contains('@') {
article_id.to_string()
} else {
format!("{}@sashiko.local", article_id)
};
pub async fn update_patchset_error(&self, root_msg_id: &str, error: &str) -> Result<()> {
self.conn
.execute(
"UPDATE patchsets SET status = 'Failed', failed_reason = ? WHERE cover_letter_message_id = ?",
Expand Down
14 changes: 14 additions & 0 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@

use crate::patch::{Patch, PatchsetMetadata};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MessageSource {
Nntp,
ApiInject,
ApiFetchThread,
GitFetch,
GitImport,
GitArchive,
}

#[derive(Debug)]
#[allow(dead_code)]
pub enum Event {
Expand All @@ -39,6 +49,8 @@ pub enum Event {
},
RawMboxSubmitted {
raw: String,
submission_id: String,
source: MessageSource,
group: String,
baseline: Option<String>,
skip_subjects: Option<Vec<String>>,
Expand All @@ -47,13 +59,15 @@ pub enum Event {
IngestionFailed {
article_id: String,
error: String,
source: MessageSource,
},
}

#[derive(Debug)]
pub struct ParsedArticle {
pub group: String,
pub article_id: String,
pub source: MessageSource,
pub metadata: Option<PatchsetMetadata>,
pub patch: Option<Patch>,
pub baseline: Option<String>,
Expand Down
7 changes: 6 additions & 1 deletion src/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::events::Event;
use crate::events::{Event, MessageSource};
use crate::utils::redact_secret;
use anyhow::{Result, anyhow};
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -134,6 +134,7 @@ impl FetchAgent {
.send(Event::IngestionFailed {
article_id: commit.clone(),
error: format!("Failed to set up remote {}: {}", url, e),
source: MessageSource::GitFetch,
})
.await;
}
Expand All @@ -155,6 +156,7 @@ impl FetchAgent {
.send(Event::IngestionFailed {
article_id: commit.clone(),
error: format!("Failed to fetch from {}: {}", url, e),
source: MessageSource::GitFetch,
})
.await;
}
Expand Down Expand Up @@ -185,6 +187,7 @@ impl FetchAgent {
.send(Event::IngestionFailed {
article_id: range.clone(),
error: format!("Failed to resolve git range: {}", e),
source: MessageSource::GitFetch,
})
.await;
continue;
Expand Down Expand Up @@ -225,6 +228,7 @@ impl FetchAgent {
.send(Event::IngestionFailed {
article_id: commit_or_range.clone(),
error: format!("Failed to resolve SHA: {}", e),
source: MessageSource::GitFetch,
})
.await;
continue;
Expand Down Expand Up @@ -252,6 +256,7 @@ impl FetchAgent {
.send(Event::IngestionFailed {
article_id: commit_or_range,
error: format!("Failed to extract patch: {}", e),
source: MessageSource::GitFetch,
})
.await;
}
Expand Down
Loading