Skip to content

Commit 71f1ebd

Browse files
committed
style: format code and improve consistency across files
- Adjusted whitespace and formatting in various files for better readability. - Ensured consistent use of newlines and indentation in Rust source files. - Updated GitHub Actions workflow file for cleaner branch specification.
1 parent 58faacb commit 71f1ebd

13 files changed

Lines changed: 107 additions & 78 deletions

File tree

.github/workflows/rust.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ name: Rust
22

33
on:
44
push:
5-
branches: [ "master" ]
5+
branches: ["master"]
66
pull_request:
7-
branches: [ "master" ]
7+
branches: ["master"]
88

99
env:
1010
CARGO_TERM_COLOR: always
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
1615

1716
steps:
18-
- uses: actions/checkout@v4
19-
- name: Build
20-
run: cargo build --verbose
21-
- name: Run tests
22-
run: cargo test --verbose
17+
- uses: actions/checkout@v4
18+
- name: Build
19+
run: cargo build --verbose
20+
- name: Run tests
21+
run: cargo test --verbose

src/core/config.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use serde::{Deserialize, Serialize};
2-
use std::fs;
3-
use std::path::Path;
42
use std::error::Error;
3+
use std::fs;
54
use std::io::{self, Write};
5+
use std::path::Path;
66

77
const CONFIG_FILE: &str = "config.toml";
88

@@ -50,34 +50,36 @@ impl Config {
5050

5151
fn load_from_file() -> Result<Self, Box<dyn Error>> {
5252
let content = fs::read_to_string(CONFIG_FILE)?;
53-
53+
5454
// Try to parse the config, but handle missing fields gracefully
5555
match toml::from_str::<Config>(&content) {
5656
Ok(config) => Ok(config),
5757
Err(e) => {
5858
// If parsing fails due to missing fields, merge with defaults
5959
if e.to_string().contains("missing field") {
6060
println!("⚠️ Config file is missing new fields, updating...");
61-
61+
6262
// Parse as a generic value first
6363
let mut existing: toml::Value = toml::from_str(&content)?;
6464
let default_config = Self::default();
6565
let default_value = toml::Value::try_from(&default_config)?;
66-
66+
6767
// Merge missing fields from defaults
68-
if let (toml::Value::Table(existing_table), toml::Value::Table(default_table)) = (&mut existing, default_value) {
68+
if let (toml::Value::Table(existing_table), toml::Value::Table(default_table)) =
69+
(&mut existing, default_value)
70+
{
6971
for (key, value) in default_table {
7072
if !existing_table.contains_key(&key) {
7173
existing_table.insert(key, value);
7274
}
7375
}
7476
}
75-
77+
7678
// Convert back to Config and save the updated version
7779
let updated_config: Config = existing.try_into()?;
7880
let updated_content = toml::to_string_pretty(&updated_config)?;
7981
fs::write(CONFIG_FILE, &updated_content)?;
80-
82+
8183
println!("✅ Config file updated with new fields");
8284
Ok(updated_config)
8385
} else {
@@ -89,12 +91,12 @@ impl Config {
8991

9092
fn create_default_and_prompt() -> Result<Self, Box<dyn Error>> {
9193
println!("🔧 First time setup - Creating configuration file...");
92-
94+
9395
let default_config = Self::default();
9496
let toml_content = toml::to_string_pretty(&default_config)?;
95-
97+
9698
fs::write(CONFIG_FILE, &toml_content)?;
97-
99+
98100
println!("✅ Created '{}'", CONFIG_FILE);
99101
println!();
100102
println!("📝 Please edit the configuration file with your settings:");
@@ -105,22 +107,20 @@ impl Config {
105107
println!();
106108
print!("Press Enter when you've finished editing the config file...");
107109
io::stdout().flush()?;
108-
110+
109111
let mut input = String::new();
110112
io::stdin().read_line(&mut input)?;
111-
113+
112114
// Reload the config after user edits
113115
Self::load_from_file()
114116
}
115117

116118
pub fn rust_color(&self) -> u32 {
117119
// Parse hex color string to u32
118120
if self.appearance.embed_color.starts_with('#') {
119-
u32::from_str_radix(&self.appearance.embed_color[1..], 16)
120-
.unwrap_or(0xCD412B)
121+
u32::from_str_radix(&self.appearance.embed_color[1..], 16).unwrap_or(0xCD412B)
121122
} else {
122-
u32::from_str_radix(&self.appearance.embed_color, 16)
123-
.unwrap_or(0xCD412B)
123+
u32::from_str_radix(&self.appearance.embed_color, 16).unwrap_or(0xCD412B)
124124
}
125125
}
126126
}
@@ -147,4 +147,4 @@ impl Default for Config {
147147
},
148148
}
149149
}
150-
}
150+
}

src/core/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ pub mod config;
22
pub mod tracker;
33

44
pub use config::*;
5-
pub use tracker::*;
5+
pub use tracker::*;

src/core/tracker.rs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::core::Config;
2-
use crate::services::{CommitScraper, DiscordNotifier, Database};
3-
use log::{info, error, debug};
2+
use crate::services::{CommitScraper, Database, DiscordNotifier};
3+
use log::{debug, error, info};
44
use std::error::Error;
55
use std::time::Duration;
66
use tokio::time::sleep;
@@ -28,11 +28,17 @@ impl CommitTracker {
2828
}
2929

3030
pub async fn start(&mut self) -> Result<(), Box<dyn Error>> {
31-
info!("🚀 {} started - monitoring Facepunch commits", self.config.discord.bot_name);
31+
info!(
32+
"🚀 {} started - monitoring Facepunch commits",
33+
self.config.discord.bot_name
34+
);
3235

3336
// Get the last sent commit info from database
3437
if let Some((last_id, changeset)) = self.database.get_last_sent_commit_info().await? {
35-
info!("📊 Resuming from last sent commit ID: {} ({})", last_id, changeset);
38+
info!(
39+
"📊 Resuming from last sent commit ID: {} ({})",
40+
last_id, changeset
41+
);
3642
} else {
3743
info!("📊 No previous commits found in database - starting fresh");
3844
}
@@ -42,12 +48,18 @@ impl CommitTracker {
4248
error!("❌ {}", e);
4349
}
4450

45-
sleep(Duration::from_secs(self.config.monitoring.check_interval_secs)).await;
51+
sleep(Duration::from_secs(
52+
self.config.monitoring.check_interval_secs,
53+
))
54+
.await;
4655
}
4756
}
4857

4958
async fn check_for_new_commits(&mut self) -> Result<(), Box<dyn Error>> {
50-
let result = self.scraper.fetch_latest_commit(&self.config.monitoring.commits_url).await?;
59+
let result = self
60+
.scraper
61+
.fetch_latest_commit(&self.config.monitoring.commits_url)
62+
.await?;
5163
let commit = &result.commit;
5264

5365
// Check if we've already sent this commit
@@ -56,28 +68,37 @@ impl CommitTracker {
5668
return Ok(());
5769
}
5870

59-
info!("🆕 New commit #{} by {} - {}", commit.id, commit.author(), commit.message);
60-
71+
info!(
72+
"🆕 New commit #{} by {} - {}",
73+
commit.id,
74+
commit.author(),
75+
commit.message
76+
);
77+
6178
// Send notification
6279
self.notifier.send_commit_notification(&result).await?;
63-
80+
6481
// Mark as sent in database
65-
self.database.mark_commit_sent(
66-
commit.id,
67-
&commit.author(),
68-
&commit.message,
69-
&commit.branch,
70-
&commit.changeset,
71-
).await?;
72-
82+
self.database
83+
.mark_commit_sent(
84+
commit.id,
85+
&commit.author(),
86+
&commit.message,
87+
&commit.branch,
88+
&commit.changeset,
89+
)
90+
.await?;
91+
7392
info!("✅ Sent to Discord and marked as sent");
7493

7594
// Periodic cleanup to prevent database from growing too large
7695
let sent_count = self.database.get_sent_commits_count().await?;
7796
if sent_count > self.config.database.cleanup_keep_last + 100 {
78-
self.database.cleanup_old_commits(self.config.database.cleanup_keep_last).await?;
97+
self.database
98+
.cleanup_old_commits(self.config.database.cleanup_keep_last)
99+
.await?;
79100
}
80101

81102
Ok(())
82103
}
83-
}
104+
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ pub mod services;
44

55
pub use core::*;
66
pub use models::*;
7-
pub use services::{CommitScraper, DiscordNotifier};
7+
pub use services::{CommitScraper, DiscordNotifier};

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use rust_commit_tracker::CommitTracker;
21
use log::error;
2+
use rust_commit_tracker::CommitTracker;
33

44
#[tokio::main]
55
async fn main() {
@@ -16,7 +16,7 @@ async fn main() {
1616
return;
1717
}
1818
};
19-
19+
2020
if let Err(e) = tracker.start().await {
2121
error!("❌ Fatal error: {}", e);
2222
}

src/models/commit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ impl CommitInfo {
3131
pub fn link(&self) -> String {
3232
format!("https://commits.facepunch.com/{}", self.id)
3333
}
34-
34+
3535
pub fn avatar_url(&self) -> &str {
3636
&self.user.avatar
3737
}
38-
38+
3939
pub fn author(&self) -> &str {
4040
&self.user.name
4141
}
42-
}
42+
}

