web frontend for git (tangled's grandpa)
7
fork

Configure Feed

Select the types of activity you want to include in your feed.

git: find main branch from config

+37 -17
+4 -1
config.yaml
··· 1 - git: 1 + repo: 2 2 scanPath: /home/icy/code/tmp/testrepos 3 3 readme: 4 4 - readme 5 5 - README 6 6 - readme.md 7 7 - README.md 8 + mainBranch: 9 + - master 10 + - main 8 11 template: 9 12 dir: ./templates 10 13 meta:
+6 -5
config/config.go
··· 8 8 ) 9 9 10 10 type Config struct { 11 - Git struct { 12 - ScanPath string `yaml:"scanPath"` 13 - Readme []string `yaml:"readme"` 14 - } `yaml:"git"` 11 + Repo struct { 12 + ScanPath string `yaml:"scanPath"` 13 + Readme []string `yaml:"readme"` 14 + MainBranch []string `yaml:"mainBranch"` 15 + } `yaml:"repo"` 15 16 Template struct { 16 17 Dir string `yaml:"dir"` 17 18 } `yaml:"template"` ··· 21 22 } `yaml:"meta"` 22 23 Server struct { 23 24 Host string `yaml:"host"` 24 - Port int `yaml:"port"` 25 + Port int `yaml:"port"` 25 26 } `yaml:"server"` 26 27 } 27 28
+10
git/git.go
··· 110 110 111 111 return branches, nil 112 112 } 113 + 114 + func (g *GitRepo) FindMainBranch(branches []string) (string, error) { 115 + for _, b := range branches { 116 + _, err := g.r.ResolveRevision(plumbing.Revision(b)) 117 + if err == nil { 118 + return b, nil 119 + } 120 + } 121 + return "", fmt.Errorf("unable to find main branch") 122 + }
+17 -11
routes/routes.go
··· 18 18 } 19 19 20 20 func (d *deps) Index(w http.ResponseWriter, r *http.Request) { 21 - dirs, err := os.ReadDir(d.c.Git.ScanPath) 21 + dirs, err := os.ReadDir(d.c.Repo.ScanPath) 22 22 if err != nil { 23 23 d.Write500(w) 24 24 log.Printf("reading scan path: %s", err) ··· 28 28 repoInfo := make(map[string]time.Time) 29 29 30 30 for _, dir := range dirs { 31 - path := filepath.Join(d.c.Git.ScanPath, dir.Name()) 31 + path := filepath.Join(d.c.Repo.ScanPath, dir.Name()) 32 32 gr, err := git.Open(path, "") 33 33 if err != nil { 34 34 d.Write500(w) ··· 61 61 func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) { 62 62 name := flow.Param(r.Context(), "name") 63 63 name = filepath.Clean(name) 64 - path := filepath.Join(d.c.Git.ScanPath, name) 64 + path := filepath.Join(d.c.Repo.ScanPath, name) 65 65 gr, err := git.Open(path, "") 66 66 if err != nil { 67 67 d.Write404(w) ··· 76 76 } 77 77 78 78 var readmeContent string 79 - for _, readme := range d.c.Git.Readme { 79 + for _, readme := range d.c.Repo.Readme { 80 80 readmeContent, _ = gr.FileContent(readme) 81 81 if readmeContent != "" { 82 82 break ··· 87 87 log.Printf("no readme found for %s", name) 88 88 } 89 89 90 + mainBranch, err := gr.FindMainBranch(d.c.Repo.MainBranch) 91 + if err != nil { 92 + d.Write500(w) 93 + log.Println(err) 94 + return 95 + } 96 + 90 97 data := make(map[string]any) 91 98 data["name"] = name 92 - // TODO: make this configurable 93 - data["ref"] = "master" 99 + data["ref"] = mainBranch 94 100 data["readme"] = readmeContent 95 101 96 102 d.listFiles(files, data, w) ··· 103 109 ref := flow.Param(r.Context(), "ref") 104 110 105 111 name = filepath.Clean(name) 106 - path := filepath.Join(d.c.Git.ScanPath, name) 112 + path := filepath.Join(d.c.Repo.ScanPath, name) 107 113 gr, err := git.Open(path, ref) 108 114 if err != nil { 109 115 d.Write404(w) ··· 132 138 ref := flow.Param(r.Context(), "ref") 133 139 134 140 name = filepath.Clean(name) 135 - path := filepath.Join(d.c.Git.ScanPath, name) 141 + path := filepath.Join(d.c.Repo.ScanPath, name) 136 142 gr, err := git.Open(path, ref) 137 143 if err != nil { 138 144 d.Write404(w) ··· 152 158 name := flow.Param(r.Context(), "name") 153 159 ref := flow.Param(r.Context(), "ref") 154 160 155 - path := filepath.Join(d.c.Git.ScanPath, name) 161 + path := filepath.Join(d.c.Repo.ScanPath, name) 156 162 gr, err := git.Open(path, ref) 157 163 if err != nil { 158 164 d.Write404(w) ··· 185 191 name := flow.Param(r.Context(), "name") 186 192 ref := flow.Param(r.Context(), "ref") 187 193 188 - path := filepath.Join(d.c.Git.ScanPath, name) 194 + path := filepath.Join(d.c.Repo.ScanPath, name) 189 195 gr, err := git.Open(path, ref) 190 196 if err != nil { 191 197 d.Write404(w) ··· 220 226 func (d *deps) Refs(w http.ResponseWriter, r *http.Request) { 221 227 name := flow.Param(r.Context(), "name") 222 228 223 - path := filepath.Join(d.c.Git.ScanPath, name) 229 + path := filepath.Join(d.c.Repo.ScanPath, name) 224 230 gr, err := git.Open(path, "") 225 231 if err != nil { 226 232 d.Write404(w)