steid

@jamesgill /

steid/src/infrastructure/web/repo_settings.rs
Rust31.0 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 // Every branch, not a page of them: this is the default-branch `<select>`, and an
125 // option missing from it is a branch that cannot be chosen — see `one_page`.
126 Ok(list_branches(
127 &repo.handle,
128 &repo.name,
129 None,
130 &current_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")]
143async 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/// Saves the description and visibility.
168///
169/// Success replies 303 so a reload cannot resubmit — see
170/// [`location`](super::context::location) for why it is spelled this way rather than
171/// with `redirect()`, which is a 307 and would re-POST this form to itself.
172///
173/// Failure re-renders with the reason and **what was typed**, rather than bouncing back
174/// to the stored values and hiding what went wrong.
175#[page(POST "/{handle}/repos/{name}/settings")]
176async fn save(cx: &Cx, Form(submitted): Form<SettingsForm>) -> Result {
177 let repo = owned_repo(cx).await?;
178
179 // An unparseable value is a tampered form, not something to default: defaulting
180 // here could publish a repository the owner asked to keep private.
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 &current_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 // The visitor's to fix, so it is shown.
212 Err(Error::Domain(DomainError::Validation { field, reason })) => {
213 format!("That {field} is no good: {reason}.")
214 }
215 // Both mean "not yours" here, and both look like a page that is not there.
216 Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => {
217 return Err(not_found().into());
218 }
219 // Ours, so it is logged and answered generically.
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/// Archives or unarchives the repository.
245///
246/// Both directions through one route, because they are one state with two values and
247/// splitting them would put the rule in the router rather than in the use case.
248#[page(POST "/{handle}/repos/{name}/settings/archive")]
249async fn archive(cx: &Cx, Form(submitted): Form<ArchiveForm>) -> Result {
250 let repo = owned_repo(cx).await?;
251
252 // An unparseable value is a tampered form, not something to default: defaulting
253 // here could reopen a repository its owner closed.
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 &current_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 // Reached by a form replayed after the import started — the page renders the
284 // button disabled — so it re-renders with the reason rather than 500ing.
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/// Points `HEAD` at the chosen branch.
313///
314/// No column is written — see
315/// [`set_default_branch`](crate::application::repo::set_default_branch). The landing
316/// page follows `HEAD` on the next request.
317#[page(POST "/{handle}/repos/{name}/settings/default-branch")]
318async 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 &current_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 // A branch that is gone is the one failure a visitor can act on: the select was
345 // rendered from a list that has since changed under them.
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/// Renames the repository, then sends the owner to the new settings URL.
381///
382/// The old URL is gone rather than redirected — see
383/// [`rename_repo`](crate::application::repo::rename_repo) — so the 303 has to name the
384/// new one or the owner lands on their own 404.
385#[page(POST "/{handle}/repos/{name}/settings/rename")]
386async fn rename(cx: &Cx, Form(submitted): Form<RenameForm>) -> Result {
387 let repo = owned_repo(cx).await?;
388
389 let outcome = rename_repo(
390 &current_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 // The **returned** name, not what was typed: it normalised on the way in, and
403 // sending someone to `/MyForge/settings` would 404 on their own repository.
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 // The import owns the directory this would move. Transient, so it says when to
423 // come back rather than what went wrong.
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/// Deletes the repository, then sends the owner back to their profile.
455///
456/// The repository page no longer exists, so there is nowhere else to go.
457///
458/// **Guarded by typing the name.** Deletion takes the git history with it and there is
459/// no undo; a single button is too easy to hit by accident for something unrecoverable.
460/// The typed value goes through [`RepoName::new`], so it is compared the same way the
461/// name was normalised on the way in — `MyRepo` confirms `myrepo`, and stray whitespace
462/// is not a reason to refuse.
463#[page(POST "/{handle}/repos/{name}/settings/delete")]
464async 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 &current_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/// The values the forms edit, grouped so the view takes one argument for them rather
521/// than four that must be kept in the same order at five call sites.
522#[derive(Debug, Clone, Copy)]
523struct Fields<'a> {
524 description: &'a str,
525 visibility: Visibility,
526 pinned: bool,
527 /// What the rename field holds. The stored name almost always, and what was typed
528 /// when a rename was refused — a form that discards the attempt hides the reason.
529 rename_to: &'a str,
530 /// Whether the repository is archived. Read-only here: the control is a button that
531 /// flips it, not a field the description form can carry along.
532 archived: bool,
533 /// Whether an import is still landing.
534 ///
535 /// Rename and Archive are refused while one is
536 /// ([`Repository::refuse_writes`](crate::domain::Repository::refuse_writes)), so the
537 /// page must not offer them: a button that always fails is worse than one that is
538 /// visibly not available yet. Description, visibility and pin are unaffected — they
539 /// touch neither the directory nor what the import is landing into.
540 importing: bool,
541}
542
543/// The settings page.
544///
545/// Values arrive as parameters rather than being read back from storage, so a rejected
546/// submission can re-render exactly what was typed.
547#[component]
548async fn settings_view(
549 handle: &str,
550 name: &str,
551 fields: Fields<'_>,
552 /// Every branch, the default first. Empty for a repository with nothing pushed.
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 // The section list. One entry today, and the slot a second lands in — the
574 // page is otherwise a single form and a new feature would have nowhere to
575 // announce itself.
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 // Labels live under the Issues tab, not under Settings — they are
583 // reached while looking at issues. This is the second door, because
584 // "where do I change a thing about this repository" is a question people
585 // bring here first.
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 // Said once, at the top, rather than beside each disabled control: two
599 // sections are affected and the reason is the same one.
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}