Add support for CODEOWNERS

Fixes #9474
This commit is contained in:
Marshall Cottrell 2022-02-18 14:28:02 -06:00 committed by Bjørn Erik Pedersen
parent ec8b767fa6
commit 06bac57ab0
13 changed files with 136 additions and 5 deletions

View file

@ -75,7 +75,8 @@ type HugoSites struct {
*deps.Deps
gitInfo *gitInfo
gitInfo *gitInfo
codeownerInfo *codeownerInfo
// As loaded from the /data dirs
data map[string]interface{}
@ -174,7 +175,7 @@ type hugoSitesInit struct {
// Performs late initialization (before render) of the templates.
layouts *lazy.Init
// Loads the Git info for all the pages if enabled.
// Loads the Git info and CODEOWNERS for all the pages if enabled.
gitInfo *lazy.Init
// Maps page translations.
@ -208,6 +209,18 @@ func (h *HugoSites) gitInfoForPage(p page.Page) (*gitmap.GitInfo, error) {
return h.gitInfo.forPage(p), nil
}
func (h *HugoSites) codeownersForPage(p page.Page) ([]string, error) {
if _, err := h.init.gitInfo.Do(); err != nil {
return nil, err
}
if h.codeownerInfo == nil {
return nil, nil
}
return h.codeownerInfo.forPage(p), nil
}
func (h *HugoSites) siteInfos() page.Sites {
infos := make(page.Sites, len(h.Sites))
for i, site := range h.Sites {
@ -417,6 +430,13 @@ func (h *HugoSites) loadGitInfo() error {
} else {
h.gitInfo = gi
}
co, err := newCodeowners(h.Cfg)
if err != nil {
h.Log.Errorln("Failed to read CODEOWNERS:", err)
} else {
h.codeownerInfo = co
}
}
return nil
}