Skip to content

New Components - lambdatest #12917

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
96 changes: 94 additions & 2 deletions components/lambdatest/lambdatest.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,103 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "lambdatest",
propDefinitions: {},
propDefinitions: {
priorityLevel: {
type: "string",
label: "Priority Level",
description: "The priority level of the issue",
options: [
"Low",
"Medium",
"High",
],
},
status: {
type: "string",
label: "Status",
description: "The status of the issue",
options: [
"New",
"In Progress",
"Resolved",
"Closed",
],
},
assignee: {
type: "string",
label: "Assignee",
description: "The assignee of the issue",
async options() {
const users = await this.getUsers();
return users.map((user) => ({
label: user.name,
value: user.id,
}));
},
},
filters: {
type: "string",
label: "Filters",
description: "Optional filters for the issue",
optional: true,
},
labels: {
type: "string",
label: "Labels",
description: "Optional labels for the issue",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
},
_baseUrl() {
return "https://api.lambdatest.com";
},
async _makeRequest(opts = {}) {
const {
$ = this, method = "GET", path = "/", headers, ...otherOpts
} = opts;
return axios($, {
...otherOpts,
method,
url: this._baseUrl() + path,
headers: {
...headers,
Authorization: `Bearer ${this.$auth.api_key}`,
},
});
},
async getUsers(opts = {}) {
return this._makeRequest({
path: "/users",
...opts,
});
},
async emitBuildOrTestEvent(opts = {}) {
return this._makeRequest({
path: "/builds-or-tests",
...opts,
});
},
async emitNewIssueEvent({
priorityLevel, status, assignee, filters, labels,
}) {
return this._makeRequest({
path: "/issues",
method: "POST",
data: {
priority_level: priorityLevel,
status,
assignee,
filters,
labels,
},
});
},
},
};
};
2 changes: 1 addition & 1 deletion components/lambdatest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"publishConfig": {
"access": "public"
}
}
}
103 changes: 103 additions & 0 deletions components/lambdatest/sources/marked-new-issue/marked-new-issue.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { axios } from "@pipedream/platform";

Check failure on line 1 in components/lambdatest/sources/marked-new-issue/marked-new-issue.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used
import lambdatest from "../../lambdatest.app.mjs";

export default {
key: "lambdatest-marked-new-issue",
name: "New Issue Marked in LambdaTest",
description: "Emit a new event when an issue is marked as new in LambdaTest. [See the documentation](https://www.lambdatest.com/support/api-doc/)",
version: "0.0.{{ts}}",
type: "source",
dedupe: "unique",
props: {
lambdatest,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: 60,
},
},
priorityLevel: {
propDefinition: [
lambdatest,
"priorityLevel",
],
},
status: {
propDefinition: [
lambdatest,
"status",
],
},
assignee: {
propDefinition: [
lambdatest,
"assignee",
],
},
filters: {
propDefinition: [
lambdatest,
"filters",
],
optional: true,
},
labels: {
propDefinition: [
lambdatest,
"labels",
],
optional: true,
},
},
hooks: {
async deploy() {
await this.run();
},
async activate() {
// Perform any setup necessary when the source is activated
},
async deactivate() {
// Perform any teardown necessary when the source is deactivated
},
},
methods: {
async _getIssues() {
const issues = await this.lambdatest.emitNewIssueEvent({
priorityLevel: this.priorityLevel,
status: this.status,
assignee: this.assignee,
filters: this.filters,
labels: this.labels,
});
return issues;
},
_getLastTimestamp() {
return this.db.get("lastTimestamp") || 0;
},
_setLastTimestamp(timestamp) {
this.db.set("lastTimestamp", timestamp);
},
},
async run() {
const issues = await this._getIssues();
const lastTimestamp = this._getLastTimestamp();
let maxTimestamp = lastTimestamp;

for (const issue of issues) {
const issueTimestamp = new Date(issue.created_at).getTime();
if (issueTimestamp > lastTimestamp) {
this.$emit(issue, {
id: issue.id,
summary: `New Issue: ${issue.title}`,
ts: issueTimestamp,
});
if (issueTimestamp > maxTimestamp) {
maxTimestamp = issueTimestamp;
}
}
}

this._setLastTimestamp(maxTimestamp);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import lambdatest from "../../lambdatest.app.mjs";

Check failure on line 1 in components/lambdatest/sources/new-build-test-instant/new-build-test-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'lambdatest' is defined but never used
import { axios } from "@pipedream/platform";

Check failure on line 2 in components/lambdatest/sources/new-build-test-instant/new-build-test-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used

export default {
key: "lambdatest-new-build-test-instant",
name: "New Build or Test Executed",
description: "Emit new event when a build or test is executed in LambdaTest. [See the documentation](https://www.lambdatest.com/support/api-doc/)",
version: "0.0.{{ts}}",
type: "source",
dedupe: "unique",
props: {
lambdatest: {
type: "app",
app: "lambdatest",
},
http: {
type: "$.interface.http",
customResponse: false,
},
db: "$.service.db",
},
hooks: {
async deploy() {
const events = await this.lambdatest.emitBuildOrTestEvent({
paginate: true,
max: 50,
});
for (const event of events) {
this.$emit(event, {
id: event.id,
summary: `New event: ${event.name}`,
ts: Date.parse(event.ts),
});
}
},
async activate() {
const webhookId = await this.lambdatest.emitBuildOrTestEvent({
method: "POST",
});
this._setWebhookId(webhookId);
},
async deactivate() {
const webhookId = this._getWebhookId();
if (webhookId) {
await this.lambdatest.emitBuildOrTestEvent({
method: "DELETE",
data: {
id: webhookId,
},
});
}
},
},
methods: {
_getWebhookId() {
return this.db.get("webhookId");
},
_setWebhookId(id) {
this.db.set("webhookId", id);
},
},
async run(event) {
this.$emit(event.body, {
id: event.body.id,
summary: `New build/test executed: ${event.body.name}`,
ts: Date.parse(event.body.timestamp),
});
},
};
Loading