src/models/discord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ pub struct EmbedField {
3434
pub struct EmbedFooter {
3535
pub text: String,
3636
pub icon_url: String,
37-
}
37+
}

src/models/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ pub mod commit;
22
pub mod discord;
33

44
pub use commit::*;
5-
pub use discord::*;
5+
pub use discord::*;

src/services/database.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use sqlx::{SqlitePool, Row};
1+
use log::{debug, info};
2+
use sqlx::{Row, SqlitePool};
23
use std::error::Error;
3-
use log::{info, debug};
44

55
pub struct Database {
66
pool: SqlitePool,
@@ -16,12 +16,12 @@ impl Database {
1616
std::fs::File::create(file_path)?;
1717
}
1818
}
19-
19+
2020
let pool = SqlitePool::connect(database_url).await?;
21-
21+
2222
let db = Self { pool };
2323
db.initialize().await?;
24-
24+
2525
Ok(db)
2626
}
2727

@@ -93,9 +93,11 @@ impl Database {
9393
}
9494

9595
pub async fn get_last_sent_commit_info(&self) -> Result<Option<(i32, String)>, Box<dyn Error>> {
96-
let row = sqlx::query("SELECT commit_id, changeset FROM sent_commits ORDER BY commit_id DESC LIMIT 1")
97-
.fetch_optional(&self.pool)
98-
.await?;
96+
let row = sqlx::query(
97+
"SELECT commit_id, changeset FROM sent_commits ORDER BY commit_id DESC LIMIT 1",
98+
)
99+
.fetch_optional(&self.pool)
100+
.await?;
99101

100102
if let Some(row) = row {
101103
let commit_id: i32 = row.get("commit_id");
@@ -134,4 +136,4 @@ impl Database {
134136
info!("Cleaned up old commits, keeping last {}", keep_last);
135137
Ok(())
136138
}
137-
}
139+
}

0 commit comments

Comments
 (0)