github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/plugin/checker/main.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package main 5 6 import ( 7 "fmt" 8 "os" 9 "sort" 10 "strings" 11 ) 12 13 const pluginPackagePath = "github.com/mattermost/mattermost-server/v5/plugin" 14 15 type result struct { 16 Warnings []string 17 Errors []string 18 } 19 20 type checkFn func(pkgPath string) (result, error) 21 22 var checks = []checkFn{ 23 checkAPIVersionComments, 24 checkHelpersVersionComments, 25 } 26 27 func main() { 28 var res result 29 for _, check := range checks { 30 res = runCheck(res, check) 31 } 32 33 var msgs []string 34 msgs = append(msgs, res.Errors...) 35 msgs = append(msgs, res.Warnings...) 36 sort.Strings(msgs) 37 38 if len(msgs) > 0 { 39 fmt.Fprintln(os.Stderr, "#", pluginPackagePath) 40 fmt.Fprintln(os.Stderr, strings.Join(msgs, "\n")) 41 } 42 43 if len(res.Errors) > 0 { 44 os.Exit(1) 45 } 46 } 47 48 func runCheck(prev result, fn checkFn) result { 49 res, err := fn(pluginPackagePath) 50 if err != nil { 51 prev.Errors = append(prev.Errors, err.Error()) 52 return prev 53 } 54 55 if len(res.Warnings) > 0 { 56 prev.Warnings = append(prev.Warnings, mapWarnings(res.Warnings)...) 57 } 58 59 if len(res.Errors) > 0 { 60 prev.Errors = append(prev.Errors, res.Errors...) 61 } 62 63 return prev 64 } 65 66 func mapWarnings(ss []string) []string { 67 var out []string 68 for _, s := range ss { 69 out = append(out, "[warn] "+s) 70 } 71 return out 72 }