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