Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpandPath ¶
ExpandPath expands a file path that starts with '~' to the user's home directory. If the path does not start with '~', it is returned unchanged.
Parameters:
path - The file path to be expanded.
Returns:
The expanded file path, with '~' replaced by the user's home directory, if applicable.
func GetCITags ¶
GetCITags retrieves and caches the CI/CD tags from environment variables. It initializes the ciTags map if it is not already initialized. This function is thread-safe due to the use of a mutex.
Returns:
A map[string]string containing the CI/CD tags.
func GetModuleAndSuiteName ¶
GetModuleAndSuiteName extracts the module name and suite name from a given program counter (pc). This function utilizes runtime.FuncForPC to retrieve the full function name associated with the program counter, then splits the string to separate the package name from the function name.
Example 1:
Input: github.com/DataDog/dd-sdk-go-testing.TestRun Output: module: github.com/DataDog/dd-sdk-go-testing suite: testing_test.go
Example 2:
Input: github.com/DataDog/dd-sdk-go-testing.TestRun.func1 Output: module: github.com/DataDog/dd-sdk-go-testing suite: testing_test.go
Parameters:
pc - The program counter for which the module and suite name should be retrieved.
Returns:
module - The module name extracted from the full function name. suite - The base name of the file where the function is located.
func GetRelativePathFromCITagsSourceRoot ¶
GetRelativePathFromCITagsSourceRoot calculates the relative path from the CI workspace root to the specified path. If the CI workspace root is not available in the tags, it returns the original path.
Parameters:
path - The absolute or relative file path for which the relative path should be calculated.
Returns:
The relative path from the CI workspace root to the specified path, or the original path if an error occurs.
func GetStacktrace ¶
GetStacktrace retrieves the current stack trace, skipping a specified number of frames.
This function captures the stack trace of the current goroutine, formats it, and returns it as a string. It uses runtime.Callers to capture the program counters of the stack frames and runtime.CallersFrames to convert these program counters into readable frames. The stack trace is formatted to include the function name, file name, and line number of each frame.
Parameters:
skip - The number of stack frames to skip before capturing the stack trace.
Returns:
A string representation of the current stack trace, with each frame on a new line.
Types ¶
type CodeOwners ¶
type CodeOwners struct {
Sections []*Section
}
CodeOwners represents a structured data type that holds sections of code owners. Each section maps to a slice of entries, where each entry includes a pattern and a list of owners.
func GetCodeOwners ¶
func GetCodeOwners() *CodeOwners
GetCodeOwners retrieves and caches the CODEOWNERS data. It looks for the CODEOWNERS file in various standard locations within the CI workspace. This function is thread-safe due to the use of a mutex.
Returns:
A pointer to a CodeOwners struct containing the parsed CODEOWNERS data, or nil if not found.
func NewCodeOwners ¶
func NewCodeOwners(filePath string) (*CodeOwners, error)
NewCodeOwners creates a new instance of CodeOwners by parsing a CODEOWNERS file located at the given filePath. It returns an error if the file cannot be read or parsed properly.
func (*CodeOwners) GetSection ¶
func (co *CodeOwners) GetSection(section string) *Section
GetSection gets the first Section entry in the CodeOwners that matches the section name. It returns a pointer to the matched entry, or nil if no match is found
type Entry ¶
Entry represents a single entry in a CODEOWNERS file. It includes the pattern for matching files, the list of owners, and the section to which it belongs.
func (Entry) GetOwnersString ¶
GetOwnersString returns a formatted string of the owners list in an Entry. It returns an empty string if there are no owners.