fix(events): Handle nullable label and milestone in resource events

GitLab returns null for the label/milestone fields on resource_label_events
and resource_milestone_events when the referenced label or milestone has
been deleted. This caused deserialization failures during sync.

- Add migration 012 to recreate both event tables with nullable
  label_name, milestone_title, and milestone_id columns (SQLite
  requires table recreation to alter NOT NULL constraints)
- Change GitLabLabelEvent.label and GitLabMilestoneEvent.milestone
  to Option<> in the Rust types
- Update upsert functions to pass through None values correctly
- Add tests for null label and null milestone deserialization

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Taylor Eernisse
2026-02-03 17:36:17 -05:00
parent deafa88af5
commit a92e176bb6
5 changed files with 134 additions and 14 deletions

View File

@@ -39,6 +39,10 @@ const MIGRATIONS: &[(&str, &str)] = &[
"011",
include_str!("../../migrations/011_resource_events.sql"),
),
(
"012",
include_str!("../../migrations/012_nullable_label_milestone.sql"),
),
];
/// Create a database connection with production-grade pragmas.

View File

@@ -82,7 +82,7 @@ pub fn upsert_label_events(
issue_id,
merge_request_id,
event.action,
event.label.name,
event.label.as_ref().map(|l| l.name.as_str()),
actor_id,
actor_username,
created_at,
@@ -123,8 +123,8 @@ pub fn upsert_milestone_events(
issue_id,
merge_request_id,
event.action,
event.milestone.title,
event.milestone.id,
event.milestone.as_ref().map(|m| m.title.as_str()),
event.milestone.as_ref().map(|m| m.id),
actor_id,
actor_username,
created_at,

View File

@@ -230,7 +230,7 @@ pub struct GitLabLabelEvent {
pub created_at: String,
pub resource_type: String,
pub resource_id: i64,
pub label: GitLabLabelRef,
pub label: Option<GitLabLabelRef>,
pub action: String,
}
@@ -242,7 +242,7 @@ pub struct GitLabMilestoneEvent {
pub created_at: String,
pub resource_type: String,
pub resource_id: i64,
pub milestone: GitLabMilestoneRef,
pub milestone: Option<GitLabMilestoneRef>,
pub action: String,
}