Skip to content
Merged
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
2 changes: 1 addition & 1 deletion components/linear/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/linear",
"version": "0.5.6",
"version": "0.5.7",
"description": "Pipedream Linear Components",
"main": "linear.app.mjs",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default {
...commentCreatedInstant,
...utils.getAppProps(commentCreatedInstant),
key: "linear-comment-created-instant",
description: "Emit new event when a new comment is created (OAuth). See the docs [here](https://developers.linear.app/docs/graphql/webhooks)",
version: "0.1.6",
description: "Emit new event when a new comment is created (OAuth). [See the documentation](https://developers.linear.app/docs/graphql/webhooks)",
version: "0.1.7",
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default {
...issueCreatedInstant,
...utils.getAppProps(issueCreatedInstant),
key: "linear-issue-created-instant",
description: "Emit new event when a new issue is created (OAuth). See the docs [here](https://developers.linear.app/docs/graphql/webhooks)",
version: "0.3.6",
description: "Emit new event when a new issue is created (OAuth). [See the documentation](https://developers.linear.app/docs/graphql/webhooks)",
version: "0.3.7",
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default {
...issueUpdatedInstant,
...utils.getAppProps(issueUpdatedInstant),
key: "linear-issue-updated-instant",
description: "Emit new event when an issue is updated (OAuth). See the docs [here](https://developers.linear.app/docs/graphql/webhooks)",
version: "0.3.6",
description: "Emit new event when an issue is updated (OAuth). See the documentation](https://developers.linear.app/docs/graphql/webhooks)",
version: "0.3.7",
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default {
...newIssueStatusUpdated,
...utils.getAppProps(newIssueStatusUpdated),
key: "linear-new-issue-status-updated",
description: "Emit new event when the status of an issue is updated (OAuth). See the docs [here](https://developers.linear.app/docs/graphql/webhooks)",
version: "0.1.6",
description: "Emit new event when the status of an issue is updated (OAuth). [See the documentation](https://developers.linear.app/docs/graphql/webhooks)",
version: "0.1.7",
};
2 changes: 1 addition & 1 deletion components/linear_app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/linear_app",
"version": "0.5.6",
"version": "0.5.7",
"description": "Pipedream Linear_app Components",
"main": "linear_app.app.mjs",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export default {
...common,
key: "linear_app-comment-created-instant",
name: "New Created Comment (Instant)",
description: "Emit new event when a new comment is created. See the docs [here](https://developers.linear.app/docs/graphql/webhooks)",
description: "Emit new event when a new comment is created. [See the documentation](https://developers.linear.app/docs/graphql/webhooks)",
type: "source",
version: "0.1.6",
version: "0.1.7",
dedupe: "unique",
methods: {
...common.methods,
Expand Down Expand Up @@ -50,6 +50,11 @@ export default {
},
};
},
getResource(comment) {
return this.linearApp.getComment({
commentId: comment.id,
});
},
getMetadata(resource) {
const {
delivery,
Expand Down
159 changes: 90 additions & 69 deletions components/linear_app/sources/common/webhook.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import linearApp from "../../linear_app.app.mjs";
import constants from "../../common/constants.mjs";
import utils from "../../common/utils.mjs";
import { ConfigurationError } from "@pipedream/platform";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
props: {
Expand All @@ -21,18 +21,28 @@ export default {
"projectId",
],
},
http: "$.interface.http",
db: "$.service.db",
},
async additionalProps() {
const props = {};
if (!(await this.isAdmin())) {
props.alert = {
type: "alert",
alertType: "error",
content: "You must have an admin role to create or manage webhooks. See the Linear [documentation](https://linear.app/docs/api-and-webhooks#webhooks) for details.",
let msg;
if (await this.isAdmin()) {
msg = "Admin role detected. Trigger will be set up as a webhook.";
props.http = "$.interface.http";
} else {
msg = "No admin role detected. Trigger will set up to use polling.";
props.timer = {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
};
}
props.alert = {
type: "alert",
alertType: "info",
content: `${msg} See the Linear [documentation](https://linear.app/docs/api-and-webhooks#webhooks) for details.`,
};
return props;
},
methods: {
Expand All @@ -54,6 +64,9 @@ export default {
useGraphQl() {
return true;
},
getResource() {
throw new Error("getResource is not implemented");
},
getResourceTypes() {
throw new Error("getResourceTypes is not implemented");
},
Expand Down Expand Up @@ -85,15 +98,7 @@ export default {
});
return data?.user?.admin;
},
},
hooks: {
async deploy() {
if (!(await this.isAdmin())) {
throw new ConfigurationError("You must have an admin role to create or manage webhooks. See the Linear [documentation](https://linear.app/docs/api-and-webhooks#webhooks) for details.");
}

// Retrieve historical events
console.log("Retrieving historical events...");
async emitPolledResources() {
const stream = this.linearApp.paginateResources({
resourcesFn: this.getResourcesFn(),
resourcesFnArgs: this.getResourcesFnArgs(),
Expand All @@ -107,73 +112,89 @@ export default {
this.$emit(resource, this.getMetadata(resource));
});
},
},
hooks: {
async deploy() {
// Retrieve historical events
console.log("Retrieving historical events...");
await this.emitPolledResources();
},
async activate() {
const args = {
resourceTypes: this.getResourceTypes(),
url: this.http.endpoint,
label: this.getWebhookLabel(),
};
if (!this.teamIds && !this.teamId) {
args.allPublicTeams = true;
const { _webhook: webhook } = await this.linearApp.createWebhook(args);
this.setWebhookId("1", webhook.id);
return;
}
const teamIds = this.teamIds || [
this.teamId,
];
for (const teamId of teamIds) {
const { _webhook: webhook } =
await this.linearApp.createWebhook({
teamId,
...args,
});
this.setWebhookId(teamId, webhook.id);
if (await this.isAdmin()) {
const args = {
resourceTypes: this.getResourceTypes(),
url: this.http.endpoint,
label: this.getWebhookLabel(),
};
if (!this.teamIds && !this.teamId) {
args.allPublicTeams = true;
const { _webhook: webhook } = await this.linearApp.createWebhook(args);
this.setWebhookId("1", webhook.id);
return;
}
const teamIds = this.teamIds || [
this.teamId,
];
for (const teamId of teamIds) {
const { _webhook: webhook } =
await this.linearApp.createWebhook({
teamId,
...args,
});
this.setWebhookId(teamId, webhook.id);
}
}
},
async deactivate() {
if (!this.teamIds && !this.teamId) {
const webhookId = this.getWebhookId("1");
if (webhookId) {
await this.linearApp.deleteWebhook(webhookId);
if (await this.isAdmin()) {
if (!this.teamIds && !this.teamId) {
const webhookId = this.getWebhookId("1");
if (webhookId) {
await this.linearApp.deleteWebhook(webhookId);
}
return;
}
return;
}
const teamIds = this.teamIds || [
this.teamId,
];
for (const teamId of teamIds) {
const webhookId = this.getWebhookId(teamId);
if (webhookId) {
await this.linearApp.deleteWebhook(webhookId);
const teamIds = this.teamIds || [
this.teamId,
];
for (const teamId of teamIds) {
const webhookId = this.getWebhookId(teamId);
if (webhookId) {
await this.linearApp.deleteWebhook(webhookId);
}
}
}
},
},
async run(event) {
const {
client_ip: clientIp,
body,
headers,
} = event;
if (!(await this.isAdmin())) {
await this.emitPolledResources();
} else {
const {
client_ip: clientIp,
body,
headers,
} = event;

const { [constants.LINEAR_DELIVERY_HEADER]: delivery } = headers;
const { [constants.LINEAR_DELIVERY_HEADER]: delivery } = headers;

const resource = {
...body,
delivery,
};
const resource = {
...body,
delivery,
};

if (!this.isWebhookValid(clientIp)) {
console.log("Webhook is not valid");
return;
}
if (!this.isWebhookValid(clientIp)) {
console.log("Webhook is not valid");
return;
}

if (!(await this.isFromProject(body)) || !this.isRelevant(body)) {
return;
}
if (!(await this.isFromProject(body)) || !this.isRelevant(body)) {
return;
}

const meta = this.getMetadata(resource);
this.$emit(body, meta);
const meta = this.getMetadata(resource);
const item = await this.getResource(body.data);
this.$emit(item, meta);
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export default {
...common,
key: "linear_app-issue-created-instant",
name: "New Created Issue (Instant)",
description: "Emit new event when a new issue is created. See the docs [here](https://developers.linear.app/docs/graphql/webhooks)",
description: "Emit new event when a new issue is created. [See the documentation](https://developers.linear.app/docs/graphql/webhooks)",
type: "source",
version: "0.3.6",
version: "0.3.7",
dedupe: "unique",
methods: {
...common.methods,
Expand Down Expand Up @@ -42,6 +42,11 @@ export default {
isRelevant(body) {
return body?.action === "create";
},
getResource(issue) {
return this.linearApp.getIssue({
issueId: issue.id,
});
},
getMetadata(resource) {
const {
delivery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export default {
...common,
key: "linear_app-issue-updated-instant",
name: "New Updated Issue (Instant)",
description: "Emit new event when an issue is updated. See the docs [here](https://developers.linear.app/docs/graphql/webhooks)",
description: "Emit new event when an issue is updated. [See the documentation](https://developers.linear.app/docs/graphql/webhooks)",
type: "source",
version: "0.3.6",
version: "0.3.7",
dedupe: "unique",
methods: {
...common.methods,
Expand Down Expand Up @@ -39,17 +39,22 @@ export default {
},
};
},
getResource(issue) {
return this.linearApp.getIssue({
issueId: issue.id,
});
},
getMetadata(resource) {
const {
delivery,
title,
data,
updatedAt,
} = resource;
const ts = Date.parse(data?.updatedAt || updatedAt);
return {
id: delivery || resource.id,
id: `${resource.id}-${ts}`,
summary: `Issue Updated: ${data?.title || title}`,
ts: Date.parse(updatedAt),
ts,
};
},
},
Expand Down
Loading
Loading