Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 0 additions & 3 deletions components/wakatime/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import wakatime from "../../wakatime.app.mjs";

export default {
key: "wakatime-fetch-daily-heartbeats",
name: "Fetch Daily Heartbeats",
description: "Fetch your daily coding activity from WakaTime. [See the documentation](https://wakatime.com/developers#heartbeats)",
version: "0.0.1",
type: "action",
props: {
wakatime,
date: {
type: "string",
label: "Date",
description: "The date to fetch heartbeats for (YYYY-MM-DD)",
},
},
async run({ $ }) {
const response = await this.wakatime.listHeartbeats({
$,
params: {
date: this.date,
},
});

$.export("$summary", `Retrieved ${response.data.length} heartbeat${response.data.length === 1
? ""
: "s"} for ${this.date}`);
return response;
},
};
39 changes: 39 additions & 0 deletions components/wakatime/actions/list-projects/list-projects.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import wakatime from "../../wakatime.app.mjs";

export default {
key: "wakatime-list-projects",
name: "List Projects",
description: "List all your WakaTime projects. [See the documentation](https://wakatime.com/developers#projects)",
version: "0.0.1",
type: "action",
props: {
wakatime,
q: {
type: "string",
label: "Query",
description: "Filter project names by a search term",
optional: true,
},
},
async run({ $ }) {
const results = this.wakatime.paginate({
fn: this.wakatime.listProjects,
args: {
$,
params: {
q: this.q,
},
},
});

const projects = [];
for await (const project of results) {
projects.push(project);
}

$.export("$summary", `Successfully retrieved ${projects.length} project${projects.length === 1
? ""
: "s"}`);
return projects;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import wakatime from "../../wakatime.app.mjs";

export default {
key: "wakatime-log-coding-activity",
name: "Log Coding Activity",
description: "Log coding activity to WakaTime. [See the documentation](https://wakatime.com/developers#heartbeats)",
version: "0.0.1",
type: "action",
props: {
wakatime,
entity: {
type: "string",
label: "Entity",
description: "The entity heartbeat is logging time against, such as an absolute file path or domain",
},
type: {
type: "string",
label: "Type",
description: "Type of entity (file, app or domain)",
default: "file",
options: [
"file",
"app",
"domain",
],
},
time: {
type: "string",
label: "Time",
description: "UNIX epoch timestamp; numbers after decimal point are fractions of a second",
},
category: {
type: "string",
label: "Category",
description: "The category for this activity",
optional: true,
options: [
"coding",
"building",
"indexing",
"debugging",
"browsing",
"running tests",
"writing tests",
"manual testing",
"writing docs",
"communicating",
"code reviewing",
"researching",
"learning",
"designing",
],
},
project: {
propDefinition: [
wakatime,
"project",
],
optional: true,
},
projectRootCount: {
type: "integer",
label: "Project Root Count",
description: "Count of the number of folders in the project root path (optional); for ex: if the project folder is /Users/user/projects/wakatime and the entity path is /Users/user/projects/wakatime/models/user.py then the project_root_count is 5 and the relative entity path after removing 5 prefix folders is models/user.py",
optional: true,
},
branch: {
type: "string",
label: "Branch",
description: "Branch name",
optional: true,
},
language: {
propDefinition: [
wakatime,
"language",
],
},
dependencies: {
type: "string",
label: "Dependencies",
description: "Comma separated list of dependencies",
optional: true,
},
lines: {
type: "integer",
label: "Lines",
description: "Total number of lines in the entity (when entity type is file)",
optional: true,
},
lineAdditions: {
type: "integer",
label: "Line Additions",
description: "Number of lines added since last heartbeat in the current file",
optional: true,
},
lineDeletions: {
type: "integer",
label: "Line Deletions",
description: "Number of lines removed since last heartbeat in the current file",
optional: true,
},
lineNo: {
type: "integer",
label: "Line Number",
description: "Current line row number of cursor with the first line starting at 1",
optional: true,
},
cursorPos: {
type: "integer",
label: "Cursor Position",
description: "Current cursor column position starting from 1",
optional: true,
},
isWrite: {
type: "boolean",
label: "Is Write",
description: "Whether this heartbeat was triggered from writing to a file",
optional: true,
},
},
async run({ $ }) {
const { data } = await this.wakatime.createHeartbeat({
$,
data: {
entity: this.entity,
type: this.type,
category: this.category,
time: this.time,
project: this.project,
project_root_count: this.projectRootCount,
branch: this.branch,
language: this.language,
dependencies: this.dependencies,
lines: this.lines,
line_additions: this.lineAdditions,
line_deletions: this.lineDeletions,
line_no: this.lineNo,
cursor_pos: this.cursorPos,
is_write: this.isWrite,
},
});

$.export("$summary", `Successfully logged coding activity for ${this.entity}`);
return data;
},
};
13 changes: 0 additions & 13 deletions components/wakatime/app/wakatime.app.ts

This file was deleted.

8 changes: 5 additions & 3 deletions components/wakatime/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "@pipedream/wakatime",
"version": "0.0.3",
"version": "0.1.0",
"description": "Pipedream WakaTime Components",
"main": "dist/app/wakatime.app.mjs",
"main": "wakatime.app.mjs",
"keywords": [
"pipedream",
"wakatime"
],
"files": ["dist"],
"homepage": "https://pipedream.com/apps/wakatime",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
92 changes: 92 additions & 0 deletions components/wakatime/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import wakatime from "../../wakatime.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
props: {
wakatime,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastTs() {
return this.db.get("lastTs") || 0;
},
_setLastTs(lastTs) {
this.db.set("lastTs", lastTs);
},
getArgs() {
return {};
},
getResourceKey() {
return "data";
},
getTsField() {
return "created_at";
},
generateMeta(item) {
return {
id: item.id,
summary: this.getSummary(item),
ts: Date.parse(item[this.getTsField()]),
};
},
async processEvent(max) {
const lastTs = this._getLastTs();
let maxTs = lastTs;

const resourceFn = this.getResourceFn();
const args = this.getArgs();
const resourceKey = this.getResourceKey();
const tsField = this.getTsField();

const results = this.wakatime.paginate({
fn: resourceFn,
args,
resourceKey,
});

let items = [];
for await (const item of results) {
const ts = Date.parse(item[tsField]);
if (ts > lastTs) {
items.push(item);
maxTs = Math.max(maxTs, ts);
}
}

if (!items.length) {
return;
}

if (max && items.length >= max) {
items = items.slice(0, max);
}

this._setLastTs(maxTs);

for (const item of items.reverse()) {
const meta = this.generateMeta(item);
this.$emit(item, meta);
}
},
getResourceFn() {
throw new Error("getResourceFn is not implemented");
},
getSummary() {
throw new Error("getSummary is not implemented");
},
},
hooks: {
async deploy() {
await this.processEvent(25);
},
},
async run() {
await this.processEvent();
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "wakatime-new-commit-created",
name: "New Commit Created",
description: "Emit new event when a new commit is created in WakaTime. [See the documentation](https://wakatime.com/developers#commits)",
version: "0.0.1}",
type: "source",
dedupe: "unique",
props: {
...common.props,
project: {
propDefinition: [
common.props.wakatime,
"project",
],
},
},
methods: {
...common.methods,
getResourceFn() {
return this.wakatime.listCommits;
},
getArgs() {
return {
project: this.project,
};
},
getResourceKey() {
return "commits";
},
getSummary(item) {
return `New Commit Created: ${item.message}`;
},
},
sampleEmit,
};
Loading
Loading