Documentation
¶
Overview ¶
Package cli implements the tctest command line interface: the cobra commands, flag and config handling, and the workflows that discover PR tests and trigger TeamCity builds.
Index ¶
- func Make() (*cobra.Command, error)
- func ValidateParams(params []string) func(cmd *cobra.Command, args []string) error
- type AstDiscoveryContext
- func (dc *AstDiscoveryContext) AddTestFile(pf provider.File, source string)
- func (dc *AstDiscoveryContext) CollectChangedFiles(ghr GithubRepo, pri int) (resourcePrefixesByPackage map[string][]string, ...)
- func (dc *AstDiscoveryContext) DiscoverSiblingTests(resourcePrefixesByPackage map[string][]string)
- func (dc *AstDiscoveryContext) ParseTestsConcurrently() (map[string][]string, error)
- func (dc *AstDiscoveryContext) PrintDiscoveredFiles()
- func (dc *AstDiscoveryContext) SortedTestFiles() []*provider.File
- func (dc *AstDiscoveryContext) TraceHelperFiles(helperFiles []provider.File)
- func (dc *AstDiscoveryContext) TraceVendorFiles(vendorFiles []provider.File)
- type DiscoveryConfig
- type Filter
- func GetFilterForAuthors(authors []string) *Filter
- func GetFilterForCreatedTime(duration time.Duration) *Filter
- func GetFilterForDrafts(filterDrafts bool) *Filter
- func GetFilterForLabels(labels []string, and bool) *Filter
- func GetFilterForLabelsAnd(labels []string) *Filter
- func GetFilterForLabelsOr(labels []string) *Filter
- func GetFilterForMilestone(milestoneRaw string) *Filter
- func GetFilterForTitleRegex(pattern string) (*Filter, error)
- func GetFilterForUpdatedTime(duration time.Duration) *Filter
- type FlagData
- func (f *FlagData) BuildCmd(buildTypeID, branch, testRegex, service string) (buildID int, buildURL string, err error)
- func (f *FlagData) BuildResultsCmd(buildID int) error
- func (f *FlagData) BuildResultsForPRCmd(pr int) error
- func (f *FlagData) CheckPrCanBuild(number int) error
- func (f *FlagData) GetAndRunPrsTests(prs map[int]string, testRegExParam string) error
- func (f *FlagData) GetFilters() ([]Filter, error)
- func (f *FlagData) GetPrTests(number int, title string) (map[string][]string, error)
- func (f *FlagData) NewRepo() GithubRepo
- func (f *FlagData) NewTCServer() tc.Server
- type FlagsGitHub
- type FlagsGitHubPrFilter
- type FlagsTeamCity
- type FlagsTeamCityBuild
- type GithubRepo
- func (ghr GithubRepo) GetPullRequestTestFiles(pri int, cfg DiscoveryConfig) ([]provider.File, error)
- func (ghr GithubRepo) ListServices() ([]string, error)
- func (ghr GithubRepo) PrTestsFromAPI(pri int, cfg DiscoveryConfig) (map[string][]string, error)
- func (ghr GithubRepo) PrTestsFromAst(pri int, cfg DiscoveryConfig) (map[string][]string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AstDiscoveryContext ¶ added in v1.0.0
type AstDiscoveryContext struct {
RepoPath string
ModulePath string
Config DiscoveryConfig
// File tracking
TestFiles map[string]*provider.File
// Accumulators for PrintDiscoveredFiles
ChangedFileLines []string
}
func NewAstDiscoveryContext ¶ added in v1.0.0
func NewAstDiscoveryContext(repoPath, modulePath string, cfg DiscoveryConfig) *AstDiscoveryContext
func (*AstDiscoveryContext) AddTestFile ¶ added in v1.0.0
func (dc *AstDiscoveryContext) AddTestFile(pf provider.File, source string)
func (*AstDiscoveryContext) CollectChangedFiles ¶ added in v1.0.0
func (dc *AstDiscoveryContext) CollectChangedFiles(ghr GithubRepo, pri int) (resourcePrefixesByPackage map[string][]string, helperFiles, vendorFiles []provider.File, err error)
func (*AstDiscoveryContext) DiscoverSiblingTests ¶ added in v1.0.0
func (dc *AstDiscoveryContext) DiscoverSiblingTests(resourcePrefixesByPackage map[string][]string)
func (*AstDiscoveryContext) ParseTestsConcurrently ¶ added in v1.0.0
func (dc *AstDiscoveryContext) ParseTestsConcurrently() (map[string][]string, error)
func (*AstDiscoveryContext) PrintDiscoveredFiles ¶ added in v1.0.0
func (dc *AstDiscoveryContext) PrintDiscoveredFiles()
func (*AstDiscoveryContext) SortedTestFiles ¶ added in v1.0.0
func (dc *AstDiscoveryContext) SortedTestFiles() []*provider.File
func (*AstDiscoveryContext) TraceHelperFiles ¶ added in v1.0.0
func (dc *AstDiscoveryContext) TraceHelperFiles(helperFiles []provider.File)
func (*AstDiscoveryContext) TraceVendorFiles ¶ added in v1.0.0
func (dc *AstDiscoveryContext) TraceVendorFiles(vendorFiles []provider.File)
type DiscoveryConfig ¶ added in v0.9.0
type DiscoveryConfig struct {
FileRegEx *regexp.Regexp `mapstructure:"-"`
SplitTestsOn string `mapstructure:"splitteston"`
ReappendSplitCharacter bool `mapstructure:"reappend-split-character"`
IndividualTests bool `mapstructure:"individual"`
AccTestFileSuffixRegexes []*regexp.Regexp `mapstructure:"-"`
Concurrency int `mapstructure:"concurrency"`
CollapseFilesAfter int `mapstructure:"collapse-files-after"`
LocalRepoPath string `mapstructure:"local-repo-path"`
LocalTraceDepth int `mapstructure:"local-trace-depth"`
LocalVendorMode string `mapstructure:"local-vendor-mode"`
Mode string `mapstructure:"mode"`
}
func (DiscoveryConfig) AccTestFileSuffixRegexStrings ¶ added in v0.9.1
func (cfg DiscoveryConfig) AccTestFileSuffixRegexStrings() string
type Filter ¶ added in v0.6.0
type Filter struct {
Name string
PR func(github.PullRequest) (bool, error) // todo shjould this return an error?
}
func GetFilterForAuthors ¶ added in v0.6.0
func GetFilterForCreatedTime ¶ added in v0.6.0
func GetFilterForDrafts ¶ added in v0.9.0
func GetFilterForLabels ¶ added in v0.6.0
func GetFilterForLabelsAnd ¶ added in v0.6.0
func GetFilterForLabelsOr ¶ added in v0.6.0
func GetFilterForMilestone ¶ added in v0.6.0
func GetFilterForTitleRegex ¶ added in v0.6.0
func GetFilterForUpdatedTime ¶ added in v0.6.0
type FlagData ¶
type FlagData struct {
GH FlagsGitHub `mapstructure:",squash"`
TC FlagsTeamCity `mapstructure:",squash"`
DiscoveryConfig DiscoveryConfig `mapstructure:",squash"`
OpenInBrowser bool `mapstructure:"open"`
RunAllTests bool `mapstructure:"all"`
Services []string `mapstructure:"service"`
DryRun bool `mapstructure:"dry-run"`
AddTests []string `mapstructure:"add-tests"`
Force bool `mapstructure:"force"`
}
func GetFlags ¶ added in v0.6.0
func GetFlags() *FlagData
GetFlags returns the fully populated FlagData. We must unmarshal from Viper instead of using globally bound pflags variables because pflags only parses command-line arguments. Viper merges environment variables (and config files) on top of the CLI flags. By unmarshaling from Viper, we ensure that environment variable overrides (e.g. TCTEST_GH_TOKEN) are properly applied.
func (*FlagData) BuildCmd ¶ added in v0.6.0
func (f *FlagData) BuildCmd(buildTypeID, branch, testRegex, service string) (buildID int, buildURL string, err error)
BuildCmd triggers a TeamCity build. service is the raw service package name ("" when not building per-service); it is used for display and, when --properties-service-package is set, sent as a build property under that name.
func (*FlagData) BuildResultsCmd ¶ added in v0.6.0
func (*FlagData) BuildResultsForPRCmd ¶ added in v0.6.0
func (*FlagData) CheckPrCanBuild ¶ added in v1.0.1
CheckPrCanBuild verifies a PR exists, is open, and is mergeable. Used by the direct-trigger path (--service + --all/test regex), which skips discovery and would otherwise happily trigger builds on a stale or missing refs/pull/N/merge ref.
func (*FlagData) GetAndRunPrsTests ¶ added in v0.6.0
func (*FlagData) GetFilters ¶ added in v0.6.0
func (*FlagData) GetPrTests ¶ added in v0.6.0
GetPrTests discovers the tests that need to be run for a PR. It first checks if the PR title contains a test override. If not, it delegates to GithubRepo.PrTestsFromAPI to discover tests based on changed files.
func (*FlagData) NewRepo ¶ added in v0.6.0
func (f *FlagData) NewRepo() GithubRepo
func (*FlagData) NewTCServer ¶ added in v0.9.1
type FlagsGitHub ¶ added in v0.6.0
type FlagsGitHub struct {
Token string `mapstructure:"token-gh"`
Repo string `mapstructure:"repo"`
FilterPRs FlagsGitHubPrFilter `mapstructure:",squash"`
// APIURL and RawURL exist so the integration tests can point the binary at mock
// GitHub servers (they also work for GitHub Enterprise). The flags are
// hidden; normally set via TCTEST_GITHUB_API_URL / TCTEST_GITHUB_RAW_URL.
APIURL string `mapstructure:"github-api-url"`
RawURL string `mapstructure:"github-raw-url"`
}
type FlagsGitHubPrFilter ¶ added in v0.6.0
type FlagsGitHubPrFilter struct {
Authors []string `mapstructure:"f-authors"`
LabelsOr []string `mapstructure:"f-labels-any"`
LabelsAnd []string `mapstructure:"f-labels-all"`
Milestone string `mapstructure:"f-milestone"`
TitleRegex string `mapstructure:"f-title-regex"`
Drafts bool `mapstructure:"f-drafts"`
CreationTime time.Duration `mapstructure:"f-created-time"`
UpdatedTime time.Duration `mapstructure:"f-updated-time"`
}
type FlagsTeamCity ¶ added in v0.6.0
type FlagsTeamCity struct {
Build FlagsTeamCityBuild `mapstructure:",squash"`
ServerURL string `mapstructure:"server"`
Token string `mapstructure:"token-tc"`
User string `mapstructure:"username"`
Pass string `mapstructure:"password"`
}
type FlagsTeamCityBuild ¶ added in v0.6.0
type FlagsTeamCityBuild struct {
TypeID string `mapstructure:"build-type-id"`
LegacyTypeID string `mapstructure:"buildtypeid"`
Parameters string `mapstructure:"properties"`
SkipQueue bool `mapstructure:"skip-queue"`
Wait bool `mapstructure:"wait"`
Latest bool `mapstructure:"latest"`
Comment bool `mapstructure:"comment"`
ForceOldUI bool `mapstructure:"build-link-force-old-ui"`
AddServiceSuffix bool `mapstructure:"build-type-id-add-service-suffix"`
ServicePackageProperty string `mapstructure:"properties-service-package"`
QueueTimeout int `mapstructure:"queue-timeout"`
RunTimeout int `mapstructure:"run-timeout"`
MaxBuildsPerPR int `mapstructure:"max-builds-per-pr"`
Tags []string `mapstructure:"tag"`
}
type GithubRepo ¶
GithubRepo wraps the common gh lib shared with my other tools, splitting common GH code from this CLI tool's tooling code.
func (GithubRepo) GetPullRequestTestFiles ¶ added in v1.0.0
func (ghr GithubRepo) GetPullRequestTestFiles(pri int, cfg DiscoveryConfig) ([]provider.File, error)
GetPullRequestTestFiles fetches all changed files in a PR and determines the related test files. It classifies files based on the DiscoveryConfig and lists contents of directories containing changed resources to find related tests.
func (GithubRepo) ListServices ¶ added in v0.7.0
func (ghr GithubRepo) ListServices() ([]string, error)
ListServices lists all service directory names under the provider's service directory (internal/services/ or internal/service/).
func (GithubRepo) PrTestsFromAPI ¶ added in v1.0.0
func (ghr GithubRepo) PrTestsFromAPI(pri int, cfg DiscoveryConfig) (map[string][]string, error)
PrTestsFromAPI fetches the list of files changed in a PR and determines which tests should be run. It uses GetPullRequestTestFiles to get the files, groups them into packages, and returns a map of package names to a list of test names.
func (GithubRepo) PrTestsFromAst ¶ added in v1.0.0
func (ghr GithubRepo) PrTestsFromAst(pri int, cfg DiscoveryConfig) (map[string][]string, error)
PrTestsFromAst performs test discovery using a local git clone of the repository. When cfg.Mode is AST, this is called instead of PrTestsFromAPI (the HTTP-based path).
It fetches the PR merge ref, checks out the code, and uses Go AST to discover affected tests — including tracing imports from helper/validation files back to resource files to find their tests.