Skip to content

Commit fd6f39e

Browse files
committed
Add --min-duration option
1 parent cbe3bb2 commit fd6f39e

File tree

6 files changed

+58
-20
lines changed

6 files changed

+58
-20
lines changed

README.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,26 @@ You can come back to the **Actions** tab later to see the logs
5858
5959
## Things to know
6060
61-
- Entries shorter than 2 minutes will be ignored
61+
- Entries shorter than 2 minutes will be ignored. This duration is configurable
6262
- Duplicate entries won't be added if they are detected
6363
- Projects will be created in your default workspace. You can move them to another workspace if you want
6464
- Time entries will be created with a default description ("Development"). You can edit it, it won't break duplicates detection
65-
- Run `wakatime-to-toggl --help` to see every possible option
65+
66+
## Detailed usage
67+
68+
```bash
69+
$ wakatime-to-toggl --help
70+
71+
Usage
72+
$ wakatime-to-toggl -w <wakatime-api-key> -t <toggl-api-key>
73+
74+
Options
75+
--wakatime, -w Your Wakatime api key
76+
--toggl, -t Your Toggl api key
77+
--day, -d The day to fetch. 0 is today, 1 is yesterday... Default: 1
78+
--min-duration -m Minimum duration (in seconds) of entries to sync. Default: 120
79+
80+
```
6681

6782
[version-src]: https://runkit.io/bokub/npm-version/branches/master/wakatime-to-toggl?style=flat
6883
[code-style-src]: https://flat.badgen.net/badge/code%20style/prettier/ff69b4

cli.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ const cli = meow(
1010
$ wakatime-to-toggl -w <wakatime-api-key> -t <toggl-api-key>
1111
1212
Options
13-
--wakatime, -w Your Wakatime api key
14-
--toggl, -t Your Toggl api key
15-
--day, -d The day to fetch. 0 is today, 1 is yesterday... Default: 1
13+
--wakatime, -w Your Wakatime api key
14+
--toggl, -t Your Toggl api key
15+
--day, -d The day to fetch. 0 is today, 1 is yesterday... Default: 1
16+
--min-duration -m Minimum duration (in seconds) of entries to sync. Default: 120
1617
`,
1718
{
1819
flags: {
@@ -31,8 +32,13 @@ const cli = meow(
3132
alias: 'd',
3233
default: 1,
3334
},
35+
minDuration: {
36+
type: 'number',
37+
alias: 'm',
38+
default: 120,
39+
},
3440
},
3541
}
3642
);
3743

38-
syncActivity(cli.flags.wakatime, cli.flags.toggl, cli.flags.day);
44+
syncActivity(cli.flags);

package-lock.json

+14-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"name": "wakatime-to-toggl",
33
"description": "Send your WakaTime data to Toggl",
4-
"version": "0.2.0",
4+
"version": "0.3.0",
55
"author": "Boris K",
66
"bin": {
77
"wakatime-to-toggl": "cli.js"
88
},
99
"dependencies": {
1010
"axios": "^0.19.2",
1111
"meow": "^7.0.1",
12-
"ora": "^5.0.0"
12+
"ora": "^5.0.0",
13+
"pretty-ms": "^7.0.0"
1314
},
1415
"devDependencies": {
1516
"prettier": "^2.0.5"

src/sync.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ const wakaTime = require('./wakatime');
22
const toggl = require('./toggl');
33
const ora = require('ora');
44

5-
module.exports = async function (wakaTimeApiKey, togglApiKey, day) {
5+
module.exports = async function (flags) {
66
// Call WakaTime and Toggl APIs
7-
const wakaTimeActivity = await wakaTime.getActivity(day, wakaTimeApiKey);
8-
const togglInfo = await toggl.getInfo(togglApiKey);
7+
const wakaTimeActivity = await wakaTime.getActivity(flags.day, flags.minDuration, flags.wakatime);
8+
const togglInfo = await toggl.getInfo(flags.toggl);
99

1010
// List all WakaTime projects
1111
const wakaTimeProjects = Object.keys(
@@ -22,7 +22,7 @@ module.exports = async function (wakaTimeApiKey, togglApiKey, day) {
2222

2323
// Create projects in Toggl
2424
for (const project of projectsToCreate) {
25-
const created = await toggl.createProject(project, togglInfo.workspaceId, togglApiKey);
25+
const created = await toggl.createProject(project, togglInfo.workspaceId, flags.toggl);
2626
togglInfo.projects.push(created);
2727
await sleep(1000); // One request / second to avoid hitting the limit
2828
}
@@ -50,7 +50,7 @@ module.exports = async function (wakaTimeApiKey, togglApiKey, day) {
5050
continue;
5151
}
5252

53-
await toggl.addEntry(projectId, start, duration, togglApiKey);
53+
await toggl.addEntry(projectId, start, duration, flags.toggl);
5454
spinner.text = `Added ${added}/${wakaTimeActivity.length} entries to Toggl...`;
5555
if (duplicates > 0) {
5656
spinner.text += ` Found ${duplicates} duplicates`;

src/wakatime.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const axios = require('axios');
22
const ora = require('ora');
3+
const prettyMs = require('pretty-ms');
34

45
module.exports = {
5-
getActivity: async function (day, apiKey) {
6+
getActivity: async function (day, minDuration, apiKey) {
67
const date = new Date();
78
date.setDate(date.getDate() - day);
89
const strDate = date.toISOString().substr(0, 10);
@@ -17,13 +18,15 @@ module.exports = {
1718
})
1819
.then((resp) => resp.data.data)
1920
.then((entries) => {
20-
const filtered = entries.filter((e) => e.duration >= 120);
21-
spinner.succeed(`Found ${entries.length} WakaTime entries for the ${strDate}.`);
21+
const filtered = entries.filter((e) => e.duration >= minDuration);
22+
let spinnerText = `Found ${entries.length} WakaTime entries for the ${strDate}.`;
2223
if (filtered.length < entries.length) {
23-
spinner.text += `${
24-
entries.length - filtered.length
25-
} of them are shorter than 2 minutes and will be ignored.`;
24+
spinnerText += ` ${entries.length - filtered.length} of them are shorter than ${prettyMs(
25+
1000 * minDuration,
26+
{ verbose: true }
27+
)} and will be ignored.`;
2628
}
29+
spinner.succeed(spinnerText);
2730
return filtered;
2831
})
2932
.catch((err) => {

0 commit comments

Comments
 (0)