-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set label on PR based on check result
- Loading branch information
1 parent
9e89e8b
commit 8c668fc
Showing
5 changed files
with
125 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
|
||
"github.com/publicsuffix/list/tools/internal/parser" | ||
) | ||
|
||
const ( | ||
invalidTag = "❌invalid" | ||
dnsFailTag = "❌FAIL - DNS VALIDATION" | ||
sortFailTag = "❌FAIL - FIX SORTING ⏬" | ||
) | ||
|
||
var errToLabel = map[error]string{ | ||
// all parser errors, sort in alphabetical order | ||
//parser.ErrCommentPreventsSectionSort{}: "", | ||
parser.ErrConflictingSuffixAndException{}: invalidTag, | ||
//parser.ErrCommentPreventsSuffixSort{}: "", | ||
parser.ErrDuplicateSection{}: invalidTag, | ||
parser.ErrDuplicateSuffix{}: invalidTag, | ||
parser.ErrInvalidEncoding{}: invalidTag, | ||
parser.ErrInvalidSuffix{}: invalidTag, | ||
parser.ErrInvalidUnicode{}: invalidTag, | ||
parser.ErrMissingEntityEmail{}: invalidTag, | ||
parser.ErrMissingEntityName{}: invalidTag, | ||
parser.ErrMissingSection{}: invalidTag, | ||
parser.ErrMissingTXTRecord{}: dnsFailTag, | ||
parser.ErrMismatchedSection{}: invalidTag, | ||
parser.ErrNestedSection{}: invalidTag, | ||
parser.ErrSectionInSuffixBlock{}: invalidTag, | ||
parser.ErrTXTCheckFailure{}: dnsFailTag, | ||
parser.ErrTXTRecordMismatch{}: dnsFailTag, | ||
parser.ErrUnclosedSection{}: invalidTag, | ||
parser.ErrUnknownSection{}: invalidTag, | ||
parser.ErrUnknownSectionMarker{}: invalidTag, | ||
parser.ErrUnknownSectionMarker{}: invalidTag, | ||
parser.ErrUnclosedSection{}: invalidTag, | ||
|
||
// all other errors | ||
ErrReformat: sortFailTag, | ||
} | ||
|
||
var ( | ||
ErrReformat = errors.New("file needs reformatting, run 'psltool fmt' to fix") | ||
) | ||
|
||
func errorsToLabels(errs []error) []string { | ||
labels := make([]string, 0, len(errs)) | ||
|
||
var ( | ||
sortSuccess = true | ||
dnsSuccess = true | ||
) | ||
setLabel := func(label string) { | ||
switch label { | ||
case sortFailTag: | ||
sortSuccess = false | ||
case dnsFailTag: | ||
dnsSuccess = false | ||
} | ||
labels = append(labels, label) | ||
} | ||
|
||
for _, err := range errs { | ||
if label, ok := errToLabel[err]; ok { | ||
setLabel(label) | ||
continue | ||
} | ||
for tpl, label := range errToLabel { | ||
if isType(err, tpl) { | ||
setLabel(label) | ||
break | ||
} | ||
} | ||
} | ||
|
||
if sortSuccess { | ||
labels = append(labels, "✔️Sorting Validated") | ||
} | ||
if dnsSuccess { | ||
labels = append(labels, "✔️DNS _psl Validated") | ||
} | ||
|
||
return labels | ||
} | ||
|
||
func isType(err error, tpl error) bool { | ||
if errors.Is(err, tpl) { | ||
return true | ||
} | ||
if reflect.TypeOf(err) == reflect.TypeOf(tpl) { | ||
return true | ||
} | ||
if wraped, ok := err.(interface{ Unwrap() error }); ok { | ||
return isType(wraped.Unwrap(), tpl) | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters