sync: Introduce repochecker-ack.txt to support check exceptions

This commit is contained in:
nemunaire 2022-10-29 17:03:57 +02:00
parent edde9f885d
commit fb368d79d1
17 changed files with 283 additions and 106 deletions

View file

@ -104,11 +104,14 @@ func getAuthors(i Importer, tname string) ([]string, error) {
}
// BuildTheme creates a Theme from a given importer.
func BuildTheme(i Importer, tdir string) (th *fic.Theme, errs []error) {
func BuildTheme(i Importer, tdir string) (th *fic.Theme, exceptions *CheckExceptions, errs []error) {
th = &fic.Theme{}
th.Path = tdir
// Get exceptions
exceptions = LoadException(i, th)
// Extract theme's label
if tname, err := GetFileContent(i, path.Join(tdir, "title.txt")); err == nil {
th.Name = fixnbsp(tname)
@ -121,7 +124,7 @@ func BuildTheme(i Importer, tdir string) (th *fic.Theme, errs []error) {
if authors, err := getAuthors(i, tdir); err != nil {
errs = append(errs, NewThemeError(th, fmt.Errorf("unable to get AUTHORS.txt: %w", err)))
return nil, errs
return nil, nil, errs
} else {
// Format authors
th.Authors = strings.Join(authors, ", ")
@ -139,6 +142,13 @@ func BuildTheme(i Importer, tdir string) (th *fic.Theme, errs []error) {
if err != nil {
errs = append(errs, NewThemeError(th, fmt.Errorf("unable to get theme's overview: %w", err)))
} else {
// Call checks hooks
for _, h := range hooks.mdTextHooks {
for _, err := range h(intro, exceptions.GetFileExceptions("overview.md")) {
errs = append(errs, NewThemeError(th, fmt.Errorf("overview.md: %w", err)))
}
}
// Split headline from intro
ovrvw := strings.Split(fixnbsp(intro), "\n")
th.Headline = ovrvw[0]
@ -188,7 +198,7 @@ func BuildTheme(i Importer, tdir string) (th *fic.Theme, errs []error) {
}
// SyncThemes imports new or updates existing themes.
func SyncThemes(i Importer) (errs []error) {
func SyncThemes(i Importer) (exceptions map[string]*CheckExceptions, errs []error) {
if themes, err := GetThemes(i); err != nil {
errs = append(errs, fmt.Errorf("Unable to list themes: %w", err))
} else {
@ -196,8 +206,10 @@ func SyncThemes(i Importer) (errs []error) {
themes[i], themes[j] = themes[j], themes[i]
})
exceptions = map[string]*CheckExceptions{}
for _, tdir := range themes {
btheme, berrs := BuildTheme(i, tdir)
btheme, excepts, berrs := BuildTheme(i, tdir)
for _, e := range berrs {
errs = append(errs, e)
}
@ -206,6 +218,8 @@ func SyncThemes(i Importer) (errs []error) {
continue
}
exceptions[tdir] = excepts
if len(btheme.Image) > 0 {
if _, err := i.importFile(btheme.Image,
func(filePath string, origin string) (interface{}, error) {
@ -251,6 +265,10 @@ func SyncThemes(i Importer) (errs []error) {
return
}
func LoadThemeExceptions(i Importer, theme *fic.Theme) (*CheckExceptions, error) {
return nil, nil
}
// ApiListRemoteThemes is an accessor letting foreign packages to access remote themes list.
func ApiListRemoteThemes(c *gin.Context) {
themes, err := GetThemes(GlobalImporter)
@ -264,7 +282,7 @@ func ApiListRemoteThemes(c *gin.Context) {
// ApiListRemoteTheme is an accessor letting foreign packages to access remote main theme attributes.
func ApiGetRemoteTheme(c *gin.Context) {
r, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
r, _, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
if r == nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Errorf("%q", errs)})
return