forge
Explore
Log in

Don't you dare go Hollow

An empty repo's home page goes live on its first push

Browse files at this commit

ec20c04ae73cec5f503efe38c1977a9622cf5b53Ahmet Kaan GümüşParent: 1f7ef93
  • fix
    • an empty repo's home page goes live on its first push
Show full message
🐛 fix: an empty repo's home page goes live on its first push
crates/forge-web/src/pages/code_live.rsmodified+6 -4
@@ -35,13 +35,15 @@ pub fn follows_branch(refs: &[RefInfo], ref_name: &str) -> bool {
35 .any(|r| r.kind == RefKind::Branch && r.name == ref_name)35 .any(|r| r.kind == RefKind::Branch && r.name == ref_name)
36 }36 }
37 37
38+/// The stream URL of a code view that follows `branch`, whether or not the branch exists yet.
39+pub fn branch_live_url(owner: &str, repo: &str, branch: &str) -> String {
40+ format!("/{owner}/{repo}/events?ref_name={}", percent_encode(branch))
41+}
42+
38 /// The stream URL of a repo page. A code view of a branch adds the branch to it.43 /// The stream URL of a repo page. A code view of a branch adds the branch to it.
39 pub fn live_url(owner: &str, repo: &str, refs: &[RefInfo], ref_name: &str) -> String {44 pub fn live_url(owner: &str, repo: &str, refs: &[RefInfo], ref_name: &str) -> String {
40 if follows_branch(refs, ref_name) {45 if follows_branch(refs, ref_name) {
41- format!(46+ branch_live_url(owner, repo, ref_name)
42- "/{owner}/{repo}/events?ref_name={}",
43- percent_encode(ref_name)
44- )
45 } else {47 } else {
46 format!("/{owner}/{repo}/events")48 format!("/{owner}/{repo}/events")
47 }49 }
crates/forge-web/src/pages/repo.rsmodified+3 -2
@@ -20,7 +20,7 @@ use topcoat::view::{View, component, view};
20 20
21 use crate::i18n::code::{self as g, K};21 use crate::i18n::code::{self as g, K};
22 use crate::i18n::{self, Lang};22 use crate::i18n::{self, Lang};
23-use crate::pages::code_live::{follows_branch, live_url};23+use crate::pages::code_live::{branch_live_url, follows_branch};
24 use crate::pages::dashboard::badge_class;24 use crate::pages::dashboard::badge_class;
25 use crate::pages::finder::file_finder;25 use crate::pages::finder::file_finder;
26 use crate::pages::issue_parts::stamp_unix;26 use crate::pages::issue_parts::stamp_unix;
@@ -467,7 +467,8 @@ async fn repo_page(cx: &Cx) -> Result<impl View> {
467 ));467 ));
468 }468 }
469 let follows = follows_branch(&refs, &branch);469 let follows = follows_branch(&refs, &branch);
470- let live = live_url(&repo.owner_name, &repo.name, &refs, &branch);470+ // The home page follows the default branch even before its first push, so that push goes live.
471+ let live = branch_live_url(&repo.owner_name, &repo.name, &branch);
471 let owner_name = repo.owner_name.clone();472 let owner_name = repo.owner_name.clone();
472 let repo_name = repo.name.clone();473 let repo_name = repo.name.clone();
473 let branches_href = repo_href(&owner_name, &repo_name, "branches", "");474 let branches_href = repo_href(&owner_name, &repo_name, "branches", "");