utils

package
v0.11.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

File: ./utils/Utils.go

Index

Constants

View Source
const BucketName = "Projects"
View Source
const CacheDirName = ".techdetector_cache"

Variables

View Source
var PredefinedFieldsSlice = []string{"Name", "Type", "Category", "Path", "RepoName"}

PredefinedFieldsSlice contains the fields that always go in the findings table

Functions

func Contains

func Contains[T comparable](slice []T, element T) bool

func CountFiles

func CountFiles(dirPath string) (int, error)

func DeleteDatabaseFileIfExists added in v0.8.0

func DeleteDatabaseFileIfExists(path string) error

func DumpSQLiteSchemaForFindings added in v0.8.0

func DumpSQLiteSchemaForFindings(db_file string)

func ExtractRepoName

func ExtractRepoName(repoURL string) (string, error)

func GenerateRandomFilename

func GenerateRandomFilename(extension string) string

func GetStructName added in v0.8.0

func GetStructName(i interface{}) string

func InitializeSQLiteDB added in v0.8.0

func InitializeSQLiteDB(dbPath string) (*sql.DB, error)

InitializeSQLiteDB opens (or creates) the SQLite DB, applies a schema for findings, and optionally turns on performance PRAGMAs for faster bulk inserts.

func InsertMatches added in v0.8.0

func InsertMatches(db *sql.DB, matches []core.Finding) (err error)

func Sanitize added in v0.8.0

func Sanitize(name string) string

func SanitizeRepoName

func SanitizeRepoName(fullName string) string

Types

type BarProgressReporter added in v0.8.0

type BarProgressReporter struct {
	// contains filtered or unexported fields
}

BarProgressReporter is a concrete implementation using progressbar.

func NewBarProgressReporter added in v0.8.0

func NewBarProgressReporter(total int, description string) *BarProgressReporter

NewBarProgressReporter creates a new BarProgressReporter with the given total and description.

func (*BarProgressReporter) Finish added in v0.8.0

func (p *BarProgressReporter) Finish()

func (*BarProgressReporter) Increment added in v0.8.0

func (p *BarProgressReporter) Increment()

Increment increases the progress bar by one.

func (*BarProgressReporter) SetTotal added in v0.8.0

func (p *BarProgressReporter) SetTotal(total int)

SetTotal reinitializes the progress bar with the new total count.

type CloneOptionsBuilder added in v0.8.0

type CloneOptionsBuilder struct {
	// contains filtered or unexported fields
}

func NewCloneOptionsBuilder added in v0.8.0

func NewCloneOptionsBuilder(ctx context.Context, cloneURL, destination string) *CloneOptionsBuilder

func (*CloneOptionsBuilder) Clone added in v0.8.0

func (b *CloneOptionsBuilder) Clone() error

func (*CloneOptionsBuilder) WithBare added in v0.8.0

func (b *CloneOptionsBuilder) WithBare(bare bool) Cloner

func (*CloneOptionsBuilder) WithToken added in v0.8.0

func (b *CloneOptionsBuilder) WithToken(token string) Cloner

type Cloner added in v0.8.0

type Cloner interface {
	WithBare(bare bool) Cloner
	WithToken(token string) Cloner
	Clone() error
}

type GitApi added in v0.8.0

type GitApi interface {
	CloneRepositoryWithContext(ctx context.Context, cloneURL, destination string, bare bool) error
	NewClone(ctx context.Context, cloneURL, destination string) Cloner
}

type GitApiClient added in v0.8.0

type GitApiClient struct{}

func (GitApiClient) Clone added in v0.8.0

func (g GitApiClient) Clone(cloneBaseDir, repoUrl string) (*GitCloneInfo, error)

func (GitApiClient) CloneRepositoryWithContext added in v0.8.0

func (g GitApiClient) CloneRepositoryWithContext(ctx context.Context, cloneURL, destination string, bare bool) error

func (GitApiClient) NewClone added in v0.8.0

