| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | use serde::Deserialize; |
| 16 | use topcoat::{ |
| 17 | Result, |
| 18 | context::Cx, |
| 19 | router::{StatusCode, content::Form, error::not_found, page, query_params}, |
| 20 | view::{attributes, component, view}, |
| 21 | }; |
| 22 | |
| 23 | use crate::{ |
| 24 | application::{ |
| 25 | Error, RepoView, Stores, list_branches, |
| 26 | repo::{ |
| 27 | RepoEdit, delete_repo, rename_repo, set_default_branch, set_repo_archived, update_repo, |
| 28 | }, |
| 29 | }, |
| 30 | components::{ |
| 31 | button::{ButtonVariant, button}, |
| 32 | flash::{FlashKind, flash}, |
| 33 | input::input, |
| 34 | label::label, |
| 35 | select::select, |
| 36 | textarea::textarea, |
| 37 | }, |
| 38 | domain::{BranchRow, DomainError, RepoName, Repository, Visibility}, |
| 39 | }; |
| 40 | |
| 41 | use super::{ |
| 42 | context::{ |
| 43 | current_actor, location, memberships, orgs, owned_repo, queries, repos, server_error, |
| 44 | storage, |
| 45 | }, |
| 46 | csrf::{csrf_field, csrf_verified}, |
| 47 | format::optional, |
| 48 | layout::narrow, |
| 49 | }; |
| 50 | |
| 51 | #[derive(Debug, Deserialize)] |
| 52 | struct SettingsForm { |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | #[serde(default)] |
| 59 | csrf_token: String, |
| 60 | description: String, |
| 61 | visibility: String, |
| 62 | |
| 63 | |
| 64 | pinned: Option<String>, |
| 65 | } |
| 66 | |
| 67 | |
| 68 | |
| 69 | #[derive(Debug, Deserialize)] |
| 70 | struct ArchiveForm { |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | #[serde(default)] |
| 77 | csrf_token: String, |
| 78 | archived: String, |
| 79 | } |
| 80 | |
| 81 | #[derive(Debug, Deserialize)] |
| 82 | struct DefaultBranchForm { |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | #[serde(default)] |
| 89 | csrf_token: String, |
| 90 | branch: String, |
| 91 | } |
| 92 | |
| 93 | #[derive(Debug, Deserialize)] |
| 94 | struct RenameForm { |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | #[serde(default)] |
| 101 | csrf_token: String, |
| 102 | name: String, |
| 103 | } |
| 104 | |
| 105 | #[derive(Debug, Deserialize)] |
| 106 | struct DeleteForm { |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | #[serde(default)] |
| 113 | csrf_token: String, |
| 114 | confirm: String, |
| 115 | } |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | #[query_params(error = bad_request)] |
| 121 | struct Saved { |
| 122 | saved: Option<String>, |
| 123 | } |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | async fn branches_of(cx: &Cx, repo: &RepoView) -> Result<Vec<BranchRow>> { |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | if repo.import.is_some() { |
| 140 | return Ok(Vec::new()); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | |
| 145 | Ok(list_branches( |
| 146 | &repo.handle, |
| 147 | &repo.name, |
| 148 | None, |
| 149 | ¤t_actor(cx).await?, |
| 150 | &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)), |
| 151 | &queries(cx), |
| 152 | ) |
| 153 | .await |
| 154 | .map_err(server_error)? |
| 155 | .map(|page| page.rows.items) |
| 156 | .unwrap_or_default()) |
| 157 | } |
| 158 | |
| 159 | #[page("/{handle}/repos/{name}/settings")] |
| 160 | async fn repo_settings_page(cx: &Cx) -> Result { |
| 161 | let repo = owned_repo(cx).await?; |
| 162 | let saved = query_params::<Saved>(cx)?.saved.is_some(); |
| 163 | let branches = branches_of(cx, &repo).await?; |
| 164 | |
| 165 | view! { |
| 166 | settings_view( |
| 167 | handle: repo.handle.as_str(), |
| 168 | name: repo.name.as_str(), |
| 169 | fields: Fields { |
| 170 | description: repo.description.as_deref().unwrap_or(""), |
| 171 | visibility: repo.visibility, |
| 172 | pinned: repo.pinned, |
| 173 | rename_to: repo.name.as_str(), |
| 174 | archived: repo.archived, |
| 175 | importing: repo.import.is_some(), |
| 176 | }, |
| 177 | branches: &branches, |
| 178 | saved: saved, |
| 179 | error: "", |
| 180 | ) |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | #[page(POST "/{handle}/repos/{name}/settings")] |
| 193 | async fn save(cx: &Cx, Form(submitted): Form<SettingsForm>) -> Result { |
| 194 | csrf_verified(cx, &submitted.csrf_token).await?; |
| 195 | |
| 196 | let repo = owned_repo(cx).await?; |
| 197 | |
| 198 | |
| 199 | |
| 200 | let visibility = submitted |
| 201 | .visibility |
| 202 | .parse::<Visibility>() |
| 203 | .map_err(|_| topcoat::router::error::bad_request("unknown visibility"))?; |
| 204 | |
| 205 | let outcome = update_repo( |
| 206 | ¤t_actor(cx).await?, |
| 207 | &repo.handle, |
| 208 | &repo.name, |
| 209 | &RepoEdit { |
| 210 | description: optional(&submitted.description), |
| 211 | visibility, |
| 212 | pinned: submitted.pinned.is_some(), |
| 213 | }, |
| 214 | &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)), |
| 215 | ) |
| 216 | .await; |
| 217 | |
| 218 | let message = match outcome { |
| 219 | Ok(_) => { |
| 220 | return view! { |
| 221 | (StatusCode::SEE_OTHER) |
| 222 | (location(&format!( |
| 223 | "/{}/repos/{}/settings?saved", |
| 224 | repo.handle, repo.name |
| 225 | ))?) |
| 226 | }; |
| 227 | } |
| 228 | |
| 229 | Err(Error::Domain(DomainError::Validation { field, reason })) => { |
| 230 | format!("That {field} is no good: {reason}.") |
| 231 | } |
| 232 | |
| 233 | Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => { |
| 234 | return Err(not_found().into()); |
| 235 | } |
| 236 | |
| 237 | Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))), |
| 238 | }; |
| 239 | |
| 240 | let branches = branches_of(cx, &repo).await?; |
| 241 | |
| 242 | view! { |
| 243 | settings_view( |
| 244 | handle: repo.handle.as_str(), |
| 245 | name: repo.name.as_str(), |
| 246 | fields: Fields { |
| 247 | description: submitted.description.as_str(), |
| 248 | visibility, |
| 249 | pinned: submitted.pinned.is_some(), |
| 250 | rename_to: repo.name.as_str(), |
| 251 | archived: repo.archived, |
| 252 | importing: repo.import.is_some(), |
| 253 | }, |
| 254 | branches: &branches, |
| 255 | saved: false, |
| 256 | error: message.as_str(), |
| 257 | ) |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | #[page(POST "/{handle}/repos/{name}/settings/archive")] |
| 266 | async fn archive(cx: &Cx, Form(submitted): Form<ArchiveForm>) -> Result { |
| 267 | csrf_verified(cx, &submitted.csrf_token).await?; |
| 268 | |
| 269 | let repo = owned_repo(cx).await?; |
| 270 | |
| 271 | |
| 272 | |
| 273 | let archived = match submitted.archived.as_str() { |
| 274 | "true" => true, |
| 275 | "false" => false, |
| 276 | _ => return Err(topcoat::router::error::bad_request("unknown archive state").into()), |
| 277 | }; |
| 278 | |
| 279 | let message = match set_repo_archived( |
| 280 | ¤t_actor(cx).await?, |
| 281 | &repo.handle, |
| 282 | &repo.name, |
| 283 | archived, |
| 284 | &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)), |
| 285 | ) |
| 286 | .await |
| 287 | { |
| 288 | Ok(_) => { |
| 289 | return view! { |
| 290 | (StatusCode::SEE_OTHER) |
| 291 | (location(&format!( |
| 292 | "/{}/repos/{}/settings?saved", |
| 293 | repo.handle, repo.name |
| 294 | ))?) |
| 295 | }; |
| 296 | } |
| 297 | Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => { |
| 298 | return Err(not_found().into()); |
| 299 | } |
| 300 | |
| 301 | |
| 302 | Err(Error::Domain(DomainError::Unavailable { reason, .. })) => { |
| 303 | format!("Nothing was changed — {reason}") |
| 304 | } |
| 305 | Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))), |
| 306 | }; |
| 307 | |
| 308 | let branches = branches_of(cx, &repo).await?; |
| 309 | |
| 310 | view! { |
| 311 | settings_view( |
| 312 | handle: repo.handle.as_str(), |
| 313 | name: repo.name.as_str(), |
| 314 | fields: Fields { |
| 315 | description: repo.description.as_deref().unwrap_or(""), |
| 316 | visibility: repo.visibility, |
| 317 | pinned: repo.pinned, |
| 318 | rename_to: repo.name.as_str(), |
| 319 | archived: repo.archived, |
| 320 | importing: repo.import.is_some(), |
| 321 | }, |
| 322 | branches: &branches, |
| 323 | saved: false, |
| 324 | error: message.as_str(), |
| 325 | ) |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | #[page(POST "/{handle}/repos/{name}/settings/default-branch")] |
| 335 | async fn default_branch(cx: &Cx, Form(submitted): Form<DefaultBranchForm>) -> Result { |
| 336 | csrf_verified(cx, &submitted.csrf_token).await?; |
| 337 | |
| 338 | let repo = owned_repo(cx).await?; |
| 339 | |
| 340 | let outcome = set_default_branch( |
| 341 | ¤t_actor(cx).await?, |
| 342 | &repo.handle, |
| 343 | &repo.name, |
| 344 | &submitted.branch, |
| 345 | &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)), |
| 346 | &queries(cx), |
| 347 | &storage(cx), |
| 348 | ) |
| 349 | .await; |
| 350 | |
| 351 | let message = match outcome { |
| 352 | Ok(_) => { |
| 353 | return view! { |
| 354 | (StatusCode::SEE_OTHER) |
| 355 | (location(&format!( |
| 356 | "/{}/repos/{}/settings?saved", |
| 357 | repo.handle, repo.name |
| 358 | ))?) |
| 359 | }; |
| 360 | } |
| 361 | |
| 362 | |
| 363 | Err(Error::Domain(DomainError::NotFound { entity: "branch" })) => format!( |
| 364 | "{} is not a branch of this repository any more. Nothing changed.", |
| 365 | submitted.branch.trim() |
| 366 | ), |
| 367 | Err(Error::Domain(DomainError::Validation { field, reason })) => { |
| 368 | format!("That {field} is no good: {reason}.") |
| 369 | } |
| 370 | Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => { |
| 371 | return Err(not_found().into()); |
| 372 | } |
| 373 | Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))), |
| 374 | }; |
| 375 | |
| 376 | let branches = branches_of(cx, &repo).await?; |
| 377 | |
| 378 | view! { |
| 379 | settings_view( |
| 380 | handle: repo.handle.as_str(), |
| 381 | name: repo.name.as_str(), |
| 382 | fields: Fields { |
| 383 | description: repo.description.as_deref().unwrap_or(""), |
| 384 | visibility: repo.visibility, |
| 385 | pinned: repo.pinned, |
| 386 | rename_to: repo.name.as_str(), |
| 387 | archived: repo.archived, |
| 388 | importing: repo.import.is_some(), |
| 389 | }, |
| 390 | branches: &branches, |
| 391 | saved: false, |
| 392 | error: message.as_str(), |
| 393 | ) |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | #[page(POST "/{handle}/repos/{name}/settings/rename")] |
| 403 | async fn rename(cx: &Cx, Form(submitted): Form<RenameForm>) -> Result { |
| 404 | csrf_verified(cx, &submitted.csrf_token).await?; |
| 405 | |
| 406 | let repo = owned_repo(cx).await?; |
| 407 | |
| 408 | let outcome = rename_repo( |
| 409 | ¤t_actor(cx).await?, |
| 410 | &repo.handle, |
| 411 | &repo.name, |
| 412 | &submitted.name, |
| 413 | &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)), |
| 414 | &storage(cx), |
| 415 | ) |
| 416 | .await; |
| 417 | |
| 418 | let message = match outcome { |
| 419 | |
| 420 | |
| 421 | Ok(renamed) => { |
| 422 | return view! { |
| 423 | (StatusCode::SEE_OTHER) |
| 424 | (location(&format!( |
| 425 | "/{}/repos/{}/settings?saved", |
| 426 | repo.handle, renamed.name |
| 427 | ))?) |
| 428 | }; |
| 429 | } |
| 430 | Err(Error::Domain(DomainError::Validation { field, reason })) => { |
| 431 | format!("That {field} is no good: {reason}.") |
| 432 | } |
| 433 | Err(Error::Domain(DomainError::AlreadyExists { .. })) => { |
| 434 | format!( |
| 435 | "You already have a repository called {}. Nothing was renamed.", |
| 436 | submitted.name.trim() |
| 437 | ) |
| 438 | } |
| 439 | |
| 440 | |
| 441 | Err(Error::Domain(DomainError::Unavailable { reason, .. })) => { |
| 442 | format!("Nothing was renamed — {reason}") |
| 443 | } |
| 444 | Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => { |
| 445 | return Err(not_found().into()); |
| 446 | } |
| 447 | Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))), |
| 448 | }; |
| 449 | |
| 450 | let branches = branches_of(cx, &repo).await?; |
| 451 | |
| 452 | view! { |
| 453 | settings_view( |
| 454 | handle: repo.handle.as_str(), |
| 455 | name: repo.name.as_str(), |
| 456 | fields: Fields { |
| 457 | description: repo.description.as_deref().unwrap_or(""), |
| 458 | visibility: repo.visibility, |
| 459 | pinned: repo.pinned, |
| 460 | rename_to: submitted.name.as_str(), |
| 461 | archived: repo.archived, |
| 462 | importing: repo.import.is_some(), |
| 463 | }, |
| 464 | branches: &branches, |
| 465 | saved: false, |
| 466 | error: message.as_str(), |
| 467 | ) |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | #[page(POST "/{handle}/repos/{name}/settings/delete")] |
| 481 | async fn delete(cx: &Cx, Form(submitted): Form<DeleteForm>) -> Result { |
| 482 | csrf_verified(cx, &submitted.csrf_token).await?; |
| 483 | |
| 484 | let repo = owned_repo(cx).await?; |
| 485 | |
| 486 | let confirmed = RepoName::new(&submitted.confirm).is_ok_and(|typed| typed == repo.name); |
| 487 | |
| 488 | if !confirmed { |
| 489 | let message = format!( |
| 490 | "Type {} exactly to confirm. Nothing was deleted.", |
| 491 | repo.name |
| 492 | ); |
| 493 | |
| 494 | let branches = branches_of(cx, &repo).await?; |
| 495 | |
| 496 | return view! { |
| 497 | settings_view( |
| 498 | handle: repo.handle.as_str(), |
| 499 | name: repo.name.as_str(), |
| 500 | fields: Fields { |
| 501 | description: repo.description.as_deref().unwrap_or(""), |
| 502 | visibility: repo.visibility, |
| 503 | pinned: repo.pinned, |
| 504 | rename_to: repo.name.as_str(), |
| 505 | archived: repo.archived, |
| 506 | importing: repo.import.is_some(), |
| 507 | }, |
| 508 | branches: &branches, |
| 509 | saved: false, |
| 510 | error: message.as_str(), |
| 511 | ) |
| 512 | }; |
| 513 | } |
| 514 | |
| 515 | match delete_repo( |
| 516 | ¤t_actor(cx).await?, |
| 517 | &repo.handle, |
| 518 | &repo.name, |
| 519 | &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)), |
| 520 | &storage(cx), |
| 521 | ) |
| 522 | .await |
| 523 | { |
| 524 | Ok(()) => {} |
| 525 | Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => { |
| 526 | return Err(not_found().into()); |
| 527 | } |
| 528 | Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))), |
| 529 | } |
| 530 | |
| 531 | view! { |
| 532 | (StatusCode::SEE_OTHER) |
| 533 | (location(&format!("/{}", repo.handle))?) |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | |
| 538 | |
| 539 | #[derive(Debug, Clone, Copy)] |
| 540 | struct Fields<'a> { |
| 541 | description: &'a str, |
| 542 | visibility: Visibility, |
| 543 | pinned: bool, |
| 544 | |
| 545 | |
| 546 | rename_to: &'a str, |
| 547 | |
| 548 | |
| 549 | archived: bool, |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | importing: bool, |
| 558 | } |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | #[component] |
| 565 | async fn settings_view( |
| 566 | handle: &str, |
| 567 | name: &str, |
| 568 | fields: Fields<'_>, |
| 569 | |
| 570 | branches: &[BranchRow], |
| 571 | saved: bool, |
| 572 | error: &str, |
| 573 | ) -> Result { |
| 574 | let Fields { |
| 575 | description, |
| 576 | visibility, |
| 577 | pinned, |
| 578 | rename_to, |
| 579 | archived, |
| 580 | importing, |
| 581 | } = fields; |
| 582 | |
| 583 | view! { |
| 584 | narrow( |
| 585 | <h1 class="text-xl font-semibold tracking-tight">"Repository settings"</h1> |
| 586 | <p class="mt-1 font-mono text-sm text-muted-foreground"> |
| 587 | "@" (handle) " / " (name) |
| 588 | </p> |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | <nav class="mt-4 flex items-center gap-4 border-b border-border pb-2 text-sm"> |
| 594 | <span class="border-b-2 border-primary -mb-2.5 pb-2">"General"</span> |
| 595 | <a |
| 596 | href=(format!("/{handle}/repos/{name}/settings/hooks")) |
| 597 | class="text-muted-foreground hover:text-foreground" |
| 598 | >"Webhooks"</a> |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | <a |
| 604 | href=(format!("/{handle}/repos/{name}/labels")) |
| 605 | class="text-muted-foreground hover:text-foreground" |
| 606 | >"Labels"</a> |
| 607 | </nav> |
| 608 | |
| 609 | if saved { |
| 610 | <div class="mt-6"> |
| 611 | flash(kind: FlashKind::Success, "Repository updated.") |
| 612 | </div> |
| 613 | } |
| 614 | |
| 615 | |
| 616 | |
| 617 | if importing { |
| 618 | <div class="mt-6"> |
| 619 | flash( |
| 620 | kind: FlashKind::Info, |
| 621 | "This repository is still being imported. Its name and its archived \ |
| 622 | state cannot change until the import finishes." |
| 623 | ) |
| 624 | </div> |
| 625 | } |
| 626 | |
| 627 | if !error.is_empty() { |
| 628 | <div class="mt-6"> |
| 629 | flash(kind: FlashKind::Error, (error)) |
| 630 | </div> |
| 631 | } |
| 632 | |
| 633 | <form |
| 634 | method="post" |
| 635 | action=(format!("/{handle}/repos/{name}/settings")) |
| 636 | class="mt-6 space-y-5" |
| 637 | > |
| 638 | csrf_field() |
| 639 | <div class="space-y-2"> |
| 640 | label(attrs: attributes! { for="description" }, "Description") |
| 641 | textarea( |
| 642 | attrs: attributes! { |
| 643 | id="description" |
| 644 | name="description" |
| 645 | rows="2" |
| 646 | maxlength=(Repository::MAX_DESCRIPTION_LEN.to_string()) |
| 647 | placeholder="A sentence for your profile." |
| 648 | }, |
| 649 | (description) |
| 650 | ) |
| 651 | <p class="text-xs text-muted-foreground"> |
| 652 | "Optional. At most " |
| 653 | (Repository::MAX_DESCRIPTION_LEN.to_string()) " characters." |
| 654 | </p> |
| 655 | </div> |
| 656 | |
| 657 | <div class="space-y-2"> |
| 658 | label(attrs: attributes! { for="visibility" }, "Visibility") |
| 659 | select( |
| 660 | attrs: attributes! { id="visibility" name="visibility" }, |
| 661 | <option value="public" selected=(visibility.is_public())>"Public"</option> |
| 662 | <option value="private" selected=(!visibility.is_public())>"Private"</option> |
| 663 | ) |
| 664 | <p class="text-xs text-muted-foreground"> |
| 665 | "A private repository is hidden from your profile and needs a token " |
| 666 | "to clone." |
| 667 | </p> |
| 668 | </div> |
| 669 | |
| 670 | <div class="space-y-2"> |
| 671 | <div class="flex items-start gap-2"> |
| 672 | <input |
| 673 | id="pinned" |
| 674 | name="pinned" |
| 675 | type="checkbox" |
| 676 | value="on" |
| 677 | checked=(pinned) |
| 678 | class="mt-0.5" |
| 679 | /> |
| 680 | label(attrs: attributes! { for="pinned" }, "Lead my profile with this") |
| 681 | </div> |
| 682 | <p class="text-xs text-muted-foreground"> |
| 683 | "One repository at a time. Choosing this one lets go of whichever " |
| 684 | "was chosen before." |
| 685 | </p> |
| 686 | </div> |
| 687 | |
| 688 | <div class="flex items-center gap-3"> |
| 689 | button(attrs: attributes! { type="submit" }, "Save") |
| 690 | <a |
| 691 | href=(format!("/{handle}/repos/{name}")) |
| 692 | class="text-sm text-muted-foreground hover:text-foreground" |
| 693 | >"Back to repository"</a> |
| 694 | </div> |
| 695 | </form> |
| 696 | |
| 697 | <section class="mt-8 border-t border-border pt-6"> |
| 698 | <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground"> |
| 699 | "Default branch" |
| 700 | </h2> |
| 701 | |
| 702 | if importing { |
| 703 | // Not "nothing has been pushed yet", which is a different fact and |
| 704 | // would read as an empty repository. The mirror brings `HEAD` with |
| 705 | // it, so there is nothing to choose here anyway. |
| 706 | <p class="mt-2 text-sm text-muted-foreground"> |
| 707 | "The import brings the source's default branch with it. Once it " |
| 708 | "has landed you can point "<code class="font-mono">"HEAD"</code> |
| 709 | " somewhere else." |
| 710 | </p> |
| 711 | } else if branches.is_empty() { |
| 712 | <p class="mt-2 text-sm text-muted-foreground"> |
| 713 | "Nothing has been pushed yet, so there is no branch to choose. " |
| 714 | "The first branch you push becomes the default." |
| 715 | </p> |
| 716 | } else { |
| 717 | <form |
| 718 | method="post" |
| 719 | action=(format!("/{handle}/repos/{name}/settings/default-branch")) |
| 720 | class="mt-3 flex flex-wrap items-center gap-3" |
| 721 | > |
| 722 | csrf_field() |
| 723 | select( |
| 724 | attrs: attributes! { |
| 725 | id="branch" |
| 726 | name="branch" |
| 727 | class="font-mono sm:w-64" |
| 728 | aria-label="Default branch" |
| 729 | }, |
| 730 | for branch in branches { |
| 731 | <option |
| 732 | value=(branch.name.as_str()) |
| 733 | selected=(branch.is_default) |
| 734 | >(branch.name.as_str())</option> |
| 735 | } |
| 736 | ) |
| 737 | button( |
| 738 | attrs: attributes! { type="submit" }, |
| 739 | variant: ButtonVariant::Outline, |
| 740 | "Update" |
| 741 | ) |
| 742 | </form> |
| 743 | <p class="mt-2 text-xs text-muted-foreground"> |
| 744 | "What the repository opens at, and what a fresh clone checks out. " |
| 745 | "Stored in git as "<code class="font-mono">"HEAD"</code>", not in Steid." |
| 746 | </p> |
| 747 | } |
| 748 | </section> |
| 749 | |
| 750 | <section class="mt-8 border-t border-border pt-6"> |
| 751 | <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground"> |
| 752 | if archived { "Archived" } else { "Archive this repository" } |
| 753 | </h2> |
| 754 | <p class="mt-2 text-sm text-muted-foreground"> |
| 755 | if archived { |
| 756 | "Pushes are refused. Everything that reads still works — browsing, " |
| 757 | "cloning, search and downloads." |
| 758 | } else { |
| 759 | "Marks it finished. Pushes are refused with a message; browsing, " |
| 760 | "cloning, search and downloads carry on unchanged. Reversible." |
| 761 | } |
| 762 | </p> |
| 763 | |
| 764 | <form |
| 765 | method="post" |
| 766 | action=(format!("/{handle}/repos/{name}/settings/archive")) |
| 767 | class="mt-3" |
| 768 | > |
| 769 | csrf_field() |
| 770 | <input |
| 771 | type="hidden" |
| 772 | name="archived" |
| 773 | value=(if archived { "false" } else { "true" }) |
| 774 | /> |
| 775 | button( |
| 776 | attrs: attributes! { type="submit" disabled=(importing) }, |
| 777 | variant: ButtonVariant::Outline, |
| 778 | if archived { "Unarchive repository" } else { "Archive repository" } |
| 779 | ) |
| 780 | </form> |
| 781 | </section> |
| 782 | |
| 783 | <section class="mt-10 rounded-lg border border-border p-4"> |
| 784 | <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground"> |
| 785 | "Rename this repository" |
| 786 | </h2> |
| 787 | <p class="mt-2 text-sm text-muted-foreground"> |
| 788 | "The old URL stops working straight away — nothing redirects from it. " |
| 789 | "Existing clones must update their remote with " |
| 790 | <code class="font-mono text-xs">"git remote set-url origin …"</code>"." |
| 791 | </p> |
| 792 | |
| 793 | <form |
| 794 | method="post" |
| 795 | action=(format!("/{handle}/repos/{name}/settings/rename")) |
| 796 | class="mt-4 space-y-2" |
| 797 | > |
| 798 | csrf_field() |
| 799 | label(attrs: attributes! { for="rename" }, "New name") |
| 800 | input(attrs: attributes! { |
| 801 | id="rename" |
| 802 | name="name" |
| 803 | type="text" |
| 804 | value=(rename_to) |
| 805 | maxlength=(RepoName::MAX_LEN.to_string()) |
| 806 | required=(true) |
| 807 | autocomplete="off" |
| 808 | class="font-mono" |
| 809 | }) |
| 810 | <div class="pt-1"> |
| 811 | button( |
| 812 | attrs: attributes! { type="submit" disabled=(importing) }, |
| 813 | variant: ButtonVariant::Outline, |
| 814 | "Rename repository" |
| 815 | ) |
| 816 | </div> |
| 817 | </form> |
| 818 | </section> |
| 819 | |
| 820 | <section class="mt-10 rounded-lg border border-destructive/30 p-4"> |
| 821 | <h2 class="text-xs font-medium uppercase tracking-wider text-destructive"> |
| 822 | "Delete this repository" |
| 823 | </h2> |
| 824 | <p class="mt-2 text-sm text-muted-foreground"> |
| 825 | "This cannot be undone. The commits, branches and tags go with it, and " |
| 826 | "anyone with a clone keeps their copy while this instance keeps nothing." |
| 827 | </p> |
| 828 | |
| 829 | <form |
| 830 | method="post" |
| 831 | action=(format!("/{handle}/repos/{name}/settings/delete")) |
| 832 | class="mt-4 space-y-2" |
| 833 | > |
| 834 | csrf_field() |
| 835 | label( |
| 836 | attrs: attributes! { for="confirm" }, |
| 837 | "Type " (name) " to confirm" |
| 838 | ) |
| 839 | input(attrs: attributes! { |
| 840 | id="confirm" |
| 841 | name="confirm" |
| 842 | type="text" |
| 843 | value="" |
| 844 | placeholder=(name) |
| 845 | required=(true) |
| 846 | autocomplete="off" |
| 847 | }) |
| 848 | <div class="pt-1"> |
| 849 | button( |
| 850 | attrs: attributes! { type="submit" }, |
| 851 | variant: ButtonVariant::Destructive, |
| 852 | "Delete repository" |
| 853 | ) |
| 854 | </div> |
| 855 | </form> |
| 856 | </section> |
| 857 | ) |
| 858 | } |
| 859 | } |