Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New line additions and deletions params #1023

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/heartbeat/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ func buildHeartbeats(params paramscmd.Params) []heartbeat.Heartbeat {
params.Heartbeat.IsWrite,
params.Heartbeat.Language,
params.Heartbeat.LanguageAlternate,
params.Heartbeat.LineAdditions,
params.Heartbeat.LineDeletions,
params.Heartbeat.LineNumber,
params.Heartbeat.LinesInFile,
params.Heartbeat.LocalFile,
Expand All @@ -210,6 +212,8 @@ func buildHeartbeats(params paramscmd.Params) []heartbeat.Heartbeat {
h.IsWrite,
h.Language,
h.LanguageAlternate,
h.LineAdditions,
h.LineDeletions,
h.LineNumber,
h.Lines,
h.LocalFile,
Expand Down
4 changes: 4 additions & 0 deletions cmd/offline/offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func buildHeartbeats(params paramscmd.Params) []heartbeat.Heartbeat {
params.Heartbeat.IsWrite,
params.Heartbeat.Language,
params.Heartbeat.LanguageAlternate,
params.Heartbeat.LineAdditions,
params.Heartbeat.LineDeletions,
params.Heartbeat.LineNumber,
params.Heartbeat.LinesInFile,
params.Heartbeat.LocalFile,
Expand All @@ -115,6 +117,8 @@ func buildHeartbeats(params paramscmd.Params) []heartbeat.Heartbeat {
h.IsWrite,
h.Language,
h.LanguageAlternate,
h.LineAdditions,
h.LineDeletions,
h.LineNumber,
h.Lines,
h.LocalFile,
Expand Down
33 changes: 31 additions & 2 deletions cmd/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
IsWrite any `json:"is_write"`
Language *string `json:"language"`
LanguageAlternate string `json:"alternate_language"`
LineAdditions any `json:"line_additions"`
LineDeletions any `json:"line_deletions"`
LineNumber any `json:"lineno"`
Lines any `json:"lines"`
Project string `json:"project"`
Expand All @@ -106,6 +108,8 @@
IsWrite *bool
Language *string
LanguageAlternate string
LineAdditions *int
LineDeletions *int
LineNumber *int
LinesInFile *int
LocalFile string
Expand Down Expand Up @@ -401,6 +405,16 @@
isWrite = heartbeat.PointerTo(b)
}

var lineAdditions *int
if num := v.GetInt("line-additions"); v.IsSet("line-additions") {
lineAdditions = heartbeat.PointerTo(num)
}

Check warning on line 411 in cmd/params/params.go

View check run for this annotation

Codecov / codecov/patch

cmd/params/params.go#L410-L411

Added lines #L410 - L411 were not covered by tests

var lineDeletions *int
if num := v.GetInt("line-deletions"); v.IsSet("line-deletions") {
lineDeletions = heartbeat.PointerTo(num)
}

Check warning on line 416 in cmd/params/params.go

View check run for this annotation

Codecov / codecov/patch

cmd/params/params.go#L415-L416

Added lines #L415 - L416 were not covered by tests

var lineNumber *int
if num := v.GetInt("lineno"); v.IsSet("lineno") {
lineNumber = heartbeat.PointerTo(num)
Expand Down Expand Up @@ -442,6 +456,8 @@
IsWrite: isWrite,
Language: language,
LanguageAlternate: vipertools.GetString(v, "alternate-language"),
LineAdditions: lineAdditions,
LineDeletions: lineDeletions,
LineNumber: lineNumber,
LinesInFile: linesInFile,
LocalFile: vipertools.GetString(v, "local-file"),
Expand Down Expand Up @@ -971,6 +987,16 @@
language = *p.Language
}

var lineAdditions string
if p.LineAdditions != nil {
lineAdditions = strconv.Itoa(*p.LineAdditions)
}

var lineDeletions string
if p.LineDeletions != nil {
lineDeletions = strconv.Itoa(*p.LineDeletions)
}

var lineNumber string
if p.LineNumber != nil {
lineNumber = strconv.Itoa(*p.LineNumber)
Expand All @@ -984,8 +1010,9 @@
return fmt.Sprintf(
"category: '%s', cursor position: '%s', entity: '%s', entity type: '%s',"+
" num extra heartbeats: %d, guess language: %t, is unsaved entity: %t,"+
" is write: %t, language: '%s', line number: '%s', lines in file: '%s',"+
" time: %.5f, filter params: (%s), project params: (%s), sanitize params: (%s)",
" is write: %t, language: '%s', line additions: '%s', line deletions: '%s',"+
" line number: '%s', lines in file: '%s', time: %.5f, filter params: (%s),"+
" project params: (%s), sanitize params: (%s)",
p.Category,
cursorPosition,
p.Entity,
Expand All @@ -995,6 +1022,8 @@
p.IsUnsavedEntity,
isWrite,
language,
lineAdditions,
lineDeletions,
lineNumber,
linesInFile,
p.Time,
Expand Down
7 changes: 5 additions & 2 deletions cmd/params/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2461,6 +2461,8 @@ func TestHeartbeat_String(t *testing.T) {
IsUnsavedEntity: true,
IsWrite: heartbeat.PointerTo(true),
Language: heartbeat.PointerTo("Golang"),
LineAdditions: heartbeat.PointerTo(123),
LineDeletions: heartbeat.PointerTo(456),
LineNumber: heartbeat.PointerTo(4),
LinesInFile: heartbeat.PointerTo(56),
Time: 1585598059,
Expand All @@ -2470,8 +2472,9 @@ func TestHeartbeat_String(t *testing.T) {
t,
"category: 'coding', cursor position: '15', entity: 'path/to/entity.go', entity type: 'file',"+
" num extra heartbeats: 3, guess language: true, is unsaved entity: true, is write: true,"+
" language: 'Golang', line number: '4', lines in file: '56', time: 1585598059.00000, filter"+
" params: (exclude: '[]', exclude unknown project: false, include: '[]', include only with"+
" language: 'Golang', line additions: '123', line deletions: '456', line number: '4',"+
" lines in file: '56', time: 1585598059.00000, filter params: (exclude: '[]',"+
" exclude unknown project: false, include: '[]', include only with"+
" project file: false), project params: (alternate: '', branch alternate: '', map patterns:"+
" '[]', override: '', git submodules disabled: '[]', git submodule project map: '[]'), sanitize"+
" params: (hide branch names: '[]', hide project folder: false, hide file names: '[]',"+
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@
0,
"Optional lines in the file. Normally, this is detected automatically but"+
" can be provided manually for performance, accuracy, or when using --local-file.")
flags.Int("line-additions", 0, "Optional number of lines added since last heartbeat in the current file.")
flags.Int("line-deletions", 0, "Optional number of lines deleted since last heartbeat in the current file.")

Check warning on line 157 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L156-L157

Added lines #L156 - L157 were not covered by tests
flags.String(
"local-file",
"",
Expand Down
6 changes: 6 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func testSendHeartbeats(t *testing.T, projectFolder, entity, p string) {
"--entity", entity,
"--cursorpos", "12",
"--offline-queue-file", offlineQueueFile.Name(),
"--line-additions", "123",
"--line-deletions", "456",
"--lineno", "42",
"--lines-in-file", "100",
"--time", "1585598059",
Expand Down Expand Up @@ -213,6 +215,8 @@ func TestSendHeartbeats_SecondaryApiKey(t *testing.T) {
"--entity", "testdata/main.go",
"--cursorpos", "12",
"--offline-queue-file", offlineQueueFile.Name(),
"--line-additions", "123",
"--line-deletions", "456",
"--lineno", "42",
"--lines-in-file", "100",
"--time", "1585598059",
Expand Down Expand Up @@ -373,6 +377,8 @@ func TestSendHeartbeats_Err(t *testing.T) {
"--entity", "testdata/main.go",
"--cursorpos", "12",
"--offline-queue-file", offlineQueueFile.Name(),
"--line-additions", "123",
"--line-deletions", "456",
"--lineno", "42",
"--lines-in-file", "100",
"--time", "1585598059",
Expand Down
6 changes: 6 additions & 0 deletions pkg/heartbeat/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Heartbeat struct {
IsWrite *bool `json:"is_write,omitempty"`
Language *string `json:"language,omitempty"`
LanguageAlternate string `json:"-"`
LineAdditions *int `json:"line_additions,omitempty"`
LineDeletions *int `json:"line_deletions,omitempty"`
LineNumber *int `json:"lineno,omitempty"`
Lines *int `json:"lines,omitempty"`
LocalFile string `json:"-"`
Expand Down Expand Up @@ -58,6 +60,8 @@ func New(
isWrite *bool,
language *string,
languageAlternate string,
lineAdditions *int,
lineDeletions *int,
lineNumber *int,
lines *int,
localFile string,
Expand All @@ -78,6 +82,8 @@ func New(
IsWrite: isWrite,
Language: language,
LanguageAlternate: languageAlternate,
LineAdditions: lineAdditions,
LineDeletions: lineDeletions,
LineNumber: lineNumber,
Lines: lines,
LocalFile: localFile,
Expand Down
6 changes: 6 additions & 0 deletions pkg/heartbeat/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func TestNew(t *testing.T) {
heartbeat.PointerTo(true),
heartbeat.PointerTo("Go"),
"Golang",
heartbeat.PointerTo(2),
heartbeat.PointerTo(3),
heartbeat.PointerTo(42),
nil,
"/path/to/file",
Expand All @@ -50,6 +52,8 @@ func TestNew(t *testing.T) {
IsWrite: heartbeat.PointerTo(true),
Language: heartbeat.PointerTo("Go"),
LanguageAlternate: "Golang",
LineAdditions: heartbeat.PointerTo(2),
LineDeletions: heartbeat.PointerTo(3),
LineNumber: heartbeat.PointerTo(42),
LocalFile: "/path/to/file",
ProjectAlternate: "billing",
Expand Down Expand Up @@ -94,6 +98,8 @@ func TestHeartbeat_JSON(t *testing.T) {
EntityType: heartbeat.FileType,
IsWrite: heartbeat.PointerTo(true),
Language: heartbeat.PointerTo("Go"),
LineAdditions: heartbeat.PointerTo(123),
LineDeletions: heartbeat.PointerTo(456),
LineNumber: heartbeat.PointerTo(42),
Lines: heartbeat.PointerTo(100),
Project: heartbeat.PointerTo("wakatime"),
Expand Down
28 changes: 15 additions & 13 deletions pkg/heartbeat/testdata/heartbeat.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"branch": "heartbeat",
"category": "coding",
"cursorpos": 12,
"dependencies": ["dep1", "dep2"],
"entity": "/tmp/main.go",
"is_write": true,
"language": "Go",
"lineno": 42,
"lines": 100,
"project": "wakatime",
"type": "file",
"time": 1585598060.1,
"user_agent": "wakatime/13.0.7"
"branch": "heartbeat",
"category": "coding",
"cursorpos": 12,
"dependencies": ["dep1", "dep2"],
"entity": "/tmp/main.go",
"is_write": true,
"language": "Go",
"lineno": 42,
"lines": 100,
"line_additions": 123,
"line_deletions": 456,
"project": "wakatime",
"type": "file",
"time": 1585598060.1,
"user_agent": "wakatime/13.0.7"
}
2 changes: 2 additions & 0 deletions testdata/api_heartbeats_request_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"entity": "%s",
"is_write": true,
"language": "Go",
"line_additions": 123,
"line_deletions": 456,
"lineno": 42,
"lines": 100,
"project": "%s",
Expand Down
Loading
Loading