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
20 changes: 13 additions & 7 deletions src/notification_triggered/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ async fn function_handler(event: LambdaEvent<AsyncLambdaPayload>) -> Result<Res,

sqlx::query(
r#"
INSERT INTO issues (number, title, labels, repository_id, issue_created_at, issue_closed_at, assignee_id, open, description)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
INSERT INTO tasks (number, title, labels, repository_id, issue_created_at, issue_closed_at, assignee_user_id, open, description, type, status)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, 'dev', $10)
ON CONFLICT (repository_id, number)
DO UPDATE SET
title = EXCLUDED.title,
labels = EXCLUDED.labels,
issue_created_at = EXCLUDED.issue_created_at,
issue_closed_at = EXCLUDED.issue_closed_at,
assignee_id = EXCLUDED.assignee_id,
assignee_user_id = EXCLUDED.assignee_user_id,
open = EXCLUDED.open,
description = EXCLUDED.description
description = EXCLUDED.description,
status = EXCLUDED.status
"#
)
.bind(&kudos_issue.number)
Expand All @@ -70,14 +71,19 @@ async fn function_handler(event: LambdaEvent<AsyncLambdaPayload>) -> Result<Res,
})
.bind(&kudos_issue.issue_closed_at.is_none())
.bind(&kudos_issue.description)
.bind(match (&kudos_issue.issue_closed_at, &kudos_issue.assignee) {
(None, None) => "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)
Expand Down
43 changes: 25 additions & 18 deletions src/shared/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,32 +180,34 @@ 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::<Vec<_>>()
.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,
labels = EXCLUDED.labels,
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
);

Expand All @@ -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
Expand All @@ -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)
Expand Down