project

package
v1.28.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Detect

func Detect(entity string, patterns []MapPattern) (project, branch string)

Detect finds the current project and branch from config plugins.

func FindFileOrDirectory added in v1.18.10

func FindFileOrDirectory(startDir, fileDir, filename string) (string, bool)

FindFileOrDirectory searches for a file or directory with name `filename`. Search starts in `startDir` and will traverse through all parent directories until the file is found, root directory is reached or `maxRecursiveIteration` is exceeded.

func WithDetection

func WithDetection(c Config) heartbeat.HandleOption

WithDetection finds the current project and branch. First looks for a .wakatime-project file. Second, uses the --project arg. Third, uses the folder name from a revision control repository. Last, uses the --alternate-project arg.

func Write

func Write(folder, project string) error

Write saves wakatime project file.

Types

type Config

type Config struct {
	// Patterns contains the overridden project name per path.
	MapPatterns []MapPattern
	// SubmodulePatterns contains the paths to validate for submodules.
	SubmodulePatterns []regex.Regex
	// ShouldObfuscateProject determines if the project name should be obfuscated according some rules.
	ShouldObfuscateProject bool
}

Config contains project detection configurations.

type Detecter

type Detecter interface {
	Detect() (Result, bool, error)
	String() string
}

Detecter is a common interface for project.

type Err

type Err string

Err handles a custom error when finding for project and branch names.

func (Err) Error

func (e Err) Error() string

Error implements error 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) String

func (f File) String() string

String returns its name.

type Git

type Git struct {
	// Filepath contains the entity path.
	Filepath string
	// SubmodulePatterns will be matched against the submodule path and if matching, will skip it.
	SubmodulePatterns []regex.Regex
}

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) String

func (g Git) String() string

String returns its name.

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) String

func (m Map) String() string

String returns its name.

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 [projectmap] data.

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) String

func (m Mercurial) String() string

String returns its name.

type Result

type Result struct {
	Project string
	Branch  string
	Folder  string
}

Result contains the result of Detect().

func DetectWithRevControl

func DetectWithRevControl(entity string, submodulePatterns []regex.Regex, shouldObfuscate bool) Result

DetectWithRevControl finds the current project and branch from rev control.

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) String

func (s Subversion) String() string

String returns its name.

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) String added in v1.6.0

func (t Tfvc) String() string

String returns its name.

Jump to

Keyboard shortcuts

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