Skip to content

Commit 8e5bf68

Browse files
committed
Improve category parsing
this test must pass fix test
1 parent 51f354b commit 8e5bf68

27 files changed

+289
-213
lines changed

cmd/handler/option.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func WithFormatting() Preprocessor {
2424
}
2525
}
2626

27-
// WithCategoryDetection returns a Preprocessor that applies heartbeat formatting.
27+
// WithCategoryDetection returns a Preprocessor that applies heartbeat categorization.
2828
func WithCategoryDetection() Preprocessor {
2929
return func(_ params.Params) heartbeat.HandleOption {
3030
return heartbeat.WithCategory()

cmd/heartbeat/heartbeat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func buildHeartbeats(ctx context.Context, params params.Params) []heartbeat.Hear
204204

205205
heartbeats = append(heartbeats, heartbeat.New(
206206
params.Heartbeat.Project.BranchAlternate,
207-
&params.Heartbeat.Category,
207+
params.Heartbeat.Category.String(),
208208
params.Heartbeat.CursorPosition,
209209
params.Heartbeat.Entity,
210210
params.Heartbeat.EntityType,

cmd/heartbeat/heartbeat_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ func TestSendHeartbeats_ExtraHeartbeats_Sanitize(t *testing.T) {
541541
assert.Equal(t, []heartbeat.Heartbeat{
542542
{
543543
Branch: nil,
544-
Category: heartbeat.WritingTestsCategory.Pointer(),
544+
Category: heartbeat.WritingTestsCategory.String(),
545545
CursorPosition: nil,
546546
Dependencies: nil,
547547
Entity: "HIDDEN.go",

cmd/heartbeat/testdata/api_heartbeats_request_extra_heartbeats_filtered_template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"category": null,
3+
"category": "writing tests",
44
"dependencies": [
55
"os"
66
],

cmd/heartbeat/testdata/api_heartbeats_request_extra_heartbeats_template.json

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
},
1717
{
1818
"cursorpos": 12,
19-
"category": "coding",
2019
"dependencies": ["os"],
2120
"entity": "%s",
2221
"is_write": true,
@@ -42,7 +41,6 @@
4241
"user_agent": "%s"
4342
},
4443
{
45-
"category": "coding",
4644
"cursorpos": 12,
4745
"dependencies": ["os"],
4846
"entity": "%s",
@@ -57,7 +55,6 @@
5755
"user_agent": "%s"
5856
},
5957
{
60-
"category": "coding",
6158
"cursorpos": 12,
6259
"dependencies": ["os"],
6360
"entity": "%s",
@@ -72,7 +69,6 @@
7269
"user_agent": "%s"
7370
},
7471
{
75-
"category": "coding",
7672
"cursorpos": 12,
7773
"dependencies": ["os"],
7874
"entity": "%s",
@@ -87,7 +83,6 @@
8783
"user_agent": "%s"
8884
},
8985
{
90-
"category": "coding",
9186
"cursorpos": 12,
9287
"dependencies": ["os"],
9388
"entity": "%s",
@@ -102,7 +97,6 @@
10297
"user_agent": "%s"
10398
},
10499
{
105-
"category": "coding",
106100
"cursorpos": 12,
107101
"dependencies": ["os"],
108102
"entity": "%s",
@@ -117,7 +111,6 @@
117111
"user_agent": "%s"
118112
},
119113
{
120-
"category": "coding",
121114
"cursorpos": 12,
122115
"dependencies": ["os"],
123116
"entity": "%s",
@@ -132,7 +125,6 @@
132125
"user_agent": "%s"
133126
},
134127
{
135-
"category": "coding",
136128
"cursorpos": 12,
137129
"dependencies": ["os"],
138130
"entity": "%s",
@@ -147,7 +139,6 @@
147139
"user_agent": "%s"
148140
},
149141
{
150-
"category": "coding",
151142
"cursorpos": 12,
152143
"dependencies": ["os"],
153144
"entity": "%s",
@@ -162,7 +153,6 @@
162153
"user_agent": "%s"
163154
},
164155
{
165-
"category": "coding",
166156
"cursorpos": 12,
167157
"dependencies": ["os"],
168158
"entity": "%s",
@@ -177,7 +167,6 @@
177167
"user_agent": "%s"
178168
},
179169
{
180-
"category": "coding",
181170
"cursorpos": 12,
182171
"dependencies": ["os"],
183172
"entity": "%s",
@@ -192,7 +181,6 @@
192181
"user_agent": "%s"
193182
},
194183
{
195-
"category": "coding",
196184
"cursorpos": 12,
197185
"dependencies": ["os"],
198186
"entity": "%s",
@@ -207,7 +195,6 @@
207195
"user_agent": "%s"
208196
},
209197
{
210-
"category": "coding",
211198
"cursorpos": 12,
212199
"dependencies": ["os"],
213200
"entity": "%s",
@@ -222,7 +209,6 @@
222209
"user_agent": "%s"
223210
},
224211
{
225-
"category": "coding",
226212
"cursorpos": 12,
227213
"dependencies": ["os"],
228214
"entity": "%s",
@@ -237,7 +223,6 @@
237223
"user_agent": "%s"
238224
},
239225
{
240-
"category": "coding",
241226
"cursorpos": 12,
242227
"dependencies": ["os"],
243228
"entity": "%s",
@@ -252,7 +237,6 @@
252237
"user_agent": "%s"
253238
},
254239
{
255-
"category": "coding",
256240
"cursorpos": 12,
257241
"dependencies": ["os"],
258242
"entity": "%s",
@@ -267,7 +251,6 @@
267251
"user_agent": "%s"
268252
},
269253
{
270-
"category": "coding",
271254
"cursorpos": 12,
272255
"dependencies": ["os"],
273256
"entity": "%s",
@@ -282,7 +265,6 @@
282265
"user_agent": "%s"
283266
},
284267
{
285-
"category": "coding",
286268
"cursorpos": 12,
287269
"dependencies": ["os"],
288270
"entity": "%s",
@@ -297,7 +279,6 @@
297279
"user_agent": "%s"
298280
},
299281
{
300-
"category": "coding",
301282
"cursorpos": 12,
302283
"dependencies": ["os"],
303284
"entity": "%s",
@@ -312,7 +293,6 @@
312293
"user_agent": "%s"
313294
},
314295
{
315-
"category": "coding",
316296
"cursorpos": 12,
317297
"dependencies": ["os"],
318298
"entity": "%s",
@@ -327,7 +307,6 @@
327307
"user_agent": "%s"
328308
},
329309
{
330-
"category": "coding",
331310
"cursorpos": 12,
332311
"dependencies": ["os"],
333312
"entity": "%s",
@@ -342,7 +321,6 @@
342321
"user_agent": "%s"
343322
},
344323
{
345-
"category": "coding",
346324
"cursorpos": 12,
347325
"dependencies": ["os"],
348326
"entity": "%s",
@@ -357,7 +335,6 @@
357335
"user_agent": "%s"
358336
},
359337
{
360-
"category": "coding",
361338
"cursorpos": 12,
362339
"dependencies": ["os"],
363340
"entity": "%s",

cmd/heartbeat/testdata/api_heartbeats_request_is_unsaved_entity_template.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[
22
{
3-
"category": "coding",
43
"cursorpos": 41,
54
"entity": "%s",
65
"language": "Go",
@@ -13,7 +12,6 @@
1312
"user_agent": "%s"
1413
},
1514
{
16-
"category": "coding",
1715
"cursorpos": 12,
1816
"entity": "%s",
1917
"is_write": true,
@@ -27,7 +25,6 @@
2725
"user_agent": "%s"
2826
},
2927
{
30-
"category": "coding",
3128
"cursorpos": 13,
3229
"dependencies": ["os"],
3330
"entity": "%s",

cmd/offline/offline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func buildHeartbeats(ctx context.Context, params params.Params) []heartbeat.Hear
8181

8282
heartbeats = append(heartbeats, heartbeat.New(
8383
params.Heartbeat.Project.BranchAlternate,
84-
&params.Heartbeat.Category,
84+
params.Heartbeat.Category.String(),
8585
params.Heartbeat.CursorPosition,
8686
params.Heartbeat.Entity,
8787
params.Heartbeat.EntityType,

cmd/offlinesync/testdata/api_heartbeats_response.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,39 @@
33
[
44
{
55
"data": {
6-
"branch": "todaygoal",
7-
"category": "building",
8-
"cursorpos": 14,
9-
"dependencies": ["dep5", "dep6"],
10-
"entity": "/tmp/main.js",
11-
"is_write": false,
12-
"language": "JavaScript",
13-
"lineno": 44,
14-
"lines": 102,
15-
"project": "wakatime",
6+
"branch": "heartbeat",
7+
"category": "coding",
8+
"cursorpos": 12,
9+
"dependencies": ["dep1", "dep2"],
10+
"entity": "/tmp/main.go",
11+
"is_write": true,
12+
"language": "Go",
13+
"lineno": 42,
14+
"lines": 100,
15+
"project": "wakatime-cli",
1616
"type": "file",
17-
"time": 1592868394.084354,
18-
"user_agent": "wakatime/13.0.8"
17+
"time": 1592868367.219124,
18+
"user_agent": "wakatime/13.0.6"
1919
}
2020
},
2121
201
2222
],
2323
[
2424
{
2525
"data": {
26-
"branch": "todaygoal",
27-
"category": "building",
28-
"cursorpos": 14,
29-
"dependencies": ["dep5", "dep6"],
30-
"entity": "/tmp/main.js",
26+
"branch": "summary",
27+
"category": "debugging",
28+
"cursorpos": 13,
29+
"dependencies": ["dep3", "dep4"],
30+
"entity": "/tmp/main.py",
3131
"is_write": false,
32-
"language": "JavaScript",
33-
"lineno": 44,
34-
"lines": 102,
32+
"language": "Python",
33+
"lineno": 43,
34+
"lines": 101,
3535
"project": "wakatime",
3636
"type": "file",
37-
"time": 1592868394.084354,
38-
"user_agent": "wakatime/13.0.8"
37+
"time": 1592868386.079084,
38+
"user_agent": "wakatime/13.0.7"
3939
}
4040
},
4141
201

0 commit comments

Comments
 (0)