sync: Report custom errors
This commit is contained in:
parent
08ea1bac0d
commit
c78545c18b
17 changed files with 510 additions and 137 deletions
17
repochecker/epita/files.go
Normal file
17
repochecker/epita/files.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
func EPITACheckFile(file *fic.EFile) (errs []error) {
|
||||
// Enforce file format
|
||||
if path.Ext(file.Name) == "rar" || path.Ext(file.Name) == "7z" {
|
||||
errs = append(errs, fmt.Errorf("this file use a forbidden archive type."))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
22
repochecker/epita/flags.go
Normal file
22
repochecker/epita/flags.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unicode"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
func EPITACheckKeyFlag(flag *fic.FlagKey, raw string) (errs []error) {
|
||||
if (flag.Label[0] == 'Q' || flag.Label[0] == 'q') && (flag.Label[1] == 'U' || flag.Label[1] == 'u') ||
|
||||
(flag.Label[0] == 'W' || flag.Label[0] == 'w') && (flag.Label[1] == 'H' || flag.Label[1] == 'h') {
|
||||
errs = append(errs, fmt.Errorf("Label should not begin with %s. This seem to be a question. Reword your label as a description of the expected flag, `:` are automatically appended.", flag.Label[0:2]))
|
||||
flag.Label = flag.Label[1:]
|
||||
}
|
||||
|
||||
if flag.Label[len(flag.Label)-1] != ')' && flag.Label[len(flag.Label)-1] != '©' && !unicode.IsLetter(rune(flag.Label[len(flag.Label)-1])) && !unicode.IsDigit(rune(flag.Label[len(flag.Label)-1])) {
|
||||
errs = append(errs, fmt.Errorf("Label should not end with punct (%q). Reword your label as a description of the expected flag, `:` are automatically appended.", flag.Label[len(flag.Label)-1]))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
10
repochecker/epita/main.go
Normal file
10
repochecker/epita/main.go
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
)
|
||||
|
||||
func RegisterChecksHooks(h *sync.CheckHooks) {
|
||||
h.RegisterFlagKeyHook(EPITACheckKeyFlag)
|
||||
h.RegisterFileHook(EPITACheckFile)
|
||||
}
|
||||
Reference in a new issue