-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
77 lines (65 loc) · 1.99 KB
/
types.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
73
74
75
76
77
package codeowners
import (
"fmt"
)
// ValidatorOptions provide input arguments for checkers to use
type ValidatorOptions struct {
Directory string
CodeownersFileLocation string
GithubTokenType string
GithubToken string
}
// Checker provides tools for validating CODEOWNER file contents
type Checker interface {
NewValidator(options ValidatorOptions) Validator
}
// Validator provides tools for validating CODEOWNER file contents
type Validator interface {
ValidateLine(lineNo int, line string) []CheckResult
}
// SeverityLevel exposes all possible levels of severity check results
type SeverityLevel int
// All possible severiy levels
const (
Error SeverityLevel = iota // Error serverity level
Warning // Warning serverity level
)
// Name returns the string representation of this severity level
func (l SeverityLevel) Name() string {
return [...]string{"Error", "Warning"}[l]
}
// Position provides structured way to evaluate where a given validation result is located in the CODEOWNERs file
type Position struct {
FilePath string
StartLine int
StartColumn int
EndLine int
EndColumn int
}
// Format converts the position data into a string
func (p Position) Format() string {
output := fmt.Sprintf("%s %d", p.FilePath, p.StartLine)
if p.StartColumn >= 1 {
output = fmt.Sprintf("%s:%d", output, p.StartColumn)
}
if p.EndLine > p.StartLine {
output = fmt.Sprintf("%s-%d:%d", output, p.EndLine, p.EndColumn)
} else if p.StartColumn >= 1 && p.EndColumn > p.StartColumn {
output = fmt.Sprintf("%s-%d", output, p.EndColumn)
}
return output
}
// CheckResult provides structured way to evaluate results of a CODEOWNERS validation check
type CheckResult struct {
Position Position
Message string
Severity SeverityLevel
CheckName string
}
// CheckOptions provides parameters for running a list of checks
type CheckOptions struct {
Directory string
Checkers []string
GithubTokenType string
GithubToken string
}