steid

@jamesgill /

steid/src/infrastructure/web/repo_settings.rs
Rust30.3 KBCode·Blame·History·Raw
1//! Repository settings — `/{handle}/repos/{name}/settings`.
2//!
3//! Owner-only: change the description, change visibility, choose the default branch,
4//! archive, rename, delete.
5//!
6//! `settings` sits in the verb position after `{name}`, where nothing user-controlled
7//! ever appears, so unlike `new` it needs no reservation in
8//! [`RepoName`](crate::domain::RepoName).
9//!
10//! **A non-owner gets a 404, not a 403.** That is the rule
11//! [`view_repo`](crate::application::view_repo) already sets for repositories: a 403
12//! would confirm that a private repository by that name exists, and there is no reason
13//! for the settings page to be more talkative than the repository page it belongs to.
14
15use serde::Deserialize;
16use topcoat::{
17 Result,
18 context::Cx,
19 router::{StatusCode, content::Form, error::not_found, page, query_params},
20 view::{attributes, component, view},
21};
22
23use 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
41use 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)]
48struct SettingsForm {
49 description: String,
50 visibility: String,
51 /// A checkbox: present when ticked, absent entirely when not. `Option` is the shape
52 /// the browser actually sends, so it is the shape parsed.
53 pinned: Option<String>,
54}
55
56/// Which way the archive button is pointing. A hidden field rather than two routes,
57/// so the form that renders the button also states what it does.
58#[derive(Debug, Deserialize)]
59struct ArchiveForm {
60 archived: String,
61}
62
63#[derive(Debug, Deserialize)]
64struct DefaultBranchForm {
65 branch: String,
66}
67
68#[derive(Debug, Deserialize)]
69struct RenameForm {
70 name: String,
71}
72
73#[derive(Debug, Deserialize)]
74struct DeleteForm {
75 confirm: String,
76}
77
78/// Set after a successful save so the confirmation survives the redirect.
79///
80/// Post-redirect-get: reloading after a save must not resubmit it.
81#[query_params(error = bad_request)]
82struct Saved {
83 saved: Option<String>,
84}
85
86/// Blank input means "clear this field", which the domain treats as unset.
87fn optional(value: &str) -> Option<String> {
88 Some(value.trim().to_owned()).filter(|value| !value.is_empty())
89}
90
91/// Resolves the repository in the path, or 404 for anyone who does not own it.
92///
93/// [`repo_for`] already 404s for a repository the viewer may not see; this adds the
94/// stronger half. The use cases decide this too — the guard here only keeps a page from
95/// rendering for someone whose submission would be refused anyway.
96async 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/// The repository's branches, for the default-branch control.
107///
108/// **One `git` process** — two on an empty repository, which is the case that spends
109/// the least elsewhere. The rows already say which branch `HEAD` names, so nothing has
110/// to ask `symbolic-ref` as well.
111///
112/// An empty list means an empty repository, and the control is left out rather than
113/// rendered with nothing in it.
114async fn branches_of(cx: &Cx, repo: &RepoView) -> Result<Vec<BranchRow>> {
115 // **Before git is asked.** A repository being imported has a directory
116 // `git clone --mirror` is still writing into, or none at all, and `for-each-ref`
117 // against one that is not there is a failed process rather than an empty list — the
118 // settings page would 500 on exactly the repository whose settings someone is
119 // checking. The view says so instead.
120 if repo.import.is_some() {
121 return Ok(Vec::new());
122 }
123
124 Ok(list_branches(
125 &repo.handle,
126 &repo.name,
127 &current_actor(cx).await?,
128 &orgs(cx),
129 &memberships(cx),
130 &repos(cx),
131 &queries(cx),
132 )
133 .await
134 .map_err(server_error)?
135 .map(|page| page.rows)
136 .unwrap_or_default())
137}
138
139#[page("/{handle}/repos/{name}/settings")]
140async fn repo_settings_page(cx: &Cx) -> Result {
141 let repo = owned_repo(cx).await?;
142 let saved = query_params::<Saved>(cx)?.saved.is_some();
143 let branches = branches_of(cx, &repo).await?;
144
145 view! {
146 settings_view(
147 handle: repo.handle.as_str(),
148 name: repo.name.as_str(),
149 fields: Fields {
150 description: repo.description.as_deref().unwrap_or(""),
151 visibility: repo.visibility,
152 pinned: repo.pinned,
153 rename_to: repo.name.as_str(),
154 archived: repo.archived,
155 importing: repo.import.is_some(),
156 },
157 branches: &branches,
158 saved: saved,
159 error: "",
160 )
161 }
162}
163
164/// Saves the description and visibility.
165///
166/// Success replies 303 so a reload cannot resubmit — see
167/// [`location`](super::context::location) for why it is spelled this way rather than
168/// with `redirect()`, which is a 307 and would re-POST this form to itself.
169///
170/// Failure re-renders with the reason and **what was typed**, rather than bouncing back
171/// to the stored values and hiding what went wrong.
172#[page(POST "/{handle}/repos/{name}/settings")]
173async fn save(cx: &Cx, Form(submitted): Form<SettingsForm>) -> Result {
174 let repo = owned_repo(cx).await?;
175
176 // An unparseable value is a tampered form, not something to default: defaulting
177 // here could publish a repository the owner asked to keep private.
178 let visibility = submitted
179 .visibility
180 .parse::<Visibility>()
181 .map_err(|_| topcoat::router::error::bad_request("unknown visibility"))?;
182
183 let outcome = update_repo(
184 &current_actor(cx).await?,
185 &repo.handle,
186 &repo.name,
187 &RepoEdit {
188 description: optional(&submitted.description),
189 visibility,
190 pinned: submitted.pinned.is_some(),
191 },
192 &orgs(cx),
193 &memberships(cx),
194 &repos(cx),
195 )
196 .await;
197
198 let message = match outcome {
199 Ok(_) => {
200 return view! {
201 (StatusCode::SEE_OTHER)
202 (location(&format!(
203 "/{}/repos/{}/settings?saved",
204 repo.handle, repo.name
205 ))?)
206 };
207 }
208 // The visitor's to fix, so it is shown.
209 Err(Error::Domain(DomainError::Validation { field, reason })) => {
210 format!("That {field} is no good: {reason}.")
211 }
212 // Both mean "not yours" here, and both look like a page that is not there.
213 Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => {
214 return Err(not_found().into());
215 }
216 // Ours, so it is logged and answered generically.
217 Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))),
218 };
219
220 let branches = branches_of(cx, &repo).await?;
221
222 view! {
223 settings_view(
224 handle: repo.handle.as_str(),
225 name: repo.name.as_str(),
226 fields: Fields {
227 description: submitted.description.as_str(),
228 visibility,
229 pinned: submitted.pinned.is_some(),
230 rename_to: repo.name.as_str(),
231 archived: repo.archived,
232 importing: repo.import.is_some(),
233 },
234 branches: &branches,
235 saved: false,
236 error: message.as_str(),
237 )
238 }
239}
240
241/// Archives or unarchives the repository.
242///
243/// Both directions through one route, because they are one state with two values and
244/// splitting them would put the rule in the router rather than in the use case.
245#[page(POST "/{handle}/repos/{name}/settings/archive")]
246async fn archive(cx: &Cx, Form(submitted): Form<ArchiveForm>) -> Result {
247 let repo = owned_repo(cx).await?;
248
249 // An unparseable value is a tampered form, not something to default: defaulting
250 // here could reopen a repository its owner closed.
251 let archived = match submitted.archived.as_str() {
252 "true" => true,
253 "false" => false,
254 _ => return Err(topcoat::router::error::bad_request("unknown archive state").into()),
255 };
256
257 let message = match set_repo_archived(
258 &current_actor(cx).await?,
259 &repo.handle,
260 &repo.name,
261 archived,
262 &orgs(cx),
263 &memberships(cx),
264 &repos(cx),
265 )
266 .await
267 {
268 Ok(_) => {
269 return view! {
270 (StatusCode::SEE_OTHER)
271 (location(&format!(
272 "/{}/repos/{}/settings?saved",
273 repo.handle, repo.name
274 ))?)
275 };
276 }
277 Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => {
278 return Err(not_found().into());
279 }
280 // Reached by a form replayed after the import started — the page renders the
281 // button disabled — so it re-renders with the reason rather than 500ing.
282 Err(Error::Domain(DomainError::Unavailable { reason, .. })) => {
283 format!("Nothing was changed — {reason}")
284 }
285 Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))),
286 };
287
288 let branches = branches_of(cx, &repo).await?;
289
290 view! {
291 settings_view(
292 handle: repo.handle.as_str(),
293 name: repo.name.as_str(),
294 fields: Fields {
295 description: repo.description.as_deref().unwrap_or(""),
296 visibility: repo.visibility,
297 pinned: repo.pinned,
298 rename_to: repo.name.as_str(),
299 archived: repo.archived,
300 importing: repo.import.is_some(),
301 },
302 branches: &branches,
303 saved: false,
304 error: message.as_str(),
305 )
306 }
307}
308
309/// Points `HEAD` at the chosen branch.
310///
311/// No column is written — see
312/// [`set_default_branch`](crate::application::repo::set_default_branch). The landing
313/// page follows `HEAD` on the next request.
314#[page(POST "/{handle}/repos/{name}/settings/default-branch")]
315async fn default_branch(cx: &Cx, Form(submitted): Form<DefaultBranchForm>) -> Result {
316 let repo = owned_repo(cx).await?;
317
318 let outcome = set_default_branch(
319 &current_actor(cx).await?,
320 &repo.handle,
321 &repo.name,
322 &submitted.branch,
323 &orgs(cx),
324 &memberships(cx),
325 &repos(cx),
326 &queries(cx),
327 &storage(cx),
328 )
329 .await;
330
331 let message = match outcome {
332 Ok(_) => {
333 return view! {
334 (StatusCode::SEE_OTHER)
335 (location(&format!(
336 "/{}/repos/{}/settings?saved",
337 repo.handle, repo.name
338 ))?)
339 };
340 }
341 // A branch that is gone is the one failure a visitor can act on: the select was
342 // rendered from a list that has since changed under them.
343 Err(Error::Domain(DomainError::NotFound { entity: "branch" })) => format!(
344 "{} is not a branch of this repository any more. Nothing changed.",
345 submitted.branch.trim()
346 ),
347 Err(Error::Domain(DomainError::Validation { field, reason })) => {
348 format!("That {field} is no good: {reason}.")
349 }
350 Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => {
351 return Err(not_found().into());
352 }
353 Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))),
354 };
355
356 let branches = branches_of(cx, &repo).await?;
357
358 view! {
359 settings_view(
360 handle: repo.handle.as_str(),
361 name: repo.name.as_str(),
362 fields: Fields {
363 description: repo.description.as_deref().unwrap_or(""),
364 visibility: repo.visibility,
365 pinned: repo.pinned,
366 rename_to: repo.name.as_str(),
367 archived: repo.archived,
368 importing: repo.import.is_some(),
369 },
370 branches: &branches,
371 saved: false,
372 error: message.as_str(),
373 )
374 }
375}
376
377/// Renames the repository, then sends the owner to the new settings URL.
378///
379/// The old URL is gone rather than redirected — see
380/// [`rename_repo`](crate::application::repo::rename_repo) — so the 303 has to name the
381/// new one or the owner lands on their own 404.
382#[page(POST "/{handle}/repos/{name}/settings/rename")]
383async fn rename(cx: &Cx, Form(submitted): Form<RenameForm>) -> Result {
384 let repo = owned_repo(cx).await?;
385
386 let outcome = rename_repo(
387 &current_actor(cx).await?,
388 &repo.handle,
389 &repo.name,
390 &submitted.name,
391 &orgs(cx),
392 &memberships(cx),
393 &repos(cx),
394 &storage(cx),
395 )
396 .await;
397
398 let message = match outcome {
399 // The **returned** name, not what was typed: it normalised on the way in, and
400 // sending someone to `/MyForge/settings` would 404 on their own repository.
401 Ok(renamed) => {
402 return view! {
403 (StatusCode::SEE_OTHER)
404 (location(&format!(
405 "/{}/repos/{}/settings?saved",
406 repo.handle, renamed.name
407 ))?)
408 };
409 }
410 Err(Error::Domain(DomainError::Validation { field, reason })) => {
411 format!("That {field} is no good: {reason}.")
412 }
413 Err(Error::Domain(DomainError::AlreadyExists { .. })) => {
414 format!(
415 "You already have a repository called {}. Nothing was renamed.",
416 submitted.name.trim()
417 )
418 }
419 // The import owns the directory this would move. Transient, so it says when to
420 // come back rather than what went wrong.
421 Err(Error::Domain(DomainError::Unavailable { reason, .. })) => {
422 format!("Nothing was renamed — {reason}")
423 }
424 Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => {
425 return Err(not_found().into());
426 }
427 Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))),
428 };
429
430 let branches = branches_of(cx, &repo).await?;
431
432 view! {
433 settings_view(
434 handle: repo.handle.as_str(),
435 name: repo.name.as_str(),
436 fields: Fields {
437 description: repo.description.as_deref().unwrap_or(""),
438 visibility: repo.visibility,
439 pinned: repo.pinned,
440 rename_to: submitted.name.as_str(),
441 archived: repo.archived,
442 importing: repo.import.is_some(),
443 },
444 branches: &branches,
445 saved: false,
446 error: message.as_str(),
447 )
448 }
449}
450
451/// Deletes the repository, then sends the owner back to their profile.
452///
453/// The repository page no longer exists, so there is nowhere else to go.
454///
455/// **Guarded by typing the name.** Deletion takes the git history with it and there is
456/// no undo; a single button is too easy to hit by accident for something unrecoverable.
457/// The typed value goes through [`RepoName::new`], so it is compared the same way the
458/// name was normalised on the way in — `MyRepo` confirms `myrepo`, and stray whitespace
459/// is not a reason to refuse.
460#[page(POST "/{handle}/repos/{name}/settings/delete")]
461async fn delete(cx: &Cx, Form(submitted): Form<DeleteForm>) -> Result {
462 let repo = owned_repo(cx).await?;
463
464 let confirmed = RepoName::new(&submitted.confirm).is_ok_and(|typed| typed == repo.name);
465
466 if !confirmed {
467 let message = format!(
468 "Type {} exactly to confirm. Nothing was deleted.",
469 repo.name
470 );
471
472 let branches = branches_of(cx, &repo).await?;
473
474 return view! {
475 settings_view(
476 handle: repo.handle.as_str(),
477 name: repo.name.as_str(),
478 fields: Fields {
479 description: repo.description.as_deref().unwrap_or(""),
480 visibility: repo.visibility,
481 pinned: repo.pinned,
482 rename_to: repo.name.as_str(),
483 archived: repo.archived,
484 importing: repo.import.is_some(),
485 },
486 branches: &branches,
487 saved: false,
488 error: message.as_str(),
489 )
490 };
491 }
492
493 match delete_repo(
494 &current_actor(cx).await?,
495 &repo.handle,
496 &repo.name,
497 &orgs(cx),
498 &memberships(cx),
499 &repos(cx),
500 &storage(cx),
501 )
502 .await
503 {
504 Ok(()) => {}
505 Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => {
506 return Err(not_found().into());
507 }
508 Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))),
509 }
510
511 view! {
512 (StatusCode::SEE_OTHER)
513 (location(&format!("/{}", repo.handle))?)
514 }
515}
516
517/// The values the forms edit, grouped so the view takes one argument for them rather
518/// than four that must be kept in the same order at five call sites.
519#[derive(Debug, Clone, Copy)]
520struct Fields<'a> {
521 description: &'a str,
522 visibility: Visibility,
523 pinned: bool,
524 /// What the rename field holds. The stored name almost always, and what was typed
525 /// when a rename was refused — a form that discards the attempt hides the reason.
526 rename_to: &'a str,
527 /// Whether the repository is archived. Read-only here: the control is a button that
528 /// flips it, not a field the description form can carry along.
529 archived: bool,
530 /// Whether an import is still landing.
531 ///
532 /// Rename and Archive are refused while one is
533 /// ([`Repository::refuse_writes`](crate::domain::Repository::refuse_writes)), so the
534 /// page must not offer them: a button that always fails is worse than one that is
535 /// visibly not available yet. Description, visibility and pin are unaffected — they
536 /// touch neither the directory nor what the import is landing into.
537 importing: bool,
538}
539
540/// The settings page.
541///
542/// Values arrive as parameters rather than being read back from storage, so a rejected
543/// submission can re-render exactly what was typed.
544#[component]
545async fn settings_view(
546 handle: &str,
547 name: &str,
548 fields: Fields<'_>,
549 /// Every branch, the default first. Empty for a repository with nothing pushed.
550 branches: &[BranchRow],
551 saved: bool,
552 error: &str,
553) -> Result {
554 let Fields {
555 description,
556 visibility,
557 pinned,
558 rename_to,
559 archived,
560 importing,
561 } = fields;
562
563 view! {
564 narrow(
565 <h1 class="text-xl font-semibold tracking-tight">"Repository settings"</h1>
566 <p class="mt-1 font-mono text-sm text-muted-foreground">
567 "@" (handle) " / " (name)
568 </p>
569
570 // The section list. One entry today, and the slot a second lands in — the
571 // page is otherwise a single form and a new feature would have nowhere to
572 // announce itself.
573 <nav class="mt-4 flex items-center gap-4 border-b border-border pb-2 text-sm">
574 <span class="border-b-2 border-primary -mb-2.5 pb-2">"General"</span>
575 <a
576 href=(format!("/{handle}/repos/{name}/settings/hooks"))
577 class="text-muted-foreground hover:text-foreground"
578 >"Webhooks"</a>
579 </nav>
580
581 if saved {
582 <div class="mt-6">
583 flash(kind: FlashKind::Success, "Repository updated.")
584 </div>
585 }
586
587 // Said once, at the top, rather than beside each disabled control: two
588 // sections are affected and the reason is the same one.
589 if importing {
590 <div class="mt-6">
591 flash(
592 kind: FlashKind::Info,
593 "This repository is still being imported. Its name and its archived \
594 state cannot change until the import finishes."
595 )
596 </div>
597 }
598
599 if !error.is_empty() {
600 <div class="mt-6">
601 flash(kind: FlashKind::Error, (error))
602 </div>
603 }
604
605 <form
606 method="post"
607 action=(format!("/{handle}/repos/{name}/settings"))
608 class="mt-6 space-y-5"
609 >
610 <div class="space-y-2">
611 label(attrs: attributes! { for="description" }, "Description")
612 textarea(
613 attrs: attributes! {
614 id="description"
615 name="description"
616 rows="2"
617 maxlength=(Repository::MAX_DESCRIPTION_LEN.to_string())
618 placeholder="A sentence for your profile."
619 },
620 (description)
621 )
622 <p class="text-xs text-muted-foreground">
623 "Optional. At most "
624 (Repository::MAX_DESCRIPTION_LEN.to_string()) " characters."
625 </p>
626 </div>
627
628 <div class="space-y-2">
629 label(attrs: attributes! { for="visibility" }, "Visibility")
630 select(
631 attrs: attributes! { id="visibility" name="visibility" },
632 <option value="public" selected=(visibility.is_public())>"Public"</option>
633 <option value="private" selected=(!visibility.is_public())>"Private"</option>
634 )
635 <p class="text-xs text-muted-foreground">
636 "A private repository is hidden from your profile and needs a token "
637 "to clone."
638 </p>
639 </div>
640
641 <div class="space-y-2">
642 <div class="flex items-start gap-2">
643 <input
644 id="pinned"
645 name="pinned"
646 type="checkbox"
647 value="on"
648 checked=(pinned)
649 class="mt-0.5"
650 />
651 label(attrs: attributes! { for="pinned" }, "Lead my profile with this")
652 </div>
653 <p class="text-xs text-muted-foreground">
654 "One repository at a time. Choosing this one lets go of whichever "
655 "was chosen before."
656 </p>
657 </div>
658
659 <div class="flex items-center gap-3">
660 button(attrs: attributes! { type="submit" }, "Save")
661 <a
662 href=(format!("/{handle}/repos/{name}"))
663 class="text-sm text-muted-foreground hover:text-foreground"
664 >"Back to repository"</a>
665 </div>
666 </form>
667
668 <section class="mt-8 border-t border-border pt-6">
669 <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground">
670 "Default branch"
671 </h2>
672
673 if importing {
674 // Not "nothing has been pushed yet", which is a different fact and
675 // would read as an empty repository. The mirror brings `HEAD` with
676 // it, so there is nothing to choose here anyway.
677 <p class="mt-2 text-sm text-muted-foreground">
678 "The import brings the source's default branch with it. Once it "
679 "has landed you can point "<code class="font-mono">"HEAD"</code>
680 " somewhere else."
681 </p>
682 } else if branches.is_empty() {
683 <p class="mt-2 text-sm text-muted-foreground">
684 "Nothing has been pushed yet, so there is no branch to choose. "
685 "The first branch you push becomes the default."
686 </p>
687 } else {
688 <form
689 method="post"
690 action=(format!("/{handle}/repos/{name}/settings/default-branch"))
691 class="mt-3 flex flex-wrap items-center gap-3"
692 >
693 select(
694 attrs: attributes! {
695 id="branch"
696 name="branch"
697 class="font-mono sm:w-64"
698 aria-label="Default branch"
699 },
700 for branch in branches {
701 <option
702 value=(branch.name.as_str())
703 selected=(branch.is_default)
704 >(branch.name.as_str())</option>
705 }
706 )
707 button(
708 attrs: attributes! { type="submit" },
709 variant: ButtonVariant::Outline,
710 "Update"
711 )
712 </form>
713 <p class="mt-2 text-xs text-muted-foreground">
714 "What the repository opens at, and what a fresh clone checks out. "
715 "Stored in git as "<code class="font-mono">"HEAD"</code>", not in Steid."
716 </p>
717 }
718 </section>
719
720 <section class="mt-8 border-t border-border pt-6">
721 <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground">
722 if archived { "Archived" } else { "Archive this repository" }
723 </h2>
724 <p class="mt-2 text-sm text-muted-foreground">
725 if archived {
726 "Pushes are refused. Everything that reads still works — browsing, "
727 "cloning, search and downloads."
728 } else {
729 "Marks it finished. Pushes are refused with a message; browsing, "
730 "cloning, search and downloads carry on unchanged. Reversible."
731 }
732 </p>
733
734 <form
735 method="post"
736 action=(format!("/{handle}/repos/{name}/settings/archive"))
737 class="mt-3"
738 >
739 <input
740 type="hidden"
741 name="archived"
742 value=(if archived { "false" } else { "true" })
743 />
744 button(
745 attrs: attributes! { type="submit" disabled=(importing) },
746 variant: ButtonVariant::Outline,
747 if archived { "Unarchive repository" } else { "Archive repository" }
748 )
749 </form>
750 </section>
751
752 <section class="mt-10 rounded-lg border border-border p-4">
753 <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground">
754 "Rename this repository"
755 </h2>
756 <p class="mt-2 text-sm text-muted-foreground">
757 "The old URL stops working straight away — nothing redirects from it. "
758 "Existing clones must update their remote with "
759 <code class="font-mono text-xs">"git remote set-url origin …"</code>"."
760 </p>
761
762 <form
763 method="post"
764 action=(format!("/{handle}/repos/{name}/settings/rename"))
765 class="mt-4 space-y-2"
766 >
767 label(attrs: attributes! { for="rename" }, "New name")
768 input(attrs: attributes! {
769 id="rename"
770 name="name"
771 type="text"
772 value=(rename_to)
773 maxlength=(RepoName::MAX_LEN.to_string())
774 required=(true)
775 autocomplete="off"
776 class="font-mono"
777 })
778 <div class="pt-1">
779 button(
780 attrs: attributes! { type="submit" disabled=(importing) },
781 variant: ButtonVariant::Outline,
782 "Rename repository"
783 )
784 </div>
785 </form>
786 </section>
787
788 <section class="mt-10 rounded-lg border border-destructive/30 p-4">
789 <h2 class="text-xs font-medium uppercase tracking-wider text-destructive">
790 "Delete this repository"
791 </h2>
792 <p class="mt-2 text-sm text-muted-foreground">
793 "This cannot be undone. The commits, branches and tags go with it, and "
794 "anyone with a clone keeps their copy while this instance keeps nothing."
795 </p>
796
797 <form
798 method="post"
799 action=(format!("/{handle}/repos/{name}/settings/delete"))
800 class="mt-4 space-y-2"
801 >
802 label(
803 attrs: attributes! { for="confirm" },
804 "Type " (name) " to confirm"
805 )
806 input(attrs: attributes! {
807 id="confirm"
808 name="confirm"
809 type="text"
810 value=""
811 placeholder=(name)
812 required=(true)
813 autocomplete="off"
814 })
815 <div class="pt-1">
816 button(
817 attrs: attributes! { type="submit" },
818 variant: ButtonVariant::Destructive,
819 "Delete repository"
820 )
821 </div>
822 </form>
823 </section>
824 )
825 }
826}