project

package
v1.90.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WakaTimeProjectFile is the special file which if present should contain the project name and optional branch name
	// that will be used instead of the auto-detected project and branch names.
	WakaTimeProjectFile = ".wakatime-project"
)

Variables

This section is empty.

Functions

func CountSlashesInProjectFolder added in v1.62.1

func CountSlashesInProjectFolder(directory string) int

CountSlashesInProjectFolder counts the number of slashes in a folder path.

func Detect

func Detect(patterns []MapPattern, args ...DetecterArg) (Result, DetectorID)

Detect finds the current project and branch from config plugins.

func Filter added in v1.35.1

func Filter(h heartbeat.Heartbeat, config FilterConfig) error

Filter determines, following the passed in configurations, if a heartbeat should be skipped.

func FindFileOrDirectory added in v1.18.10

func FindFileOrDirectory(directory, filename string) (string, bool)

FindFileOrDirectory searches for a file or directory named `filename`. Search starts in `directory` and will traverse through all parent directories. `directory` may also be a file, and in that case will start from the file's directory.

func FormatProjectFolder added in v1.62.1

func FormatProjectFolder(fp string) string

FormatProjectFolder returns the abs and real path for the given directory path.

func ReadFile added in v1.73.1

func ReadFile(fp string, max int) ([]string, error)

ReadFile reads a file until max number of lines and return an array of lines.

func WithDetection

func WithDetection(config Config) heartbeat.HandleOption

WithDetection finds the current project and branch. First looks for a .wakatime-project file or project map. Second, uses the --project arg. Third, try to auto-detect using a revision control repository. Last, uses the --alternate-project arg.

func WithFiltering added in v1.35.1

func WithFiltering(config FilterConfig) heartbeat.HandleOption

WithFiltering initializes and returns a heartbeat handle option, which can be used in a heartbeat processing pipeline to filter heartbeats following the provided configurations.

func Write

func Write(folder, project string) error

Write saves wakatime project file.

Types

type Config

type Config struct {
	// HideProjectNames determines if the project name should be obfuscated by matching its path.
	HideProjectNames []regex.Regex
	// Patterns contains the overridden project name per path.
	MapPatterns []MapPattern
	// ProjectFromGitRemote when enabled uses the git remote as the project name instead of local git folder.
	ProjectFromGitRemote bool
	// Submodule contains the submodule configurations.
	Submodule Submodule
}

Config contains project detection configurations.

type Detecter

type Detecter interface {
	Detect() (Result, bool, error)
	ID() DetectorID
}

Detecter is a common interface for project.

type DetecterArg added in v1.45.2

type DetecterArg struct {
	Filepath  string
	ShouldRun bool
}

DetecterArg determines for a given path if it needs to run.

type DetectorID added in v1.45.2

type DetectorID int

DetectorID represents a detector ID.

const (
	// UnknownDetector is the detector ID used when not detected.
	UnknownDetector DetectorID = iota
	// FileDetector is the detector ID for file detector.
	FileDetector
	// MapDetector is the detector ID for map detector.
	MapDetector
	// GitDetector is the detector ID for git detector.
	GitDetector
	// MercurialDetector is the detector ID for mercurial detector.
	MercurialDetector
	// SubversionDetector is the detector ID for subversion detector.
	SubversionDetector
	// TfvcDetector is the detector ID for tfvc detector.
	TfvcDetector
)

func (DetectorID) String added in v1.45.2

func (d DetectorID) String() string

String implements fmt.Stringer interface.

type File

type File struct {
	Filepath string
}

File contains file data.

func (File) Detect

func (f File) Detect() (Result, bool, error)

Detect get information from a .wakatime-project file about the project for a given file. First line of .wakatime-project sets the project name. Second line sets the current branch name.

func (File) ID added in v1.45.2

func (File) ID() DetectorID

ID returns its id.

type FilterConfig added in v1.35.1

type FilterConfig struct {
	// ExcludeUnknownProject determines if heartbeat should be skipped when the project cannot be detected.
	ExcludeUnknownProject bool
}

FilterConfig contains project filtering configurations.

type Git

type Git struct {
	// Filepath contains the entity path.
	Filepath string
	// ProjectFromGitRemote when enabled uses the git remote as the project name instead of local git folder.
	ProjectFromGitRemote bool
	// SubmoduleDisabledPatterns will be matched against the submodule path and if matching, will skip it.
	SubmoduleDisabledPatterns []regex.Regex
	// SubmoduleProjectMapPatterns will be matched against the submodule path and if matching, will use the project map.
	SubmoduleProjectMapPatterns []MapPattern
}

Git contains git data.

func (Git) Detect

func (g Git) Detect() (Result, bool, error)

Detect gets information about the git project for a given file. It tries to return a project and branch name.

func (Git) ID added in v1.45.2

func (Git) ID() DetectorID

ID returns its id.

type Map

type Map struct {
	Filepath string
	Patterns []MapPattern
}

Map contains map data.

func (Map) Detect

func (m Map) Detect() (Result, bool, error)

Detect use the ~/.wakatime.cfg file to set custom project names by matching files with regex patterns. Project maps go under the [projectmap] config section.

For example:

[projectmap]
/home/user/projects/foo = new project name
/home/user/projects/bar(\d+)/ = project{0}

Will result in file '/home/user/projects/foo/src/main.c' to have project name 'new project name' and file '/home/user/projects/bar42/main.c' to have project name 'project42'.

func (Map) ID added in v1.45.2

func (Map) ID() DetectorID

ID returns its id.

type MapPattern

type MapPattern struct {
	// Name is the project name.
	Name string
	// Regex is the regular expression for a specific path.
	Regex regex.Regex
}

MapPattern contains the project name and regular expression for a specific path.

type Mercurial

type Mercurial struct {
	// Filepath contains the entity path.
	Filepath string
}

Mercurial contains mercurial data.

func (Mercurial) Detect

func (m Mercurial) Detect() (Result, bool, error)

Detect gets information about the mercurial project for a given file.

func (Mercurial) ID added in v1.45.2

func (Mercurial) ID() DetectorID

ID returns its id.

type Result

type Result struct {
	Project string
	Branch  string
	Folder  string
}

Result contains the result of Detect().

func DetectWithRevControl

func DetectWithRevControl(
	submoduleDisabledPatterns []regex.Regex,
	submoduleProjectMapPatterns []MapPattern,
	projectFromGitRemote bool,
	args ...DetecterArg) Result

DetectWithRevControl finds the current project and branch from rev control.

type Submodule added in v1.61.0

type Submodule struct {
	// DisabledPatterns contains the paths to match against submodules
	// and if matched it will skip the project detection.
	DisabledPatterns []regex.Regex
	// MapPatterns contains the overridden project name per path for submodule.
	MapPatterns []MapPattern
}

Submodule contains the submodule configurations.

type Subversion

type Subversion struct {
	// Filepath contains the entity path.
	Filepath string
}

Subversion contains svn data.

func (Subversion) Detect

func (s Subversion) Detect() (Result, bool, error)

Detect gets information about the svn project for a given file.

func (Subversion) ID added in v1.45.2

func (Subversion) ID() DetectorID

ID returns its id.

type Tfvc added in v1.6.0

type Tfvc struct {
	// Filepath contains the entity path.
	Filepath string
}

Tfvc contains tfvc data.

func (Tfvc) Detect added in v1.6.0

func (t Tfvc) Detect() (Result, bool, error)

Detect gets information about the tfvc project for a given file.

func (Tfvc) ID added in v1.45.2

func (Tfvc) ID() DetectorID

ID returns its id.

Jump to

Keyboard shortcuts

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