Documentation ¶
Index ¶
- Constants
- func IsValidBypassCmd(comment *gogh.IssueComment, prLoader *ghservice.PullRequestLazyLoader) bool
- func Matches(matchers []FilePattern, filename string) bool
- func OkWithoutTestsPullRequestWithLabelValues(lvs ...string) (prometheus.Observer, error)
- func PullRequestCounterWithLabelValues(lvs ...string) (prometheus.Counter, error)
- func RegisterMetrics() []error
- func UnRegisterAndResetMetrics()
- type BypassCmd
- type FileCategories
- type FileCategoryCounter
- type FilePattern
- type FilePatterns
- type GitHubTestEventsHandler
- type PluginConfiguration
- type TestMatcher
Constants ¶
const ( // WithTests is a label used in prometheus metrics pull_requests_total for pull request containing some tests. WithTests = "with_tests" // WithoutTests is a label used in prometheus metrics pull_requests_total for pull request without any tests. WithoutTests = "without_tests" )
const ( // TestsExistMessage is a message used in GH Status as description when tests are found TestsExistMessage = "There are some tests :)" // TestsExistDetailsPageName is a name of a documentation page that contains additional status details for TestsExistMessage TestsExistDetailsPageName = "tests-exist" // NoTestsMessage is a message used in GH Status as description when no tests shipped with the PR NoTestsMessage = "No tests in this PR :(" // NoTestsDetailsPageName is a name of a documentation page that contains additional status details for NoTestsMessage NoTestsDetailsPageName = "no-tests" // OkOnlySkippedFilesMessage is a message used in GH Status as description when PR comes with a changeset which shouldn't be subject of test verification OkOnlySkippedFilesMessage = "Seems that this PR doesn't need to have tests" // OkOnlySkippedFilesDetailsPageName is a name of a documentation page that contains additional status details for OkOnlySkippedFilesMessage OkOnlySkippedFilesDetailsPageName = "only-skipped" // FailureMessage is a message used in GH Status as description when failure occurred FailureMessage = "Failed while check for tests" // ApprovedByMessage is a message used in GH Status as description when it's commented to skip the check ApprovedByMessage = "PR is fine without tests says @%s" // ApprovedByDetailsPageName is a name of a documentation page that contains additional status details for ApprovedByMessage ApprovedByDetailsPageName = "keeper-approved-by" )
const ( // WithoutTestsMsg contains a status message related to the state when PR is pushed without any test WithoutTestsMsg = "It appears that no tests have been added or updated in this PR." + paragraph + "Automated tests give us confidence in shipping reliable software. Please add some as part of this change." + paragraph + "If you are an admin or the reviewer of this PR and you are sure that no test is needed then you can use the command `" + BypassCheckComment + "` " + "as a comment to make the status green.\n" // WithTestsMsg contains a status message related to the state when PR is updated by a commit containing a test WithTestsMsg = "It seems that this PR already contains some added or changed tests. Good job!" // OnlySkippedMsg contains a status message related to the state when PR is updated so it contains only skipped files OnlySkippedMsg = "It seems that this PR doesn't need any test as all changed files in the changeset match " + "patterns for which the validation should be skipped." )
const BypassCheckComment = "/ok-without-tests"
BypassCheckComment is used as a command to bypass test presence validation
const ProwPluginName = "test-keeper"
ProwPluginName is an external prow plugin name used to register this service
Variables ¶
This section is empty.
Functions ¶
func IsValidBypassCmd ¶
func IsValidBypassCmd(comment *gogh.IssueComment, prLoader *ghservice.PullRequestLazyLoader) bool
IsValidBypassCmd checks if the given comment contains expected string and was added by user with sufficient permissions
func Matches ¶
func Matches(matchers []FilePattern, filename string) bool
Matches iterates over a slice of FilePattern and verifies if passed name matches any of the defined patterns
func OkWithoutTestsPullRequestWithLabelValues ¶
func OkWithoutTestsPullRequestWithLabelValues(lvs ...string) (prometheus.Observer, error)
OkWithoutTestsPullRequestWithLabelValues replaces the method of the same name in MetricVec.
func PullRequestCounterWithLabelValues ¶
func PullRequestCounterWithLabelValues(lvs ...string) (prometheus.Counter, error)
PullRequestCounterWithLabelValues replaces the method of the same name in MetricVec.
func RegisterMetrics ¶
func RegisterMetrics() []error
RegisterMetrics registers prometheus collectors to collect metrics for test-keeper.
func UnRegisterAndResetMetrics ¶
func UnRegisterAndResetMetrics()
UnRegisterAndResetMetrics unregisters and reset prometheus collectors.
Types ¶
type BypassCmd ¶
type BypassCmd struct {
// contains filtered or unexported fields
}
BypassCmd represents a command that is triggered by "/ok-without-tests"
type FileCategories ¶
type FileCategories struct {
Total, Skipped, Tests int
Files *[]scm.ChangedFile
}
FileCategories holds information about the total files coming in the changeset, skipped files (those which are excluded from test verification) and tests
func NewFileTypes ¶
func NewFileTypes(files []scm.ChangedFile) FileCategories
NewFileTypes creates new instance of FileCategories struct with files populated
func (*FileCategories) OnlySkippedFiles ¶
func (f *FileCategories) OnlySkippedFiles() bool
OnlySkippedFiles indicates if changeset contains only files which are excluded from test verification
func (*FileCategories) TestsExist ¶
func (f *FileCategories) TestsExist() bool
TestsExist answers if any test files are found
type FileCategoryCounter ¶
type FileCategoryCounter struct {
Matcher TestMatcher
}
FileCategoryCounter is using plugin.FilePattern to figure out if the given commit affects any test file The plugin.FilePattern is loaded either from test-keeper.yaml file or from set of default matchers based on the languages using in the related project
func (*FileCategoryCounter) Count ¶
func (t *FileCategoryCounter) Count(files []scm.ChangedFile) (FileCategories, error)
Count counts files in the changeset which are tests (included files) and should not be considered for verification (excluded). When first test is found it stops, as this is enough to unblock PR
type FilePattern ¶
type FilePattern struct {
Regexp string
}
FilePattern contains regexp that matches a file
func (*FilePattern) Matches ¶
func (matcher *FilePattern) Matches(filename string) bool
Matches checks if the given string (representing path to a file) contains a substring that matches Regexp stored in this matcher
type FilePatterns ¶
type FilePatterns []FilePattern
FilePatterns is an alias type representing slice of FilePattern
func ParseFilePatterns ¶
func ParseFilePatterns(filePatterns []string) FilePatterns
ParseFilePatterns takes the given patterns and parses to an array of FilePattern instances
func (*FilePatterns) Matches ¶
func (f *FilePatterns) Matches(filename string) bool
Matches iterates over all patterns and returns first successful match or false if none patterns matched
type GitHubTestEventsHandler ¶
GitHubTestEventsHandler is the event handler for the plugin. Implements server.GitHubEventHandler interface which contains the logic for incoming GitHub events
func (*GitHubTestEventsHandler) HandleIssueCommentEvent ¶
func (gh *GitHubTestEventsHandler) HandleIssueCommentEvent(logger log.Logger, comment *gogh.IssueCommentEvent) error
HandleIssueCommentEvent is an entry point for the plugin logic. This method is invoked by the Server when issue comment event is dispatched from the /hook service
func (*GitHubTestEventsHandler) HandlePullRequestEvent ¶
func (gh *GitHubTestEventsHandler) HandlePullRequestEvent(logger log.Logger, event *gogh.PullRequestEvent) error
HandlePullRequestEvent is an entry point for the plugin logic. This method is invoked by the Server when pull request event is dispatched from the /hook service
type PluginConfiguration ¶
type PluginConfiguration struct { config.PluginConfiguration `yaml:",inline,omitempty"` Inclusions []string `yaml:"test_patterns,omitempty"` Exclusions []string `yaml:"skip_validation_for,omitempty"` Combine bool `yaml:"combine_defaults,omitempty"` }
PluginConfiguration defines inclusion and exclusion patterns set of files will be matched against It's unmarshaled from test-keeper.yml configuration file
func LoadConfiguration ¶
func LoadConfiguration(logger log.Logger, change scm.RepositoryChange) *PluginConfiguration
LoadConfiguration loads a PluginConfiguration for the given change
type TestMatcher ¶
type TestMatcher struct { Inclusion []FilePattern Exclusion []FilePattern }
TestMatcher holds definitions of patterns considered as test filenames (inclusions) and those which shouldn't be verified (exclusions)
func LoadDefaultMatcher ¶
func LoadDefaultMatcher() (TestMatcher, error)
LoadDefaultMatcher loads default matcher containing default include and exclude patterns
func LoadMatcher ¶
func LoadMatcher(configuration *PluginConfiguration) (TestMatcher, error)
LoadMatcher loads list of FilePattern either from the provided configuration or from languages retrieved from the given function
func (*TestMatcher) MatchesExclusion ¶
func (matcher *TestMatcher) MatchesExclusion(filename string) bool
MatchesExclusion checks if file name matches defined exclusion patterns
func (*TestMatcher) MatchesInclusion ¶
func (matcher *TestMatcher) MatchesInclusion(filename string) bool
MatchesInclusion checks if file name matches defined inclusion patterns