diff --git a/src/notification_triggered/src/main.rs b/src/notification_triggered/src/main.rs index b72f519..8b8c74d 100644 --- a/src/notification_triggered/src/main.rs +++ b/src/notification_triggered/src/main.rs @@ -44,17 +44,18 @@ async fn function_handler(event: LambdaEvent) -> Result) -> Result "open", + (None, Some(_)) => "in-progress", + (Some(_), _) => "completed", + }) .execute(&mut *tx).await?; } sqlx::query( r#" - UPDATE issues - SET certified = true - WHERE (certified = false OR certified IS NULL) AND 'kudos' = ANY(labels) + UPDATE tasks + SET is_certified = true + WHERE (is_certified = false OR is_certified IS NULL) AND 'kudos' = ANY(labels) "#, ) .execute(&mut *tx) diff --git a/src/shared/src/functions.rs b/src/shared/src/functions.rs index d3ba93c..ec635b8 100644 --- a/src/shared/src/functions.rs +++ b/src/shared/src/functions.rs @@ -180,23 +180,24 @@ pub async fn import_repositories( .enumerate() .map(|(i, _)| { format!( - "(${}, ${}, ${}, ${}, ${}, ${}, ${}, ${}, ${})", - i * 9 + 1, - i * 9 + 2, - i * 9 + 3, - i * 9 + 4, - i * 9 + 5, - i * 9 + 6, - i * 9 + 7, - i * 9 + 8, - i * 9 + 9, + "(${}, ${}, ${}, ${}, ${}, ${}, ${}, ${}, ${}, 'dev', ${})", + i * 10 + 1, + i * 10 + 2, + i * 10 + 3, + i * 10 + 4, + i * 10 + 5, + i * 10 + 6, + i * 10 + 7, + i * 10 + 8, + i * 10 + 9, + i * 10 + 10, ) }) .collect::>() .join(", "); let query_string = format!( - "INSERT INTO issues (number, title, labels, repository_id, issue_created_at, issue_closed_at, open, assignee_id, description) VALUES {} + "INSERT INTO tasks (number, title, labels, repository_id, issue_created_at, issue_closed_at, open, assignee_user_id, description, type, status) VALUES {} ON CONFLICT (repository_id, number) DO UPDATE SET title = EXCLUDED.title, @@ -204,8 +205,9 @@ pub async fn import_repositories( issue_created_at = EXCLUDED.issue_created_at, issue_closed_at = EXCLUDED.issue_closed_at, open = EXCLUDED.open, - assignee_id = EXCLUDED.assignee_id, - description = EXCLUDED.description", + assignee_user_id = EXCLUDED.assignee_user_id, + description = EXCLUDED.description, + status = EXCLUDED.status", placeholders ); @@ -222,12 +224,17 @@ pub async fn import_repositories( .bind(issue.issue_created_at) .bind(issue.issue_closed_at) .bind(issue.issue_closed_at.is_none()) - .bind(if let Some(assignee) = issue.assignee { - username_to_id.get(&assignee) + .bind(if let Some(assignee) = &issue.assignee { + username_to_id.get(assignee) } else { None }) .bind(issue.description) + .bind(match (issue.issue_closed_at, &issue.assignee) { + (None, None) => "open", + (None, Some(_)) => "in-progress", + (Some(_), _) => "completed", + }) } let issues_inserted_count = insert_issues_query @@ -240,9 +247,9 @@ pub async fn import_repositories( sqlx::query( r#" - UPDATE issues - SET certified = true - WHERE (certified = false OR certified IS NULL) AND 'kudos' = ANY(labels) + UPDATE tasks + SET is_certified = true + WHERE (is_certified = false OR is_certified IS NULL) AND 'kudos' = ANY(labels) "#, ) .execute(&mut **tx)