config: add repo.ignore
This commit is contained in:
parent
2b57b6e0b1
commit
f661e6e4ce
|
@ -12,6 +12,7 @@ type Config struct {
|
||||||
ScanPath string `yaml:"scanPath"`
|
ScanPath string `yaml:"scanPath"`
|
||||||
Readme []string `yaml:"readme"`
|
Readme []string `yaml:"readme"`
|
||||||
MainBranch []string `yaml:"mainBranch"`
|
MainBranch []string `yaml:"mainBranch"`
|
||||||
|
Ignore []string `yaml:"ignore,omitempty"`
|
||||||
} `yaml:"repo"`
|
} `yaml:"repo"`
|
||||||
Dirs struct {
|
Dirs struct {
|
||||||
Templates string `yaml:"templates"`
|
Templates string `yaml:"templates"`
|
||||||
|
|
4
readme
4
readme
|
@ -39,6 +39,9 @@ Example config.yaml:
|
||||||
mainBranch:
|
mainBranch:
|
||||||
- master
|
- master
|
||||||
- main
|
- main
|
||||||
|
ignore:
|
||||||
|
- foo
|
||||||
|
- bar
|
||||||
dirs:
|
dirs:
|
||||||
templates: ./templates
|
templates: ./templates
|
||||||
static: ./static
|
static: ./static
|
||||||
|
@ -56,6 +59,7 @@ These options are fairly self-explanatory, but of note are:
|
||||||
traverse subdirs yet.
|
traverse subdirs yet.
|
||||||
• repo.readme: readme files to look for. Markdown isn't rendered.
|
• repo.readme: readme files to look for. Markdown isn't rendered.
|
||||||
• repo.mainBranch: main branch names to look for.
|
• repo.mainBranch: main branch names to look for.
|
||||||
|
• repo.ignore: repos to ignore.
|
||||||
• server.name: used for go-import meta tags and clone URLs.
|
• server.name: used for go-import meta tags and clone URLs.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,10 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) {
|
||||||
infos := []info{}
|
infos := []info{}
|
||||||
|
|
||||||
for _, dir := range dirs {
|
for _, dir := range dirs {
|
||||||
|
if d.isIgnored(dir.Name()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
path := filepath.Join(d.c.Repo.ScanPath, dir.Name())
|
path := filepath.Join(d.c.Repo.ScanPath, dir.Name())
|
||||||
gr, err := git.Open(path, "")
|
gr, err := git.Open(path, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -77,8 +81,13 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
|
func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
|
||||||
name := flow.Param(r.Context(), "name")
|
name := flow.Param(r.Context(), "name")
|
||||||
|
if d.isIgnored(name) {
|
||||||
|
d.Write404(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
name = filepath.Clean(name)
|
name = filepath.Clean(name)
|
||||||
path := filepath.Join(d.c.Repo.ScanPath, name)
|
path := filepath.Join(d.c.Repo.ScanPath, name)
|
||||||
|
|
||||||
gr, err := git.Open(path, "")
|
gr, err := git.Open(path, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.Write404(w)
|
d.Write404(w)
|
||||||
|
@ -136,6 +145,10 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (d *deps) RepoTree(w http.ResponseWriter, r *http.Request) {
|
func (d *deps) RepoTree(w http.ResponseWriter, r *http.Request) {
|
||||||
name := flow.Param(r.Context(), "name")
|
name := flow.Param(r.Context(), "name")
|
||||||
|
if d.isIgnored(name) {
|
||||||
|
d.Write404(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
treePath := flow.Param(r.Context(), "...")
|
treePath := flow.Param(r.Context(), "...")
|
||||||
ref := flow.Param(r.Context(), "ref")
|
ref := flow.Param(r.Context(), "ref")
|
||||||
|
|
||||||
|
@ -166,6 +179,10 @@ func (d *deps) RepoTree(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) {
|
func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) {
|
||||||
name := flow.Param(r.Context(), "name")
|
name := flow.Param(r.Context(), "name")
|
||||||
|
if d.isIgnored(name) {
|
||||||
|
d.Write404(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
treePath := flow.Param(r.Context(), "...")
|
treePath := flow.Param(r.Context(), "...")
|
||||||
ref := flow.Param(r.Context(), "ref")
|
ref := flow.Param(r.Context(), "ref")
|
||||||
|
|
||||||
|
@ -190,6 +207,10 @@ func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (d *deps) Log(w http.ResponseWriter, r *http.Request) {
|
func (d *deps) Log(w http.ResponseWriter, r *http.Request) {
|
||||||
name := flow.Param(r.Context(), "name")
|
name := flow.Param(r.Context(), "name")
|
||||||
|
if d.isIgnored(name) {
|
||||||
|
d.Write404(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
ref := flow.Param(r.Context(), "ref")
|
ref := flow.Param(r.Context(), "ref")
|
||||||
|
|
||||||
path := filepath.Join(d.c.Repo.ScanPath, name)
|
path := filepath.Join(d.c.Repo.ScanPath, name)
|
||||||
|
@ -224,6 +245,10 @@ func (d *deps) Log(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (d *deps) Diff(w http.ResponseWriter, r *http.Request) {
|
func (d *deps) Diff(w http.ResponseWriter, r *http.Request) {
|
||||||
name := flow.Param(r.Context(), "name")
|
name := flow.Param(r.Context(), "name")
|
||||||
|
if d.isIgnored(name) {
|
||||||
|
d.Write404(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
ref := flow.Param(r.Context(), "ref")
|
ref := flow.Param(r.Context(), "ref")
|
||||||
|
|
||||||
path := filepath.Join(d.c.Repo.ScanPath, name)
|
path := filepath.Join(d.c.Repo.ScanPath, name)
|
||||||
|
@ -261,6 +286,10 @@ func (d *deps) Diff(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (d *deps) Refs(w http.ResponseWriter, r *http.Request) {
|
func (d *deps) Refs(w http.ResponseWriter, r *http.Request) {
|
||||||
name := flow.Param(r.Context(), "name")
|
name := flow.Param(r.Context(), "name")
|
||||||
|
if d.isIgnored(name) {
|
||||||
|
d.Write404(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
path := filepath.Join(d.c.Repo.ScanPath, name)
|
path := filepath.Join(d.c.Repo.ScanPath, name)
|
||||||
gr, err := git.Open(path, "")
|
gr, err := git.Open(path, "")
|
||||||
|
@ -305,13 +334,3 @@ func (d *deps) ServeStatic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
http.ServeFile(w, r, f)
|
http.ServeFile(w, r, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDescription(path string) (desc string) {
|
|
||||||
db, err := os.ReadFile(filepath.Join(path, "description"))
|
|
||||||
if err == nil {
|
|
||||||
desc = string(db)
|
|
||||||
} else {
|
|
||||||
desc = ""
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package routes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getDescription(path string) (desc string) {
|
||||||
|
db, err := os.ReadFile(filepath.Join(path, "description"))
|
||||||
|
if err == nil {
|
||||||
|
desc = string(db)
|
||||||
|
} else {
|
||||||
|
desc = ""
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deps) isIgnored(name string) bool {
|
||||||
|
for _, i := range d.c.Repo.Ignore {
|
||||||
|
if name == i {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
Loading…
Reference in New Issue