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

@ -23,7 +23,7 @@ type importHint struct {
FlagsDeps []int64
}
func buildExerciceHints(i Importer, exercice *fic.Exercice) (hints []importHint, errs []error) {
func buildExerciceHints(i Importer, exercice *fic.Exercice, exceptions *CheckExceptions) (hints []importHint, errs []error) {
params, _, err := parseExerciceParams(i, exercice.Path)
if err != nil {
errs = append(errs, NewChallengeTxtError(exercice, 0, err))
@ -82,13 +82,22 @@ func buildExerciceHints(i Importer, exercice *fic.Exercice) (hints []importHint,
} else if hint.Content == "" {
errs = append(errs, NewHintError(exercice, h, n, fmt.Errorf("content and filename can't be empty at the same time")))
continue
} else if h.Content, err = ProcessMarkdown(i, fixnbsp(hint.Content), exercice.Path); err != nil {
errs = append(errs, NewHintError(exercice, h, n, fmt.Errorf("error during markdown formating: %w", err)))
} else {
// Call checks hooks
for _, hk := range hooks.mdTextHooks {
for _, err := range hk(h.Content, exceptions.GetFileExceptions("challenge.txt")) {
errs = append(errs, NewHintError(exercice, h, n, err))
}
}
if h.Content, err = ProcessMarkdown(i, fixnbsp(hint.Content), exercice.Path); err != nil {
errs = append(errs, NewHintError(exercice, h, n, fmt.Errorf("error during markdown formating: %w", err)))
}
}
// Call checks hooks
for _, hook := range hooks.hintHooks {
for _, e := range hook(h) {
for _, e := range hook(h, exceptions.GetFileExceptions("challenge.txt")) {
errs = append(errs, NewHintError(exercice, h, n, e))
}
}
@ -110,16 +119,16 @@ func buildExerciceHints(i Importer, exercice *fic.Exercice) (hints []importHint,
}
// CheckExerciceHints checks if all hints are corrects..
func CheckExerciceHints(i Importer, exercice *fic.Exercice) ([]importHint, []error) {
return buildExerciceHints(i, exercice)
func CheckExerciceHints(i Importer, exercice *fic.Exercice, exceptions *CheckExceptions) ([]importHint, []error) {
return buildExerciceHints(i, exercice, exceptions)
}
// SyncExerciceHints reads the content of hints/ directories and import it as EHint for the given challenge.
func SyncExerciceHints(i Importer, exercice *fic.Exercice, flagsBindings map[int64]fic.Flag) (hintsBindings map[int]*fic.EHint, errs []error) {
func SyncExerciceHints(i Importer, exercice *fic.Exercice, flagsBindings map[int64]fic.Flag, exceptions *CheckExceptions) (hintsBindings map[int]*fic.EHint, errs []error) {
if _, err := exercice.WipeHints(); err != nil {
errs = append(errs, err)
} else {
hints, berrs := buildExerciceHints(i, exercice)
hints, berrs := buildExerciceHints(i, exercice, exceptions)
errs = append(errs, berrs...)
hintsBindings = map[int]*fic.EHint{}
@ -149,11 +158,11 @@ func SyncExerciceHints(i Importer, exercice *fic.Exercice, flagsBindings map[int
// ApiListRemoteExerciceHints is an accessor letting foreign packages to access remote exercice hints.
func ApiGetRemoteExerciceHints(c *gin.Context) {
theme, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
theme, exceptions, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
if theme != nil {
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil)
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil, exceptions)
if exercice != nil {
hints, errs := CheckExerciceHints(GlobalImporter, exercice)
hints, errs := CheckExerciceHints(GlobalImporter, exercice, exceptions)
if hints != nil {
c.JSON(http.StatusOK, hints)
return