From 6eeb3fa25090edd11c0782079e7bbaa823159d7a Mon Sep 17 00:00:00 2001 From: Denis BOURGE Date: Wed, 5 Jun 2024 14:49:36 +0000 Subject: [PATCH] fix: handle status comment ID greater than i32 --- CHANGELOG.md | 9 ++++++++- Cargo.lock | 2 +- .../bot_commands/commands/admin/admin_add_merge_rule.rs | 4 ++-- .../src/use_cases/repositories/rename_repository.rs | 4 ++-- crates/prbot-database-memory/src/lib.rs | 6 +++--- .../migrations/202406051613_bigint_status_comment.sql | 1 + crates/prbot-database-pg/src/lib.rs | 2 ++ crates/prbot-database-pg/src/postgres.rs | 4 ++-- crates/prbot-database-tests/src/testcase.rs | 4 ++-- crates/prbot-ghapi-github/src/auth.rs | 2 +- .../src/types/reviews/review_state.rs | 8 +++++--- crates/prbot-models/src/checks_status.rs | 8 +++++--- crates/prbot-models/src/qa_status.rs | 8 ++++---- crates/prbot-models/src/repository.rs | 3 ++- crates/prbot-models/src/step_label.rs | 8 ++++---- crates/prbot/Cargo.toml | 2 +- rust-toolchain.toml | 2 +- 17 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 crates/prbot-database-pg/migrations/202406051613_bigint_status_comment.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 741c9ab5..404b3022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.25.1] + +### Fixes + +- Handle status comment IDs as bigint/int8 because of integer overflow (GitHub IDs are just super large!) + ## [0.25.0] ### Breaking changes @@ -353,7 +359,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Give rights to external accounts on specific repositories - Simple terminal UI interface to have an overview on pull requests -[Unreleased]: https://github.com/sharingcloud/github-scbot/compare/v0.25.0...HEAD +[Unreleased]: https://github.com/sharingcloud/github-scbot/compare/v0.25.1...HEAD +[0.25.1]: https://github.com/sharingcloud/github-scbot/compare/v0.25.0...v0.25.1 [0.25.0]: https://github.com/sharingcloud/github-scbot/compare/v0.24.0...v0.25.0 [0.24.0]: https://github.com/sharingcloud/github-scbot/compare/v0.23.1...v0.24.0 [0.23.1]: https://github.com/sharingcloud/github-scbot/compare/v0.23.0...v0.23.1 diff --git a/Cargo.lock b/Cargo.lock index 13ccca1c..bf7d6a73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2054,7 +2054,7 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "prbot" -version = "0.25.0" +version = "0.25.1" dependencies = [ "actix-rt", "anyhow", diff --git a/crates/prbot-core/src/bot_commands/commands/admin/admin_add_merge_rule.rs b/crates/prbot-core/src/bot_commands/commands/admin/admin_add_merge_rule.rs index eb719eb5..4b151db4 100644 --- a/crates/prbot-core/src/bot_commands/commands/admin/admin_add_merge_rule.rs +++ b/crates/prbot-core/src/bot_commands/commands/admin/admin_add_merge_rule.rs @@ -68,8 +68,8 @@ mod tests { let repo_owner: String = "bar".into(); let mut ctx = CommandContextTest::new(); - ctx.repo_name = repo_name.clone(); - ctx.repo_owner = repo_owner.clone(); + ctx.repo_name.clone_from(&repo_name); + ctx.repo_owner.clone_from(&repo_owner); ctx.db_service .repositories_create(Repository { owner: repo_owner.clone(), diff --git a/crates/prbot-core/src/use_cases/repositories/rename_repository.rs b/crates/prbot-core/src/use_cases/repositories/rename_repository.rs index 91e8175a..9aaf7a87 100644 --- a/crates/prbot-core/src/use_cases/repositories/rename_repository.rs +++ b/crates/prbot-core/src/use_cases/repositories/rename_repository.rs @@ -33,8 +33,8 @@ impl RenameRepositoryInterface for RenameRepository { .await?; if let Some(mut repo) = repo { - repo.owner = new_path.owner().to_owned(); - repo.name = new_path.name().to_owned(); + new_path.owner().clone_into(&mut repo.owner); + new_path.name().clone_into(&mut repo.name); let repo = ctx.db_service.repositories_update(repo).await?; Ok(Some(repo)) diff --git a/crates/prbot-database-memory/src/lib.rs b/crates/prbot-database-memory/src/lib.rs index c37882dc..21fceb6f 100644 --- a/crates/prbot-database-memory/src/lib.rs +++ b/crates/prbot-database-memory/src/lib.rs @@ -286,8 +286,8 @@ impl DbService for MemoryDb { private_key: &str, ) -> Result { let mut account = self.external_accounts_get_expect(username).await?; - account.public_key = public_key.to_owned(); - account.private_key = private_key.to_owned(); + public_key.clone_into(&mut account.public_key); + private_key.clone_into(&mut account.private_key); self.external_accounts .write() .unwrap() @@ -874,7 +874,7 @@ impl DbService for MemoryDb { value: &str, ) -> Result { let mut repository = self.repositories_get_expect(owner, name).await?; - repository.pr_title_validation_regex = value.to_owned(); + value.clone_into(&mut repository.pr_title_validation_regex); self.repositories .write() .unwrap() diff --git a/crates/prbot-database-pg/migrations/202406051613_bigint_status_comment.sql b/crates/prbot-database-pg/migrations/202406051613_bigint_status_comment.sql new file mode 100644 index 00000000..be1a362c --- /dev/null +++ b/crates/prbot-database-pg/migrations/202406051613_bigint_status_comment.sql @@ -0,0 +1 @@ +ALTER TABLE pull_request ALTER COLUMN status_comment_id TYPE bigint; diff --git a/crates/prbot-database-pg/src/lib.rs b/crates/prbot-database-pg/src/lib.rs index ebd9e636..8cf5b2de 100644 --- a/crates/prbot-database-pg/src/lib.rs +++ b/crates/prbot-database-pg/src/lib.rs @@ -21,6 +21,8 @@ where A: Acquire<'a>, ::Target: Migrate, { + info!("Running migrations"); + sqlx::migrate!("./migrations") .run(migrator) .await diff --git a/crates/prbot-database-pg/src/postgres.rs b/crates/prbot-database-pg/src/postgres.rs index dd95c9eb..efb29032 100644 --- a/crates/prbot-database-pg/src/postgres.rs +++ b/crates/prbot-database-pg/src/postgres.rs @@ -769,7 +769,7 @@ impl DbService for PostgresDb { .bind(instance.number as i32) .bind(instance.qa_status.to_string()) .bind(instance.needed_reviewers_count as i32) - .bind(instance.status_comment_id as i32) + .bind(instance.status_comment_id as i64) .bind(instance.checks_enabled) .bind(instance.automerge) .bind(instance.locked) @@ -805,7 +805,7 @@ impl DbService for PostgresDb { ) .bind(instance.qa_status.to_string()) .bind(instance.needed_reviewers_count as i32) - .bind(instance.status_comment_id as i32) + .bind(instance.status_comment_id as i64) .bind(instance.checks_enabled) .bind(instance.automerge) .bind(instance.locked) diff --git a/crates/prbot-database-tests/src/testcase.rs b/crates/prbot-database-tests/src/testcase.rs index fe7ac415..05eb0c18 100644 --- a/crates/prbot-database-tests/src/testcase.rs +++ b/crates/prbot-database-tests/src/testcase.rs @@ -17,7 +17,7 @@ where let full_name = format!("test-bot-{test_name}"); let base_url = get_base_url(&config.database.pg.url); let new_url = create_db_url(&base_url, &full_name); - config.database.pg.url = new_url.clone(); + config.database.pg.url.clone_from(&new_url); config.database.pg.pool_size = 2; config.database.pg.connection_timeout = 5; @@ -50,7 +50,7 @@ where let full_name = format!("test-bot-{test_name}"); let base_url = get_base_url(&config.database.pg.url); let new_url = create_db_url(&base_url, &full_name); - config.database.pg.url = new_url.clone(); + config.database.pg.url.clone_from(&new_url); config.database.pg.pool_size = 2; config.database.pg.connection_timeout = 5; diff --git a/crates/prbot-ghapi-github/src/auth.rs b/crates/prbot-ghapi-github/src/auth.rs index e7cad93b..9b1460b9 100644 --- a/crates/prbot-ghapi-github/src/auth.rs +++ b/crates/prbot-ghapi-github/src/auth.rs @@ -116,7 +116,7 @@ async fn get_or_create_installation_access_token( // Time to rebuild! let token = create_installation_access_token(config, api_service).await?; let mut last_auth = LAST_TOKEN.write().await; - last_auth.token = token.clone(); + last_auth.token.clone_from(&token); last_auth.expiration = now_timestamp + INSTALLATION_TOKEN_LIFETIME_IN_SECONDS; Ok(token) diff --git a/crates/prbot-ghapi-interface/src/types/reviews/review_state.rs b/crates/prbot-ghapi-interface/src/types/reviews/review_state.rs index 1b784e39..517d3987 100644 --- a/crates/prbot-ghapi-interface/src/types/reviews/review_state.rs +++ b/crates/prbot-ghapi-interface/src/types/reviews/review_state.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use serde::{Deserialize, Serialize}; /// GitHub Review state. @@ -17,9 +19,9 @@ pub enum GhReviewState { Pending, } -impl ToString for GhReviewState { - fn to_string(&self) -> String { - serde_plain::to_string(&self).unwrap() +impl Display for GhReviewState { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&serde_plain::to_string(&self).unwrap()) } } diff --git a/crates/prbot-models/src/checks_status.rs b/crates/prbot-models/src/checks_status.rs index 4af79c90..e8579a37 100644 --- a/crates/prbot-models/src/checks_status.rs +++ b/crates/prbot-models/src/checks_status.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -30,9 +32,9 @@ impl ChecksStatus { } } -impl ToString for ChecksStatus { - fn to_string(&self) -> String { - self.to_str().into() +impl Display for ChecksStatus { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.to_str()) } } diff --git a/crates/prbot-models/src/qa_status.rs b/crates/prbot-models/src/qa_status.rs index 29488f6d..6e3f4f80 100644 --- a/crates/prbot-models/src/qa_status.rs +++ b/crates/prbot-models/src/qa_status.rs @@ -1,4 +1,4 @@ -use std::str::FromStr; +use std::{fmt::Display, str::FromStr}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -32,9 +32,9 @@ impl QaStatus { } } -impl ToString for QaStatus { - fn to_string(&self) -> String { - self.to_str().into() +impl Display for QaStatus { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.to_str()) } } diff --git a/crates/prbot-models/src/repository.rs b/crates/prbot-models/src/repository.rs index 61d26a9e..744e6619 100644 --- a/crates/prbot-models/src/repository.rs +++ b/crates/prbot-models/src/repository.rs @@ -44,7 +44,8 @@ impl Repository { .try_into() .unwrap_or_default(); self.default_needed_reviewers_count = config.default_needed_reviewers_count; - self.pr_title_validation_regex = config.default_pr_title_validation_regex.clone(); + self.pr_title_validation_regex + .clone_from(&config.default_pr_title_validation_regex); self } } diff --git a/crates/prbot-models/src/step_label.rs b/crates/prbot-models/src/step_label.rs index 79c481ec..e077d9a3 100644 --- a/crates/prbot-models/src/step_label.rs +++ b/crates/prbot-models/src/step_label.rs @@ -1,6 +1,6 @@ //! Label types. -use std::convert::TryFrom; +use std::{convert::TryFrom, fmt::Display}; use thiserror::Error; @@ -41,9 +41,9 @@ impl StepLabel { } } -impl ToString for StepLabel { - fn to_string(&self) -> String { - self.to_str().into() +impl Display for StepLabel { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.to_str()) } } diff --git a/crates/prbot/Cargo.toml b/crates/prbot/Cargo.toml index 3624f8ac..4d4b3c71 100644 --- a/crates/prbot/Cargo.toml +++ b/crates/prbot/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "prbot" -version = "0.25.0" +version = "0.25.1" authors = ["Denis BOURGE "] edition = "2021" build = "build.rs" diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 28384363..ec8e6f97 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "stable" +channel = "1.78.0" components = ["clippy", "rustfmt", "llvm-tools"]