Skip to content

Commit

Permalink
Merge pull request #11 from kudos-ink/add-issue-certification
Browse files Browse the repository at this point in the history
set certified column
  • Loading branch information
CJ13th authored Sep 24, 2024
2 parents 2dfb939 + 95ac987 commit ffa8d16
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/notification_triggered/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ async fn function_handler(event: LambdaEvent<AsyncLambdaPayload>) -> Result<Res,

let insert_count = sqlx::query(
r#"
INSERT INTO issues (number, title, labels, repository_id, issue_created_at, issue_closed_at, assignee_id, open)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
INSERT INTO issues (number, title, labels, repository_id, issue_created_at, issue_closed_at, assignee_id, open, certified)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
ON CONFLICT (repository_id, number)
DO UPDATE SET
title = EXCLUDED.title,
Expand All @@ -53,7 +53,8 @@ async fn function_handler(event: LambdaEvent<AsyncLambdaPayload>) -> Result<Res,
issue_created_at = EXCLUDED.issue_created_at,
issue_closed_at = EXCLUDED.issue_closed_at,
assignee_id = EXCLUDED.assignee_id,
open = EXCLUDED.open
open = EXCLUDED.open,
certified = EXCLUDED.certified
"#
)
.bind(&kudos_issue.number)
Expand All @@ -68,6 +69,7 @@ async fn function_handler(event: LambdaEvent<AsyncLambdaPayload>) -> Result<Res,
None
})
.bind(&kudos_issue.issue_closed_at.is_none())
.bind(&kudos_issue.certified)
.execute(&mut *tx).await?.rows_affected();

tx.commit().await?;
Expand Down
20 changes: 11 additions & 9 deletions src/shared/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,22 @@ pub async fn import_repositories(
.enumerate()
.map(|(i, _)| {
format!(
"(${}, ${}, ${}, ${}, ${}, ${}, ${})",
i * 7 + 1,
i * 7 + 2,
i * 7 + 3,
i * 7 + 4,
i * 7 + 5,
i * 7 + 6,
i * 7 + 7,
"(${}, ${}, ${}, ${}, ${}, ${}, ${}, ${})",
i * 8 + 1,
i * 8 + 2,
i * 8 + 3,
i * 8 + 4,
i * 8 + 5,
i * 8 + 6,
i * 8 + 7,
i * 8 + 8,
)
})
.collect::<Vec<_>>()
.join(", ");

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

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

let issues_inserted_count = insert_issues_query
Expand Down
14 changes: 9 additions & 5 deletions src/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ pub struct KudosIssue {
pub issue_closed_at: Option<DateTime<Utc>>,
pub creator: String,
pub assignee: Option<String>,
pub certified: bool,
pub labels: Vec<String>,
}

impl From<Issue> for KudosIssue {
fn from(value: Issue) -> Self {
let labels = value
.labels
.iter()
.map(|label| label.name.clone())
.collect::<Vec<String>>();

KudosIssue {
number: value.number as i64,
title: value.title,
Expand All @@ -46,11 +53,8 @@ impl From<Issue> for KudosIssue {
issue_closed_at: value.closed_at,
creator: value.user.login,
assignee: value.assignee.map(|assignee| assignee.login),
labels: value
.labels
.iter()
.map(|label| label.name.clone())
.collect::<Vec<String>>(),
certified: labels.contains(&String::from("kudos")),
labels,
}
}
}
Expand Down

0 comments on commit ffa8d16

Please sign in to comment.