Skip to content

Commit 14be592

Browse files
authored
Merge pull request #1209 from wakatime/develop
Release v1.125.1
2 parents 4780247 + 48103ac commit 14be592

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1026
-729
lines changed

.golangci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ linters:
1919
- usestdlibvars
2020
- usetesting
2121
- whitespace
22-
- wsl
22+
- wsl_v5
2323
settings:
2424
revive:
2525
rules:
@@ -58,6 +58,10 @@ linters:
5858
usetesting:
5959
os-setenv: true
6060
os-temp-dir: true
61+
wsl_v5:
62+
allow-first-in-block: true
63+
allow-whole-block: false
64+
branch-max-lines: 2
6165
exclusions:
6266
generated: lax
6367
rules:

cmd/fileexperts/fileexperts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/wakatime/wakatime-cli/cmd/handler"
99
"github.com/wakatime/wakatime-cli/pkg/exitcode"
1010
"github.com/wakatime/wakatime-cli/pkg/fileexperts"
11+
"github.com/wakatime/wakatime-cli/pkg/filter"
1112
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
1213
"github.com/wakatime/wakatime-cli/pkg/log"
1314
"github.com/wakatime/wakatime-cli/pkg/params"
@@ -57,7 +58,7 @@ func FileExperts(ctx context.Context, v *viper.Viper) (string, error) {
5758
return "", fmt.Errorf("failed to initialize api client: %w", err)
5859
}
5960

60-
sender := fileexperts.NewHandle(apiClient)
61+
sender := fileexperts.NewHandle(apiClient, filter.WithLengthValidator())
6162
handle := handler.New(v, handler.Config{
6263
Params: params,
6364
ParamsLoader: LoadParams,
@@ -125,7 +126,6 @@ func initHandleOptions() []handler.Preprocessor {
125126
handler.WithHeartbeatSanitization(),
126127
handler.WithFileExpertsValidation(),
127128
handler.WithRemoteCleanup(),
128-
handler.WithLengthValidator(),
129129
}
130130
}
131131

cmd/fileexperts/fileexperts_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func TestFileExperts(t *testing.T) {
7474

7575
f, err := os.Open("testdata/api_file_experts_response.json")
7676
require.NoError(t, err)
77+
7778
defer f.Close()
7879

7980
_, err = io.Copy(w, f)

cmd/handler/option.go

Lines changed: 1 addition & 8 deletions
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()
@@ -141,10 +141,3 @@ func WithRemoteCleanup() Preprocessor {
141141
return remote.WithCleanup()
142142
}
143143
}
144-
145-
// WithLengthValidator returns a Preprocessor that applies length validation to heartbeats.
146-
func WithLengthValidator() Preprocessor {
147-
return func(_ params.Params) heartbeat.HandleOption {
148-
return filter.WithLengthValidator()
149-
}
150-
}

cmd/handler/option_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,3 @@ func TestWithRemoteCleanup(t *testing.T) {
167167

168168
assert.Len(t, res, 0)
169169
}
170-
171-
func TestWithLengthValidator(t *testing.T) {
172-
opt := handler.WithLengthValidator()
173-
174-
chain := heartbeat.NewHandle(noopMock{})
175-
hdl := opt(params.Params{})(chain)
176-
177-
res, err := hdl(context.Background(), nil)
178-
require.NoError(t, err)
179-
180-
assert.Len(t, res, 0)
181-
}

cmd/heartbeat/heartbeat.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/wakatime/wakatime-cli/pkg/api"
1313
"github.com/wakatime/wakatime-cli/pkg/backoff"
1414
"github.com/wakatime/wakatime-cli/pkg/exitcode"
15+
"github.com/wakatime/wakatime-cli/pkg/filter"
1516
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
1617
_ "github.com/wakatime/wakatime-cli/pkg/lexer" // force to load all lexers
1718
"github.com/wakatime/wakatime-cli/pkg/log"
@@ -90,10 +91,15 @@ func SendHeartbeats(ctx context.Context, v *viper.Viper, queueFilepath string) e
9091

9192
heartbeats := buildHeartbeats(ctx, params)
9293

93-
var chOfflineSave = make(chan bool)
94+
var (
95+
chOfflineSave = make(chan bool)
96+
savedOffline bool
97+
)
9498

9599
// only send at once the maximum amount of `offline.SendLimit`.
96100
if len(heartbeats) > offline.SendLimit {
101+
savedOffline = true
102+
97103
extraHeartbeats := heartbeats[offline.SendLimit:]
98104

99105
logger.Debugf("save %d extra heartbeat(s) to offline queue", len(extraHeartbeats))
@@ -130,7 +136,7 @@ func SendHeartbeats(ctx context.Context, v *viper.Viper, queueFilepath string) e
130136
results, err := handle(ctx, heartbeats)
131137

132138
// wait for offline queue save to finish
133-
if len(heartbeats) > offline.SendLimit {
139+
if savedOffline {
134140
<-chOfflineSave
135141
}
136142

@@ -157,7 +163,9 @@ func buildHandle(ctx context.Context, v *viper.Viper, params params.Params, queu
157163
return nil, err
158164
}
159165

160-
var handleOpts []heartbeat.HandleOption
166+
handleOpts := []heartbeat.HandleOption{
167+
filter.WithLengthValidator(),
168+
}
161169

162170
if !params.Offline.Disabled {
163171
handleOpts = append(handleOpts, offline.WithQueue(queueFilepath))
@@ -204,7 +212,7 @@ func buildHeartbeats(ctx context.Context, params params.Params) []heartbeat.Hear
204212

205213
heartbeats = append(heartbeats, heartbeat.New(
206214
params.Heartbeat.Project.BranchAlternate,
207-
&params.Heartbeat.Category,
215+
params.Heartbeat.Category.String(),
208216
params.Heartbeat.CursorPosition,
209217
params.Heartbeat.Entity,
210218
params.Heartbeat.EntityType,
@@ -254,7 +262,6 @@ func initHandleOptions() []handler.Preprocessor {
254262
handler.WithProjectFiltering(),
255263
handler.WithHeartbeatSanitization(),
256264
handler.WithRemoteCleanup(),
257-
handler.WithLengthValidator(),
258265
}
259266
}
260267

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",

0 commit comments

Comments
 (0)