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