Skip to content

Commit 0f58785

Browse files
committed
chore: Move to Rust edition 2024
1 parent 38b733e commit 0f58785

7 files changed

Lines changed: 56 additions & 45 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ version = "0.1.0"
1313
license = "MIT"
1414
repository = "https://github.com/obeli-sk/stargazers"
1515
authors = ["Project Developers"]
16-
edition = "2021"
17-
rust-version = "1.87.0"
16+
edition = "2024"
17+
rust-version = "1.89.0"
1818

1919
[workspace.dependencies]
2020
cynic = "3.12.0"

activity/db/turso/src/lib.rs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::exports::stargazers::db::user::Guest as UserGuest;
66
use exports::stargazers::db::user::{Ordering, Stargazer};
77
use humantime::format_rfc3339_millis;
88
use turso::request::{NamedArg, PipelineAction, PipelineRequest, Stmt};
9-
use turso::response::{extract_first_value_from_nth_response, QueryResult, Response};
9+
use turso::response::{QueryResult, Response, extract_first_value_from_nth_response};
1010
use turso::{TursoClient, TursoValue};
1111
use wit_bindgen::generate;
1212

@@ -54,7 +54,9 @@ fn get_user_description_and_star_status(
5454
// Check if the user already starred the repo
5555
PipelineAction::Execute {
5656
stmt: Stmt {
57-
sql: format!("SELECT 1 FROM stars WHERE user_name = :{PARAM_LOGIN} AND repo_name = :{PARAM_REPO}"),
57+
sql: format!(
58+
"SELECT 1 FROM stars WHERE user_name = :{PARAM_LOGIN} AND repo_name = :{PARAM_REPO}"
59+
),
5860
named_args: vec![
5961
NamedArg {
6062
name: PARAM_LOGIN,
@@ -75,14 +77,12 @@ fn get_user_description_and_star_status(
7577
PipelineAction::Execute {
7678
stmt: Stmt {
7779
sql: format!("SELECT description FROM users WHERE name = :{PARAM_LOGIN}"),
78-
named_args: vec![
79-
NamedArg {
80-
name: PARAM_LOGIN,
81-
value: TursoValue::Text {
82-
value: login.to_string(),
83-
},
80+
named_args: vec![NamedArg {
81+
name: PARAM_LOGIN,
82+
value: TursoValue::Text {
83+
value: login.to_string(),
8484
},
85-
]
85+
}],
8686
},
8787
},
8888
PipelineAction::Close,
@@ -104,14 +104,14 @@ fn parse_user_description_and_star_status(
104104
}
105105
resp.pop().unwrap(); // Close
106106
let description = resp.pop().unwrap(); // Select user's description
107-
// Check if the user already starred the repo
107+
// Check if the user already starred the repo
108108
let already_starred = match extract_first_value_from_nth_response(resp, 0)? {
109109
TursoValue::Integer { .. } => true,
110110
TursoValue::Null => false,
111111
other => {
112112
return Err(format!(
113113
"unexpected data type, expected Integer or Null, got {other:?}"
114-
))
114+
));
115115
}
116116
};
117117
// Get the user's description
@@ -121,7 +121,7 @@ fn parse_user_description_and_star_status(
121121
other => {
122122
return Err(format!(
123123
"unexpected data type, expected Text or Null, got {other:?}"
124-
))
124+
));
125125
}
126126
};
127127
Ok((description, already_starred))
@@ -144,10 +144,12 @@ impl UserGuest for Component {
144144
// Add user: if the user already exists and did not have a star relation to the repo, update the `updated_at` field.
145145
PipelineAction::Execute {
146146
stmt: Stmt {
147-
sql: format!("INSERT INTO users (name, updated_at) VALUES
147+
sql: format!(
148+
"INSERT INTO users (name, updated_at) VALUES
148149
(:{PARAM_LOGIN}, :{PARAM_NOW}) \
149150
ON CONFLICT(name) DO UPDATE \
150-
SET updated_at = :{PARAM_NOW}"),
151+
SET updated_at = :{PARAM_NOW}"
152+
),
151153
named_args: vec![
152154
NamedArg {
153155
name: PARAM_LOGIN,
@@ -157,32 +159,32 @@ impl UserGuest for Component {
157159
},
158160
NamedArg {
159161
name: PARAM_NOW,
160-
value: TursoValue::Text {
161-
value: now.clone()
162-
}
163-
}
162+
value: TursoValue::Text { value: now.clone() },
163+
},
164164
],
165165
},
166166
},
167167
// Add repo if it does not exist.
168168
PipelineAction::Execute {
169169
stmt: Stmt {
170-
sql: format!("INSERT INTO repos (name) VALUES (:{PARAM_REPO}) ON CONFLICT DO NOTHING;"),
171-
named_args: vec![
172-
NamedArg {
173-
name: PARAM_REPO,
174-
value: TursoValue::Text {
175-
value: repo.clone(),
176-
},
170+
sql: format!(
171+
"INSERT INTO repos (name) VALUES (:{PARAM_REPO}) ON CONFLICT DO NOTHING;"
172+
),
173+
named_args: vec![NamedArg {
174+
name: PARAM_REPO,
175+
value: TursoValue::Text {
176+
value: repo.clone(),
177177
},
178-
],
178+
}],
179179
},
180180
},
181181
// Add the star relation
182182
PipelineAction::Execute {
183183
stmt: Stmt {
184-
sql: format!("INSERT INTO stars (user_name, repo_name) VALUES \
185-
(:{PARAM_LOGIN}, :{PARAM_REPO}) ON CONFLICT DO NOTHING;"),
184+
sql: format!(
185+
"INSERT INTO stars (user_name, repo_name) VALUES \
186+
(:{PARAM_LOGIN}, :{PARAM_REPO}) ON CONFLICT DO NOTHING;"
187+
),
186188
named_args: vec![
187189
NamedArg {
188190
name: PARAM_LOGIN,
@@ -196,7 +198,6 @@ impl UserGuest for Component {
196198
value: repo.clone(),
197199
},
198200
},
199-
200201
],
201202
},
202203
},
@@ -405,8 +406,8 @@ mod tests {
405406
exports::stargazers::db::user::Stargazer,
406407
process_resp_list_stargazers,
407408
turso::{
408-
response::{extract_first_value_from_nth_response, PipelineResponse},
409409
TursoValue,
410+
response::{PipelineResponse, extract_first_value_from_nth_response},
410411
},
411412
};
412413

@@ -676,30 +677,30 @@ mod tests {
676677

677678
mod integration {
678679
use crate::{
680+
Component, ENV_TURSO_LOCATION, ENV_TURSO_TOKEN,
679681
exports::stargazers::db::{
680682
llm::Guest as _,
681683
user::{Guest as _, Ordering, Stargazer},
682684
},
683685
turso::{
686+
TursoClient, TursoValue,
684687
request::{NamedArg, PipelineAction, PipelineRequest, Stmt},
685688
response::{QueryResult, Response},
686-
TursoClient, TursoValue,
687689
},
688-
Component, ENV_TURSO_LOCATION, ENV_TURSO_TOKEN,
689690
};
690691

691692
fn set_up() {
692693
let test_token =
693694
std::env::var(format!("TEST_{ENV_TURSO_TOKEN}")).unwrap_or_else(|_| {
694695
panic!("TEST_{ENV_TURSO_TOKEN} must be set as an environment variable")
695696
});
696-
std::env::set_var(ENV_TURSO_TOKEN, test_token);
697+
unsafe { std::env::set_var(ENV_TURSO_TOKEN, test_token) };
697698

698699
let test_location =
699700
std::env::var(format!("TEST_{ENV_TURSO_LOCATION}")).unwrap_or_else(|_| {
700701
panic!("TEST_{ENV_TURSO_LOCATION} must be set as an environment variable")
701702
});
702-
std::env::set_var(ENV_TURSO_LOCATION, test_location);
703+
unsafe { std::env::set_var(ENV_TURSO_LOCATION, test_location) };
703704
}
704705

705706
fn random_string() -> String {

activity/github/impl/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,16 @@ pub struct UserArguments {
148148

149149
#[cfg(test)]
150150
mod tests {
151-
use crate::exports::stargazers::github::account::Guest;
152151
use crate::Component;
153-
use crate::{extract_stargazers, stargazers::QueryStargazers, ENV_GITHUB_TOKEN};
152+
use crate::exports::stargazers::github::account::Guest;
153+
use crate::{ENV_GITHUB_TOKEN, extract_stargazers, stargazers::QueryStargazers};
154154
use cynic::GraphQlResponse;
155155

156156
fn set_up() {
157157
let test_token = std::env::var(format!("TEST_{ENV_GITHUB_TOKEN}")).unwrap_or_else(|_| {
158158
panic!("TEST_{ENV_GITHUB_TOKEN} must be set as an environment variable")
159159
});
160-
std::env::set_var(ENV_GITHUB_TOKEN, test_token);
160+
unsafe { std::env::set_var(ENV_GITHUB_TOKEN, test_token) };
161161
}
162162

163163
#[test]

activity/llm/openai/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@ impl Guest for Component {
9898

9999
#[cfg(test)]
100100
mod tests {
101-
use crate::exports::stargazers::llm::llm::Guest;
102101
use crate::Component;
103102
use crate::ENV_OPENAI_API_KEY;
103+
use crate::exports::stargazers::llm::llm::Guest;
104104
use crate::{Message, Role, Settings};
105105

106106
fn set_up() {
107107
let test_token = std::env::var(format!("TEST_{ENV_OPENAI_API_KEY}")).unwrap_or_else(|_| {
108108
panic!("TEST_{ENV_OPENAI_API_KEY} must be set as an environment variable")
109109
});
110-
std::env::set_var(ENV_OPENAI_API_KEY, test_token);
110+
unsafe { std::env::set_var(ENV_OPENAI_API_KEY, test_token) };
111111
}
112112

113113
#[test]

scripts/clippy.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
set -exuo pipefail
4+
cd "$(dirname "$0")/.."
5+
6+
cargo clippy --workspace --all-targets --fix --allow-dirty --allow-staged -- -D warnings
7+
8+
cargo fmt
9+
10+
git status -s

webhook/webhook-rs/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use stargazers::{
33
db::{self, user::Ordering},
44
workflow_obelisk_schedule::workflow::{star_added_schedule, star_removed_schedule},
55
};
6-
use waki::{handler, ErrorCode, Method, Request, Response};
6+
use waki::{ErrorCode, Method, Request, Response, handler};
77
use wit_bindgen::generate;
88

99
generate!({
@@ -61,8 +61,8 @@ fn handle_webhook(req: Request) -> Result<Response, ErrorCode> {
6161
Ok("true")
6262
) {
6363
println!(
64-
"WARN: Not verifying the request because {ENV_GITHUB_WEBHOOK_INSECURE} is set to `true`!"
65-
);
64+
"WARN: Not verifying the request because {ENV_GITHUB_WEBHOOK_INSECURE} is set to `true`!"
65+
);
6666
} else {
6767
let secret = std::env::var(ENV_GITHUB_WEBHOOK_SECRET).unwrap_or_else(|_| {
6868
panic!("{ENV_GITHUB_WEBHOOK_SECRET} must be passed as environment variable")

workflow/workflow-rs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::exports::stargazers::workflow::workflow::Guest;
22
use obelisk::{
33
types::execution::AwaitNextExtensionError,
4-
workflow::workflow_support::{new_join_set_named, ClosingStrategy},
4+
workflow::workflow_support::{ClosingStrategy, new_join_set_named},
55
};
66
use stargazers::{
77
db,

0 commit comments

Comments
 (0)