func (g GitApiClient) NewClone(ctx context.Context, cloneURL, destination string) Cloner

type GitCloneInfo added in v0.8.0

type GitCloneInfo struct {
	RepoPath     string
	BareRepoPath string
}

type GitMetrics added in v0.8.0

type GitMetrics interface {
	CollectGitMetrics(repoPath, repoName, cutoffDate string) ([]core.Finding, error)
}

GitMetrics defines the behavior for collecting Git metrics.

type GitMetricsClient added in v0.8.0

type GitMetricsClient struct{}

GitMetricsClient is the default implementation of GitMetrics.

func (GitMetricsClient) CollectGitMetrics added in v0.8.0

func (g GitMetricsClient) CollectGitMetrics(repoPath, repoName, cutoffDate string) ([]core.Finding, error)

CollectGitMetrics collects various Git metrics from the repository.

type GithubApi added in v0.8.0

type GithubApi interface {
	ListRepositories(org string) ([]*github.Repository, error)
}

type GithubApiClient added in v0.8.0

type GithubApiClient struct {
	// contains filtered or unexported fields
}

func NewGithubApiClient added in v0.8.0

func NewGithubApiClient() GithubApiClient

func (GithubApiClient) ListRepositories added in v0.8.0

func (apiClient GithubApiClient) ListRepositories(org string) ([]*github.Repository, error)

type GitlabApi added in v0.8.0

type GitlabApi interface {
	ListAllProjects() ([]*gitlab.Project, error)
	Token() string
	BaseURL() string
}

type GitlabApiClient added in v0.8.0

type GitlabApiClient struct {
	// contains filtered or unexported fields
}

func NewGitlabApiClient added in v0.8.0

func NewGitlabApiClient(gitlabToken string, gitlabBaseURL string, noCache bool) *GitlabApiClient

func (GitlabApiClient) BaseURL added in v0.8.0

func (g GitlabApiClient) BaseURL() string

func (GitlabApiClient) ListAllProjects added in v0.8.0

func (g GitlabApiClient) ListAllProjects() ([]*gitlab.Project, error)

func (GitlabApiClient) Token added in v0.8.0

func (g GitlabApiClient) Token() string

type MockMatchIterator added in v0.8.0

type MockMatchIterator struct {
	// contains filtered or unexported fields
}

MockMatchIterator is a mock implementation of core.FindingIterator

func (*MockMatchIterator) HasNext added in v0.8.0

func (m *MockMatchIterator) HasNext() bool

HasNext checks if there are more findings to iterate over.

func (*MockMatchIterator) Next added in v0.8.0

func (m *MockMatchIterator) Next() (core.FindingSet, error)

Next retrieves the next set of findings.

func (*MockMatchIterator) Reset added in v0.8.0

func (m *MockMatchIterator) Reset() error

Reset resets the iterator to the beginning.

type MockMatchRepository added in v0.8.0

type MockMatchRepository struct {
	Matches []core.Finding
}

MockMatchRepository is a mock implementation of core.FindingRepository

func (*MockMatchRepository) Clear added in v0.8.0

func (m *MockMatchRepository) Clear() error

Clear removes all findings from the repository.

func (*MockMatchRepository) Close added in v0.8.0

func (m *MockMatchRepository) Close() error

func (*MockMatchRepository) NewIterator added in v0.8.0

func (m *MockMatchRepository) NewIterator() core.FindingIterator

NewIterator returns a new MockMatchIterator for iterating over the findings.

func (*MockMatchRepository) Store added in v0.8.0

func (m *MockMatchRepository) Store(matches []core.Finding) error

Store appends the provided findings to the repository's Matches slice.

type ProgressReporter added in v0.8.0

type ProgressReporter interface {
	// SetTotal reinitializes the progress bar with the new total count.
	SetTotal(total int)
	// Increment increases the progress by one.
	Increment()

	Finish()
}

ProgressReporter defines methods for reporting progress.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL