| 1 |
|
| 2 |
|
| 3 |
use super::{now_ms, Pool}; |
| 4 |
use hub_api::Visibility; |
| 5 |
use sqlx::FromRow; |
| 6 |
|
| 7 |
#[derive(Clone, Debug, Default, FromRow)] |
| 8 |
pub struct RepoRow { |
| 9 |
pub id: i64, |
| 10 |
pub owner: String, |
| 11 |
pub name: String, |
| 12 |
pub description: String, |
| 13 |
pub default_bookmark: String, |
| 14 |
pub visibility: String, |
| 15 |
pub created_ms: i64, |
| 16 |
pub updated_ms: i64, |
| 17 |
#[sqlx(default)] |
| 18 |
pub git_mirror: bool, |
| 19 |
#[sqlx(default)] |
| 20 |
pub git_mirror_state: String, |
| 21 |
|
| 22 |
#[sqlx(default)] |
| 23 |
pub forked_from: Option<i64>, |
| 24 |
|
| 25 |
#[sqlx(default)] |
| 26 |
pub topics: String, |
| 27 |
|
| 28 |
#[sqlx(default)] |
| 29 |
pub flow: String, |
| 30 |
|
| 31 |
|
| 32 |
#[sqlx(default)] |
| 33 |
pub flow_priority: String, |
| 34 |
|
| 35 |
|
| 36 |
#[sqlx(default)] |
| 37 |
pub diffusion: String, |
| 38 |
|
| 39 |
|
| 40 |
#[sqlx(default)] |
| 41 |
pub diffusion_land: String, |
| 42 |
|
| 43 |
|
| 44 |
#[sqlx(default)] |
| 45 |
pub backup: String, |
| 46 |
|
| 47 |
#[sqlx(default)] |
| 48 |
pub archived: bool, |
| 49 |
#[sqlx(default)] |
| 50 |
pub archived_reason: String, |
| 51 |
|
| 52 |
#[sqlx(default)] |
| 53 |
pub agents_decide_gates: bool, |
| 54 |
|
| 55 |
|
| 56 |
#[sqlx(default)] |
| 57 |
pub flow_keep_running: bool, |
| 58 |
|
| 59 |
|
| 60 |
#[sqlx(default)] |
| 61 |
pub push_protection: bool, |
| 62 |
|
| 63 |
|
| 64 |
#[sqlx(default)] |
| 65 |
pub kind: String, |
| 66 |
|
| 67 |
#[sqlx(default)] |
| 68 |
pub title: String, |
| 69 |
|
| 70 |
#[sqlx(default)] |
| 71 |
pub open_issues: i64, |
| 72 |
#[sqlx(default)] |
| 73 |
pub open_proposals: i64, |
| 74 |
} |
| 75 |
|
| 76 |
impl RepoRow { |
| 77 |
pub fn visibility(&self) -> Visibility { |
| 78 |
Visibility::parse(&self.visibility).unwrap_or(Visibility::Private) |
| 79 |
} |
| 80 |
|
| 81 |
pub fn topic_list(&self) -> Vec<&str> { |
| 82 |
self.topics.split_whitespace().collect() |
| 83 |
} |
| 84 |
|
| 85 |
pub fn slug(&self) -> String { |
| 86 |
format!("{}/{}", self.owner, self.name) |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
pub fn is_drop(&self) -> bool { |
| 91 |
self.kind == DROP |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
pub const DROP: &str = "drop"; |
| 97 |
|
| 98 |
#[derive(Clone, Debug, FromRow)] |
| 99 |
pub struct PushRow { |
| 100 |
pub id: i64, |
| 101 |
pub at_ms: i64, |
| 102 |
pub reference: String, |
| 103 |
pub ok: bool, |
| 104 |
pub reason: String, |
| 105 |
pub old_state: String, |
| 106 |
pub new_state: String, |
| 107 |
pub heads: i64, |
| 108 |
pub changes: i64, |
| 109 |
pub pusher: String, |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
#[derive(Clone, Debug)] |
| 114 |
pub struct PushOutcome { |
| 115 |
pub reference: String, |
| 116 |
pub ok: bool, |
| 117 |
pub reason: String, |
| 118 |
pub old_state: String, |
| 119 |
pub new_state: String, |
| 120 |
pub heads: i64, |
| 121 |
pub changes: i64, |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
pub async fn list(pool: &Pool) -> sqlx::Result<Vec<RepoRow>> { |
| 127 |
sqlx::query_as("SELECT * FROM repositories WHERE kind = 'repo' ORDER BY updated_ms DESC, owner, name").fetch_all(pool).await |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
pub async fn list_with_drops(pool: &Pool) -> sqlx::Result<Vec<RepoRow>> { |
| 134 |
sqlx::query_as("SELECT * FROM repositories ORDER BY updated_ms DESC, owner, name").fetch_all(pool).await |
| 135 |
} |
| 136 |
|
| 137 |
pub async fn get_by_id(pool: &Pool, id: i64) -> sqlx::Result<Option<RepoRow>> { |
| 138 |
sqlx::query_as("SELECT * FROM repositories WHERE id = $1").bind(id).fetch_optional(pool).await |
| 139 |
} |
| 140 |
|
| 141 |
pub async fn list_by_owner(pool: &Pool, owner: &str) -> sqlx::Result<Vec<RepoRow>> { |
| 142 |
sqlx::query_as("SELECT * FROM repositories WHERE owner = $1 AND kind = 'repo' ORDER BY updated_ms DESC, name") |
| 143 |
.bind(owner) |
| 144 |
.fetch_all(pool) |
| 145 |
.await |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
pub async fn create_drop( |
| 154 |
pool: &Pool, |
| 155 |
owner: &str, |
| 156 |
id: &str, |
| 157 |
title: &str, |
| 158 |
description: &str, |
| 159 |
visibility: Visibility, |
| 160 |
) -> sqlx::Result<RepoRow> { |
| 161 |
let now = now_ms(); |
| 162 |
sqlx::query_as( |
| 163 |
"INSERT INTO repositories (owner, name, description, visibility, created_ms, updated_ms, kind, title, flow) \ |
| 164 |
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'off') RETURNING *", |
| 165 |
) |
| 166 |
.bind(owner) |
| 167 |
.bind(format!("{}/{id}", crate::repos::names::DROPS)) |
| 168 |
.bind(description) |
| 169 |
.bind(visibility.as_str()) |
| 170 |
.bind(now) |
| 171 |
.bind(now) |
| 172 |
.bind(DROP) |
| 173 |
.bind(title) |
| 174 |
.fetch_one(pool) |
| 175 |
.await |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
pub async fn drops_of(pool: &Pool, owner: &str) -> sqlx::Result<Vec<RepoRow>> { |
| 180 |
sqlx::query_as("SELECT * FROM repositories WHERE kind = 'drop' AND owner = $1 ORDER BY updated_ms DESC, id DESC") |
| 181 |
.bind(owner) |
| 182 |
.fetch_all(pool) |
| 183 |
.await |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
pub async fn drop_by_id(pool: &Pool, id: &str) -> sqlx::Result<Option<RepoRow>> { |
| 189 |
sqlx::query_as("SELECT * FROM repositories WHERE kind = 'drop' AND name = $1") |
| 190 |
.bind(format!("{}/{id}", crate::repos::names::DROPS)) |
| 191 |
.fetch_optional(pool) |
| 192 |
.await |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
pub async fn set_drop(pool: &Pool, row_id: i64, title: &str, description: &str, visibility: Visibility) -> sqlx::Result<()> { |
| 197 |
sqlx::query("UPDATE repositories SET title = $1, description = $2, visibility = $3, updated_ms = $4 WHERE id = $5 AND kind = 'drop'") |
| 198 |
.bind(title) |
| 199 |
.bind(description) |
| 200 |
.bind(visibility.as_str()) |
| 201 |
.bind(now_ms()) |
| 202 |
.bind(row_id) |
| 203 |
.execute(pool) |
| 204 |
.await?; |
| 205 |
Ok(()) |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
pub async fn get(pool: &Pool, owner: &str, name: &str) -> sqlx::Result<Option<RepoRow>> { |
| 210 |
sqlx::query_as( |
| 211 |
"SELECT r.*, \ |
| 212 |
(SELECT COUNT(*) FROM issues i WHERE i.repo_id = r.id AND i.state = 'open') AS open_issues, \ |
| 213 |
(SELECT COUNT(*) FROM proposals p WHERE p.repo_id = r.id AND p.state IN ('open', 'draft')) AS open_proposals \ |
| 214 |
FROM repositories r WHERE r.owner = $1 AND r.name = $2", |
| 215 |
) |
| 216 |
.bind(owner) |
| 217 |
.bind(name) |
| 218 |
.fetch_optional(pool) |
| 219 |
.await |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
pub async fn create(pool: &Pool, owner: &str, name: &str, description: &str, visibility: Visibility) -> sqlx::Result<RepoRow> { |
| 226 |
let now = now_ms(); |
| 227 |
sqlx::query_as( |
| 228 |
"INSERT INTO repositories (owner, name, description, visibility, created_ms, updated_ms, required_approvals) \ |
| 229 |
VALUES ($1, $2, $3, $4, $5, $6, (SELECT CASE WHEN COUNT(*) >= 2 THEN 1 ELSE 0 END FROM org_members m JOIN organisations o ON o.id = m.org_id WHERE o.name = $7)) RETURNING *", |
| 230 |
) |
| 231 |
.bind(owner) |
| 232 |
.bind(name) |
| 233 |
.bind(description) |
| 234 |
.bind(visibility.as_str()) |
| 235 |
.bind(now) |
| 236 |
.bind(now) |
| 237 |
.bind(owner) |
| 238 |
.fetch_one(pool) |
| 239 |
.await |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
pub async fn moved_to(pool: &Pool, owner: &str, name: &str) -> sqlx::Result<Option<RepoRow>> { |
| 244 |
let id: Option<i64> = sqlx::query_scalar("SELECT repo_id FROM repo_redirects WHERE old_owner = $1 AND old_name = $2") |
| 245 |
.bind(owner) |
| 246 |
.bind(name) |
| 247 |
.fetch_optional(pool) |
| 248 |
.await?; |
| 249 |
match id { |
| 250 |
Some(id) => get_by_id(pool, id).await, |
| 251 |
None => Ok(None), |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
pub async fn transfer(pool: &Pool, id: i64, old_owner: &str, name: &str, new_owner: &str) -> sqlx::Result<()> { |
| 259 |
sqlx::query("UPDATE repositories SET owner = $1, updated_ms = $2 WHERE id = $3") |
| 260 |
.bind(new_owner) |
| 261 |
.bind(now_ms()) |
| 262 |
.bind(id) |
| 263 |
.execute(pool) |
| 264 |
.await?; |
| 265 |
sqlx::query("DELETE FROM repo_redirects WHERE old_owner = $1 AND old_name = $2").bind(new_owner).bind(name).execute(pool).await?; |
| 266 |
sqlx::query("INSERT INTO repo_redirects (old_owner, old_name, repo_id, moved_ms) VALUES ($1, $2, $3, $4) ON CONFLICT (old_owner, old_name) DO UPDATE SET repo_id = excluded.repo_id, moved_ms = excluded.moved_ms") |
| 267 |
.bind(old_owner) |
| 268 |
.bind(name) |
| 269 |
.bind(id) |
| 270 |
.bind(now_ms()) |
| 271 |
.execute(pool) |
| 272 |
.await?; |
| 273 |
Ok(()) |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
pub async fn set_archived(pool: &Pool, id: i64, archived: bool, reason: &str) -> sqlx::Result<()> { |
| 278 |
sqlx::query("UPDATE repositories SET archived = $1, archived_reason = $2, updated_ms = $3 WHERE id = $4") |
| 279 |
.bind(archived) |
| 280 |
.bind(if archived { reason } else { "" }) |
| 281 |
.bind(now_ms()) |
| 282 |
.bind(id) |
| 283 |
.execute(pool) |
| 284 |
.await?; |
| 285 |
Ok(()) |
| 286 |
} |
| 287 |
|
| 288 |
pub async fn delete(pool: &Pool, id: i64) -> sqlx::Result<()> { |
| 289 |
sqlx::query("DELETE FROM repositories WHERE id = $1").bind(id).execute(pool).await?; |
| 290 |
Ok(()) |
| 291 |
} |
| 292 |
|
| 293 |
pub async fn set_description(pool: &Pool, id: i64, description: &str) -> sqlx::Result<()> { |
| 294 |
sqlx::query("UPDATE repositories SET description = $1 WHERE id = $2").bind(description).bind(id).execute(pool).await?; |
| 295 |
Ok(()) |
| 296 |
} |
| 297 |
|
| 298 |
pub async fn set_default_bookmark(pool: &Pool, id: i64, bookmark: &str) -> sqlx::Result<()> { |
| 299 |
sqlx::query("UPDATE repositories SET default_bookmark = $1 WHERE id = $2").bind(bookmark).bind(id).execute(pool).await?; |
| 300 |
Ok(()) |
| 301 |
} |
| 302 |
|
| 303 |
pub async fn set_visibility(pool: &Pool, id: i64, visibility: Visibility) -> sqlx::Result<()> { |
| 304 |
sqlx::query("UPDATE repositories SET visibility = $1 WHERE id = $2").bind(visibility.as_str()).bind(id).execute(pool).await?; |
| 305 |
Ok(()) |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
pub async fn record_push(pool: &Pool, id: i64, pusher: Option<(i64, &str)>, results: &[PushOutcome]) -> sqlx::Result<()> { |
| 310 |
record_push_via(pool, id, pusher, "", results).await |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
pub async fn record_push_via(pool: &Pool, id: i64, pusher: Option<(i64, &str)>, via: &str, results: &[PushOutcome]) -> sqlx::Result<()> { |
| 315 |
let now = now_ms(); |
| 316 |
let mut tx = super::begin_write(pool).await?; |
| 317 |
for r in results { |
| 318 |
sqlx::query("INSERT INTO pushes (repo_id, at_ms, reference, ok, reason, old_state, new_state, heads, changes, account_id, pusher, via) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)") |
| 319 |
.bind(id) |
| 320 |
.bind(now) |
| 321 |
.bind(&r.reference) |
| 322 |
.bind(r.ok) |
| 323 |
.bind(&r.reason) |
| 324 |
.bind(&r.old_state) |
| 325 |
.bind(&r.new_state) |
| 326 |
.bind(r.heads) |
| 327 |
.bind(r.changes) |
| 328 |
.bind(pusher.map(|p| p.0).filter(|id| *id > 0)) |
| 329 |
.bind(pusher.map(|p| p.1).unwrap_or("")) |
| 330 |
.bind(via) |
| 331 |
.execute(&mut *tx) |
| 332 |
.await?; |
| 333 |
} |
| 334 |
if results.iter().any(|r| r.ok) { |
| 335 |
sqlx::query("UPDATE repositories SET updated_ms = $1 WHERE id = $2").bind(now).bind(id).execute(&mut *tx).await?; |
| 336 |
} |
| 337 |
tx.commit().await |
| 338 |
} |
| 339 |
|
| 340 |
pub async fn pushes(pool: &Pool, id: i64, limit: i64) -> sqlx::Result<Vec<PushRow>> { |
| 341 |
sqlx::query_as("SELECT id, at_ms, reference, ok, reason, old_state, new_state, heads, changes, pusher FROM pushes WHERE repo_id = $1 ORDER BY at_ms DESC, id DESC LIMIT $2") |
| 342 |
.bind(id) |
| 343 |
.bind(limit) |
| 344 |
.fetch_all(pool) |
| 345 |
.await |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
pub fn parse_topics(input: &str) -> Result<String, String> { |
| 352 |
let mut out: Vec<String> = Vec::new(); |
| 353 |
for t in input.split([',', ' ', '\n', '\t']).map(|t| t.trim().to_ascii_lowercase()).filter(|t| !t.is_empty()) { |
| 354 |
if t.len() > 35 || !t.chars().all(|c| c.is_ascii_alphanumeric() || c == '-') || t.starts_with('-') { |
| 355 |
return Err(format!("\"{t}\" is not a topic: use letters, digits and dashes, up to 35 characters")); |
| 356 |
} |
| 357 |
if !out.contains(&t) { |
| 358 |
out.push(t); |
| 359 |
} |
| 360 |
} |
| 361 |
if out.len() > 20 { |
| 362 |
return Err("At most 20 topics.".into()); |
| 363 |
} |
| 364 |
Ok(out.join(" ")) |
| 365 |
} |
| 366 |
|
| 367 |
pub async fn set_topics(pool: &Pool, id: i64, topics: &str) -> sqlx::Result<()> { |
| 368 |
sqlx::query("UPDATE repositories SET topics = $1 WHERE id = $2").bind(topics).bind(id).execute(pool).await?; |
| 369 |
Ok(()) |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
pub async fn toggle_star(pool: &Pool, account_id: i64, repo_id: i64) -> sqlx::Result<bool> { |
| 374 |
let gone = sqlx::query("DELETE FROM stars WHERE account_id = $1 AND repo_id = $2").bind(account_id).bind(repo_id).execute(pool).await?; |
| 375 |
if gone.rows_affected() > 0 { |
| 376 |
return Ok(false); |
| 377 |
} |
| 378 |
sqlx::query("INSERT INTO stars (account_id, repo_id, at_ms) VALUES ($1, $2, $3)") |
| 379 |
.bind(account_id) |
| 380 |
.bind(repo_id) |
| 381 |
.bind(now_ms()) |
| 382 |
.execute(pool) |
| 383 |
.await?; |
| 384 |
Ok(true) |
| 385 |
} |
| 386 |
|
| 387 |
pub async fn starred(pool: &Pool, account_id: i64, repo_id: i64) -> sqlx::Result<bool> { |
| 388 |
let n: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM stars WHERE account_id = $1 AND repo_id = $2") |
| 389 |
.bind(account_id) |
| 390 |
.bind(repo_id) |
| 391 |
.fetch_one(pool) |
| 392 |
.await?; |
| 393 |
Ok(n > 0) |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
pub async fn counts(pool: &Pool, repo_id: i64) -> sqlx::Result<(i64, i64)> { |
| 398 |
let stars: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM stars WHERE repo_id = $1").bind(repo_id).fetch_one(pool).await?; |
| 399 |
let watchers = super::notify::watchers(pool, repo_id).await?.len() as i64; |
| 400 |
Ok((stars, watchers)) |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
pub async fn star_counts(pool: &Pool) -> sqlx::Result<std::collections::HashMap<i64, i64>> { |
| 405 |
let rows: Vec<(i64, i64)> = sqlx::query_as("SELECT repo_id, COUNT(*) FROM stars GROUP BY repo_id").fetch_all(pool).await?; |
| 406 |
Ok(rows.into_iter().collect()) |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
pub async fn set_forked_from(pool: &Pool, id: i64, from: i64) -> sqlx::Result<()> { |
| 411 |
sqlx::query("UPDATE repositories SET forked_from = $1 WHERE id = $2").bind(from).bind(id).execute(pool).await?; |
| 412 |
Ok(()) |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
pub async fn forks_of(pool: &Pool, id: i64) -> sqlx::Result<Vec<RepoRow>> { |
| 417 |
sqlx::query_as("SELECT * FROM repositories WHERE forked_from = $1 AND kind = 'repo' ORDER BY updated_ms DESC") |
| 418 |
.bind(id) |
| 419 |
.fetch_all(pool) |
| 420 |
.await |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
pub async fn set_flow(pool: &Pool, id: i64, setting: &str) -> sqlx::Result<()> { |
| 425 |
sqlx::query("UPDATE repositories SET flow = $1 WHERE id = $2").bind(setting).bind(id).execute(pool).await?; |
| 426 |
Ok(()) |
| 427 |
} |
| 428 |
|
| 429 |
pub async fn set_flow_priority(pool: &Pool, id: i64, priority: &str) -> sqlx::Result<()> { |
| 430 |
sqlx::query("UPDATE repositories SET flow_priority = $1 WHERE id = $2").bind(priority).bind(id).execute(pool).await?; |
| 431 |
Ok(()) |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
pub async fn set_agents_decide_gates(pool: &Pool, id: i64, on: bool) -> sqlx::Result<()> { |
| 436 |
sqlx::query("UPDATE repositories SET agents_decide_gates = $1 WHERE id = $2").bind(on).bind(id).execute(pool).await?; |
| 437 |
Ok(()) |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
pub async fn set_flow_keep_running(pool: &Pool, id: i64, on: bool) -> sqlx::Result<()> { |
| 443 |
sqlx::query("UPDATE repositories SET flow_keep_running = $1 WHERE id = $2").bind(on).bind(id).execute(pool).await?; |
| 444 |
Ok(()) |
| 445 |
} |
| 446 |
|
| 447 |
pub async fn set_backup(pool: &Pool, id: i64, setting: &str) -> sqlx::Result<()> { |
| 448 |
sqlx::query("UPDATE repositories SET backup = $1 WHERE id = $2").bind(setting).bind(id).execute(pool).await?; |
| 449 |
Ok(()) |
| 450 |
} |
| 451 |
|
| 452 |
pub async fn set_diffusion_land(pool: &Pool, id: i64, setting: &str) -> sqlx::Result<()> { |
| 453 |
sqlx::query("UPDATE repositories SET diffusion_land = $1 WHERE id = $2").bind(setting).bind(id).execute(pool).await?; |
| 454 |
Ok(()) |
| 455 |
} |
| 456 |
|
| 457 |
pub async fn set_diffusion(pool: &Pool, id: i64, setting: &str) -> sqlx::Result<()> { |
| 458 |
sqlx::query("UPDATE repositories SET diffusion = $1 WHERE id = $2").bind(setting).bind(id).execute(pool).await?; |
| 459 |
Ok(()) |
| 460 |
} |
| 461 |
|
| 462 |
pub async fn set_git_mirror(pool: &Pool, id: i64, on: bool) -> sqlx::Result<()> { |
| 463 |
sqlx::query("UPDATE repositories SET git_mirror = $1 WHERE id = $2").bind(on).bind(id).execute(pool).await?; |
| 464 |
Ok(()) |
| 465 |
} |
| 466 |
|
| 467 |
pub async fn set_git_mirror_state(pool: &Pool, id: i64, state: &str) -> sqlx::Result<()> { |
| 468 |
sqlx::query("UPDATE repositories SET git_mirror_state = $1 WHERE id = $2").bind(state).bind(id).execute(pool).await?; |
| 469 |
Ok(()) |
| 470 |
} |
| 471 |
|
| 472 |
#[cfg(test)] |
| 473 |
mod topic_tests { |
| 474 |
use super::parse_topics; |
| 475 |
|
| 476 |
#[test] |
| 477 |
fn topics_are_normalised_and_checked() { |
| 478 |
assert_eq!(parse_topics("Rust, vcs retro-computing,rust").unwrap(), "rust vcs retro-computing"); |
| 479 |
assert_eq!(parse_topics("").unwrap(), ""); |
| 480 |
assert!(parse_topics("c++").is_err()); |
| 481 |
assert!(parse_topics("-lead").is_err()); |
| 482 |
assert!(parse_topics(&"x".repeat(36)).is_err()); |
| 483 |
assert!(parse_topics(&(0..21).map(|i| format!("t{i}")).collect::<Vec<_>>().join(" ")).is_err()); |
| 484 |
} |
| 485 |
} |