admin/sync: Keep Exceptions from multiple files

This commit is contained in:
nemunaire 2022-10-31 16:38:32 +01:00
parent ac25202024
commit 23ac512ce6
4 changed files with 16 additions and 13 deletions

View file

@ -14,7 +14,7 @@ func (c *CheckExceptions) GetExerciceExceptions(e *fic.Exercice) *CheckException
return c.GetFileExceptions(filepath.Base(e.Path)) return c.GetFileExceptions(filepath.Base(e.Path))
} }
func (c *CheckExceptions) GetFileExceptions(path string) *CheckExceptions { func (c *CheckExceptions) GetFileExceptions(paths ...string) *CheckExceptions {
if c == nil { if c == nil {
return nil return nil
} }
@ -22,6 +22,7 @@ func (c *CheckExceptions) GetFileExceptions(path string) *CheckExceptions {
ret := CheckExceptions{} ret := CheckExceptions{}
for k, v := range *c { for k, v := range *c {
for _, path := range paths {
if strings.HasPrefix(k, "*:") || strings.HasPrefix(k, path) { if strings.HasPrefix(k, "*:") || strings.HasPrefix(k, path) {
k = strings.TrimPrefix(k, path) k = strings.TrimPrefix(k, path)
@ -30,6 +31,8 @@ func (c *CheckExceptions) GetFileExceptions(path string) *CheckExceptions {
} }
ret[k] = v ret[k] = v
break
}
} }
} }

View file

@ -134,7 +134,7 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
// Call checks hooks // Call checks hooks
for _, h := range hooks.mdTextHooks { for _, h := range hooks.mdTextHooks {
for _, err := range h(e.Overview, exceptions.GetFileExceptions("overview.md")) { for _, err := range h(e.Overview, exceptions.GetFileExceptions("overview.md", "overview.txt")) {
errs = append(errs, NewExerciceError(e, fmt.Errorf("overview.md: %w", err))) errs = append(errs, NewExerciceError(e, fmt.Errorf("overview.md: %w", err)))
} }
} }
@ -164,7 +164,7 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
} else { } else {
// Call checks hooks // Call checks hooks
for _, h := range hooks.mdTextHooks { for _, h := range hooks.mdTextHooks {
for _, err := range h(e.Statement, exceptions.GetFileExceptions("statement.md")) { for _, err := range h(e.Statement, exceptions.GetFileExceptions("statement.md", "statement.txt")) {
errs = append(errs, NewExerciceError(e, fmt.Errorf("statement.md: %w", err))) errs = append(errs, NewExerciceError(e, fmt.Errorf("statement.md: %w", err)))
} }
} }
@ -181,7 +181,7 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
} else { } else {
// Call checks hooks // Call checks hooks
for _, h := range hooks.mdTextHooks { for _, h := range hooks.mdTextHooks {
for _, err := range h(e.Finished, exceptions.GetFileExceptions("finished.txt")) { for _, err := range h(e.Finished, exceptions.GetFileExceptions("finished.md", "finished.txt")) {
errs = append(errs, NewExerciceError(e, fmt.Errorf("finished.md: %w", err))) errs = append(errs, NewExerciceError(e, fmt.Errorf("finished.md: %w", err)))
} }
} }
@ -286,7 +286,7 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
// Call checks hooks // Call checks hooks
for _, h := range hooks.exerciceHooks { for _, h := range hooks.exerciceHooks {
for _, err := range h(e, exceptions.GetFileExceptions("challenge.txt")) { for _, err := range h(e, exceptions) {
errs = append(errs, NewExerciceError(e, err)) errs = append(errs, NewExerciceError(e, err))
} }
} }

View file

@ -7,7 +7,7 @@ import (
"srs.epita.fr/fic-server/libfic" "srs.epita.fr/fic-server/libfic"
) )
var hooks = &CheckHooks{} var hooks = &CheckHooks{customHooks: map[string]CustomCheckHook{}}
type CheckFlagChoiceHook func(*fic.FlagChoice, *CheckExceptions) []error type CheckFlagChoiceHook func(*fic.FlagChoice, *CheckExceptions) []error
type CheckFlagKeyHook func(*fic.FlagKey, string, *CheckExceptions) []error type CheckFlagKeyHook func(*fic.FlagKey, string, *CheckExceptions) []error

View file

@ -144,7 +144,7 @@ func BuildTheme(i Importer, tdir string) (th *fic.Theme, exceptions *CheckExcept
} else { } else {
// Call checks hooks // Call checks hooks
for _, h := range hooks.mdTextHooks { for _, h := range hooks.mdTextHooks {
for _, err := range h(intro, exceptions.GetFileExceptions("overview.md")) { for _, err := range h(intro, exceptions.GetFileExceptions("overview.md", "overview.txt")) {
errs = append(errs, NewThemeError(th, fmt.Errorf("overview.md: %w", err))) errs = append(errs, NewThemeError(th, fmt.Errorf("overview.md: %w", err)))
} }
} }