Skip to content

Commit

Permalink
Merge pull request #143 from kudos-ink/allow-for-manual-certification
Browse files Browse the repository at this point in the history
feat: allow manual certification
  • Loading branch information
CJ13th authored Oct 31, 2024
2 parents 4adab0d + d097f1a commit b50bdaa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
7 changes: 2 additions & 5 deletions src/notification_triggered/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use shared::types::{AsyncLambdaPayload, KudosIssue, Res};
use sqlx::PgPool;
use sqlx::Row;
use std::env;
use std::fmt::format;

/*
Receives issue details as payload
Expand Down Expand Up @@ -45,8 +44,8 @@ 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, certified, description)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
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)
ON CONFLICT (repository_id, number)
DO UPDATE SET
title = EXCLUDED.title,
Expand All @@ -56,7 +55,6 @@ async fn function_handler(event: LambdaEvent<AsyncLambdaPayload>) -> Result<Res,
issue_closed_at = EXCLUDED.issue_closed_at,
assignee_id = EXCLUDED.assignee_id,
open = EXCLUDED.open,
certified = EXCLUDED.certified,
description = EXCLUDED.description
"#
)
Expand All @@ -72,7 +70,6 @@ async fn function_handler(event: LambdaEvent<AsyncLambdaPayload>) -> Result<Res,
None
})
.bind(&kudos_issue.issue_closed_at.is_none())
.bind(&kudos_issue.certified)
.bind(&kudos_issue.description)
.execute(&mut *tx).await?;
}
Expand Down
35 changes: 22 additions & 13 deletions src/shared/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,24 +180,23 @@ pub async fn import_repositories(
.enumerate()
.map(|(i, _)| {
format!(
"(${}, ${}, ${}, ${}, ${}, ${}, ${}, ${}, ${}, ${})",
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,
"(${}, ${}, ${}, ${}, ${}, ${}, ${}, ${}, ${})",
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,
)
})
.collect::<Vec<_>>()
.join(", ");

let query_string = format!(
"INSERT INTO issues (number, title, labels, repository_id, issue_created_at, issue_closed_at, open, assignee_id, certified, description) VALUES {}",
"INSERT INTO issues (number, title, labels, repository_id, issue_created_at, issue_closed_at, open, assignee_id, description) VALUES {}",
placeholders
);

Expand All @@ -219,7 +218,6 @@ pub async fn import_repositories(
} else {
None
})
.bind(issue.certified)
.bind(issue.description)
}

Expand All @@ -230,6 +228,17 @@ pub async fn import_repositories(

total_issues_imported += issues_inserted_count;
}

sqlx::query(
r#"
UPDATE issues
SET certified = true
WHERE certified = false AND 'kudos' = ANY(labels)
"#,
)
.execute(&mut **tx)
.await?;

Ok(total_issues_imported)
}

Expand Down
4 changes: 2 additions & 2 deletions src/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct KudosIssue {
pub issue_closed_at: Option<DateTime<Utc>>,
pub creator: String,
pub assignee: Option<String>,
pub certified: bool,
// pub certified: bool,
pub labels: Vec<String>,
pub description: Option<String>,
}
Expand All @@ -54,7 +54,7 @@ impl From<Issue> for KudosIssue {
issue_closed_at: value.closed_at,
creator: value.user.login,
assignee: value.assignee.map(|assignee| assignee.login),
certified: labels.contains(&String::from("kudos")),
// certified: labels.contains(&String::from("kudos")),
labels,
description: value.body,
}
Expand Down

0 comments on commit b50bdaa

Please sign in to comment.