From 634e6a0c5f72f00643c5fe427362ca44464016a1 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Sun, 8 Sep 2024 20:42:02 -0300 Subject: [PATCH 01/13] Docs link updates for sources --- components/github/sources/common/common-flex.mjs | 15 ++++++++++++++- .../github/sources/new-branch/new-branch.mjs | 13 ++++++++----- .../sources/new-collaborator/new-collaborator.mjs | 11 +++++++---- .../new-commit-comment/new-commit-comment.mjs | 11 +++++++---- .../github/sources/new-commit/new-commit.mjs | 11 +++++++---- .../sources/new-discussion/new-discussion.mjs | 11 +++++++---- components/github/sources/new-fork/new-fork.mjs | 11 +++++++---- components/github/sources/new-label/new-label.mjs | 11 +++++++---- .../new-or-updated-issue/new-or-updated-issue.mjs | 13 ++++++++----- .../new-or-updated-milestone.mjs | 13 ++++++++----- .../new-or-updated-pull-request.mjs | 13 ++++++++----- .../github/sources/new-release/new-release.mjs | 11 +++++++---- components/github/sources/new-star/new-star.mjs | 10 +++++++--- 13 files changed, 102 insertions(+), 52 deletions(-) diff --git a/components/github/sources/common/common-flex.mjs b/components/github/sources/common/common-flex.mjs index baaab6643e4a1..df4dfe5095440 100644 --- a/components/github/sources/common/common-flex.mjs +++ b/components/github/sources/common/common-flex.mjs @@ -17,18 +17,24 @@ export default { db: "$.service.db", }, async additionalProps() { + const getDocsInfo = (docsLink) => ({ + type: "alert", + alertType: "info", + content: `[See the GitHub documentation](${docsLink}) for more information on the event format.`, + }); if (await this.checkAdminPermission()) { return { http: { type: "$.interface.http", }, ...this.getHttpAdditionalProps(), + docsInfo: getDocsInfo(this.getHttpDocsLink()), }; } else { return { info: { type: "alert", - alertType: "info", + alertType: "warning", content: "Admin rights on the repo are required in order to register webhooks. In order to continue setting up your source, configure a polling interval below to check for new events.", }, timer: { @@ -38,6 +44,7 @@ export default { }, }, ...this.getTimerAdditionalProps(), + docsInfo: getDocsInfo(this.getTimerDocsLink()), }; } }, @@ -196,6 +203,12 @@ export default { this._setSavedItems(savedItems); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest?apiVersion=2022-11-28"; + }, }, hooks: { async activate() { diff --git a/components/github/sources/new-branch/new-branch.mjs b/components/github/sources/new-branch/new-branch.mjs index 76f705162cde5..f3326221044c7 100644 --- a/components/github/sources/new-branch/new-branch.mjs +++ b/components/github/sources/new-branch/new-branch.mjs @@ -3,14 +3,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = - "https://docs.github.com/en/webhooks/webhook-events-and-payloads#create"; - export default { ...common, key: "github-new-branch", - name: "New Branch", - description: `Emit new event when a branch is created [See the documentation](${DOCS_LINK})`, + name: "New Branch Created", + description: "Emit new event when a branch is created.", version: "1.0.4", type: "source", dedupe: "unique", @@ -35,5 +32,11 @@ export default { getPollingData(args) { return this.github.getBranches(args); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#create"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest/branches/branches?apiVersion=2022-11-28#list-branches"; + }, }, }; diff --git a/components/github/sources/new-collaborator/new-collaborator.mjs b/components/github/sources/new-collaborator/new-collaborator.mjs index 63c6a8e3fb77c..e18b62c14a1ad 100644 --- a/components/github/sources/new-collaborator/new-collaborator.mjs +++ b/components/github/sources/new-collaborator/new-collaborator.mjs @@ -3,14 +3,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = - "https://docs.github.com/en/webhooks/webhook-events-and-payloads#member"; - export default { ...common, key: "github-new-collaborator", name: "New Collaborator", - description: `Emit new event when a collaborator is added [See the documentation](${DOCS_LINK})`, + description: "Emit new event when a collaborator is added", version: "1.0.4", type: "source", dedupe: "unique", @@ -35,5 +32,11 @@ export default { getPollingData(args) { return this.github.getRepositoryLatestCollaborators(args); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#member"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest/collaborators/collaborators?apiVersion=2022-11-28#list-repository-collaborators"; + }, }, }; diff --git a/components/github/sources/new-commit-comment/new-commit-comment.mjs b/components/github/sources/new-commit-comment/new-commit-comment.mjs index 362c4c0d2e8bc..84b7c51581e34 100644 --- a/components/github/sources/new-commit-comment/new-commit-comment.mjs +++ b/components/github/sources/new-commit-comment/new-commit-comment.mjs @@ -3,14 +3,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = - "https://docs.github.com/en/webhooks/webhook-events-and-payloads#commit_comment"; - export default { ...common, key: "github-new-commit-comment", name: "New Commit Comment", - description: `Emit new event when a commit comment is created [See the documentation](${DOCS_LINK})`, + description: "Emit new event when a commit comment is created", version: "1.0.4", type: "source", dedupe: "unique", @@ -35,5 +32,11 @@ export default { getPollingData(args) { return this.github.getRepositoryLatestCommitComments(args); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#commit_comment"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest/commits/comments?apiVersion=2022-11-28#list-commit-comments-for-a-repository"; + }, }, }; diff --git a/components/github/sources/new-commit/new-commit.mjs b/components/github/sources/new-commit/new-commit.mjs index afe52351dd41f..a13b62e05ff16 100644 --- a/components/github/sources/new-commit/new-commit.mjs +++ b/components/github/sources/new-commit/new-commit.mjs @@ -3,14 +3,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = - "https://docs.github.com/en/webhooks/webhook-events-and-payloads#push"; - export default { ...common, key: "github-new-commit", name: "New Commit", - description: `Emit new event when commits are pushed to a branch [See the documentation](${DOCS_LINK})`, + description: "Emit new event when commits are pushed to a branch", version: "1.0.5", type: "source", dedupe: "unique", @@ -95,5 +92,11 @@ export default { this._setSavedItems(savedItems); this._setLastTimestamp(Date.now()); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#push"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-commits"; + }, }, }; diff --git a/components/github/sources/new-discussion/new-discussion.mjs b/components/github/sources/new-discussion/new-discussion.mjs index 24c9fc9420239..c9baf3f6d90b8 100644 --- a/components/github/sources/new-discussion/new-discussion.mjs +++ b/components/github/sources/new-discussion/new-discussion.mjs @@ -3,14 +3,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = - "https://docs.github.com/en/webhooks/webhook-events-and-payloads#discussion"; - export default { ...common, key: "github-new-discussion", name: "New Discussion", - description: `Emit new event when a discussion is created [See the documentation](${DOCS_LINK})`, + description: "Emit new event when a discussion is created", version: "1.0.4", type: "source", dedupe: "unique", @@ -42,5 +39,11 @@ export default { return dateA - dateB; }); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#discussion"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/graphql/reference/objects#discussion"; + }, }, }; diff --git a/components/github/sources/new-fork/new-fork.mjs b/components/github/sources/new-fork/new-fork.mjs index 4f882e5aee7cd..953b15f3ee02c 100644 --- a/components/github/sources/new-fork/new-fork.mjs +++ b/components/github/sources/new-fork/new-fork.mjs @@ -3,14 +3,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = - "https://docs.github.com/en/webhooks/webhook-events-and-payloads#fork"; - export default { ...common, key: "github-new-fork", name: "New Fork", - description: `Emit new event when a repository is forked [See the documentation](${DOCS_LINK})`, + description: "Emit new event when a repository is forked", version: "1.0.4", type: "source", dedupe: "unique", @@ -35,5 +32,11 @@ export default { getPollingData(args) { return this.github.getRepositoryForks(args); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#fork"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest/repos/forks?apiVersion=2022-11-28#list-forks"; + }, }, }; diff --git a/components/github/sources/new-label/new-label.mjs b/components/github/sources/new-label/new-label.mjs index 8a7127bffc9c9..4c06bc4d28815 100644 --- a/components/github/sources/new-label/new-label.mjs +++ b/components/github/sources/new-label/new-label.mjs @@ -3,14 +3,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = - "https://docs.github.com/en/webhooks/webhook-events-and-payloads#label"; - export default { ...common, key: "github-new-label", name: "New Label", - description: `Emit new event when a new label is created [See the documentation](${DOCS_LINK})`, + description: "Emit new event when a new label is created", version: "1.0.4", type: "source", dedupe: "unique", @@ -35,5 +32,11 @@ export default { getPollingData(args) { return this.github.getRepositoryLatestLabels(args); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#label"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest/issues/labels?apiVersion=2022-11-28#list-labels-for-a-repository"; + }, }, }; diff --git a/components/github/sources/new-or-updated-issue/new-or-updated-issue.mjs b/components/github/sources/new-or-updated-issue/new-or-updated-issue.mjs index f3085cc42e434..4e2ad133eb847 100644 --- a/components/github/sources/new-or-updated-issue/new-or-updated-issue.mjs +++ b/components/github/sources/new-or-updated-issue/new-or-updated-issue.mjs @@ -4,14 +4,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = - "https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#issues"; - export default { ...common, key: "github-new-or-updated-issue", name: "New or Updated Issue", - description: `Emit new events when an issue is created or updated [See the documentation](${DOCS_LINK})`, + description: "Emit new events when an issue is created or updated", version: "1.1.1", type: "source", dedupe: "unique", @@ -23,7 +20,7 @@ export default { type: "string[]", label: "Filter Event Types", optional: true, - description: `Specify the type(s) of activity that should emit events. [See the documentation](${DOCS_LINK}) for more information on each type. By default, events will be emitted for all activity.`, + description: "Specify the type(s) of activity that should emit events. By default, events will be emitted for all activity.", options: constants.EVENT_TYPES_ISSUES, }, }; @@ -49,5 +46,11 @@ export default { sort, }); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#issues"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#list-repository-issues"; + }, }, }; diff --git a/components/github/sources/new-or-updated-milestone/new-or-updated-milestone.mjs b/components/github/sources/new-or-updated-milestone/new-or-updated-milestone.mjs index 15fac9a619639..bce8bef94b23e 100644 --- a/components/github/sources/new-or-updated-milestone/new-or-updated-milestone.mjs +++ b/components/github/sources/new-or-updated-milestone/new-or-updated-milestone.mjs @@ -4,14 +4,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = - "https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#milestone"; - export default { ...common, key: "github-new-or-updated-milestone", name: "New or Updated Milestone", - description: `Emit new events when a milestone is created or updated [See the documentation](${DOCS_LINK})`, + description: "Emit new event when a milestone is created or updated", version: "1.1.1", type: "source", dedupe: "unique", @@ -23,7 +20,7 @@ export default { type: "string[]", label: "Filter Event Types", optional: true, - description: `Specify the type(s) of activity that should emit events. [See the documentation](${DOCS_LINK}) for more information on each type. By default, events will be emitted for all activity.`, + description: "Specify the type(s) of activity that should emit events. By default, events will be emitted for all activity.", options: constants.EVENT_TYPES_MILESTONES, }, }; @@ -46,5 +43,11 @@ export default { repoFullname, }); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#milestone"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28#list-milestones"; + }, }, }; diff --git a/components/github/sources/new-or-updated-pull-request/new-or-updated-pull-request.mjs b/components/github/sources/new-or-updated-pull-request/new-or-updated-pull-request.mjs index 6a2100ffc2a0d..5e1e36572fd34 100644 --- a/components/github/sources/new-or-updated-pull-request/new-or-updated-pull-request.mjs +++ b/components/github/sources/new-or-updated-pull-request/new-or-updated-pull-request.mjs @@ -4,14 +4,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = - "https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request"; - export default { ...common, key: "github-new-or-updated-pull-request", name: "New or Updated Pull Request", - description: `Emit new events when a pull request is opened or updated [See the documentation](${DOCS_LINK})`, + description: "Emit new event when a pull request is opened or updated", version: "1.2.1", type: "source", dedupe: "unique", @@ -23,7 +20,7 @@ export default { type: "string[]", label: "Filter Event Types", optional: true, - description: `Specify the type(s) of activity that should emit events. [See the documentation](${DOCS_LINK}) for more information on each type. By default, events will be emitted for all activity.`, + description: "Specify the type(s) of activity that should emit events. By default, events will be emitted for all activity.", options: constants.EVENT_TYPES_PULL_REQUEST, }, }; @@ -49,5 +46,11 @@ export default { sort, }); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28"; + }, }, }; diff --git a/components/github/sources/new-release/new-release.mjs b/components/github/sources/new-release/new-release.mjs index 334e795c9a603..370496a5c4555 100644 --- a/components/github/sources/new-release/new-release.mjs +++ b/components/github/sources/new-release/new-release.mjs @@ -3,14 +3,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = - "https://docs.github.com/en/webhooks/webhook-events-and-payloads#fork"; - export default { ...common, key: "github-new-release", name: "New release", - description: `Emit new event when a new release is created [See the documentation](${DOCS_LINK})`, + description: "Emit new event when a new release is created", version: "1.0.4", type: "source", dedupe: "unique", @@ -38,5 +35,11 @@ export default { per_page: 100, }); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#release"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28"; + }, }, }; diff --git a/components/github/sources/new-star/new-star.mjs b/components/github/sources/new-star/new-star.mjs index f76dbe72e81eb..7aafc7e9ae320 100644 --- a/components/github/sources/new-star/new-star.mjs +++ b/components/github/sources/new-star/new-star.mjs @@ -3,13 +3,11 @@ import { getSampleTimerEvent, getSampleWebhookEvent, } from "./common-sample-events.mjs"; -const DOCS_LINK = "https://docs.github.com/en/webhooks/webhook-events-and-payloads#star"; - export default { ...common, key: "github-new-star", name: "New Stars", - description: `Emit new event when a repository is starred [See the documentation](${DOCS_LINK})`, + description: "Emit new event when a repository is starred", version: "1.0.4", type: "source", dedupe: "unique", @@ -41,5 +39,11 @@ export default { per_page: 100, }); }, + getHttpDocsLink() { + return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#star"; + }, + getTimerDocsLink() { + return "https://docs.github.com/en/rest/activity/starring?apiVersion=2022-11-28#list-stargazers"; + }, }, }; From f44f722a7ed2e32bf515e6c662ec00672e1b6648 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Sun, 8 Sep 2024 21:34:54 -0300 Subject: [PATCH 02/13] Adding docs info alerts --- .../sources/new-commit-comment/new-commit-comment.mjs | 8 ++++++++ components/github/sources/new-commit/new-commit.mjs | 5 +++++ .../github/sources/webhook-events/webhook-events.mjs | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/components/github/sources/new-commit-comment/new-commit-comment.mjs b/components/github/sources/new-commit-comment/new-commit-comment.mjs index 84b7c51581e34..0ebe9c4c73854 100644 --- a/components/github/sources/new-commit-comment/new-commit-comment.mjs +++ b/components/github/sources/new-commit-comment/new-commit-comment.mjs @@ -11,6 +11,14 @@ export default { version: "1.0.4", type: "source", dedupe: "unique", + props: { + eventTypeInfo: { + type: "alert", + alertType: "info", + content: "**Note:** commit comments are not the same as pull request comments. [See the GitHub documentation](https://docs.github.com/en/rest/guides/working-with-comments?apiVersion=2022-11-28) for more information.", + }, + ...common.props, + }, methods: { ...common.methods, getSampleTimerEvent, diff --git a/components/github/sources/new-commit/new-commit.mjs b/components/github/sources/new-commit/new-commit.mjs index a13b62e05ff16..a0347e6f5bdba 100644 --- a/components/github/sources/new-commit/new-commit.mjs +++ b/components/github/sources/new-commit/new-commit.mjs @@ -12,6 +12,11 @@ export default { type: "source", dedupe: "unique", props: { + eventTypeInfo: { + type: "alert", + alertType: "info", + content: "**Note:** one event is emitted for each individual commit, even if they are received at the same time.", + }, ...common.props, branch: { propDefinition: [ diff --git a/components/github/sources/webhook-events/webhook-events.mjs b/components/github/sources/webhook-events/webhook-events.mjs index 21abfd4f6931a..649e980a446c6 100644 --- a/components/github/sources/webhook-events/webhook-events.mjs +++ b/components/github/sources/webhook-events/webhook-events.mjs @@ -10,6 +10,11 @@ export default { type: "source", version: "1.0.4", props: { + docsInfo: { + type: "alert", + alertType: "info", + content: "[See the GitHub documentation](https://docs.github.com/en/webhooks/webhook-events-and-payloads) for more information on available events.", + }, ...common.props, events: { label: "Webhook Events", From 96c8d535e0905907968c3269139167bc057a0b6d Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Sun, 8 Sep 2024 22:44:50 -0300 Subject: [PATCH 03/13] Improvements for common polling interface --- .../github/sources/common/common-polling.mjs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/components/github/sources/common/common-polling.mjs b/components/github/sources/common/common-polling.mjs index 7c58a15f35955..ca5bbd527ebcc 100644 --- a/components/github/sources/common/common-polling.mjs +++ b/components/github/sources/common/common-polling.mjs @@ -12,4 +12,36 @@ export default { }, db: "$.service.db", }, + methods: { + _getSavedIds() { + return this.db.get("savedIds") || []; + }, + _setSavedIds(value) { + this.db.set("savedIds", value); + }, + getItemId(item) { + return item.id; + }, + async getAndProcessData(maxEmits = 0) { + const savedIds = this._getSavedIds(); + const items = await this.getItems(); + + items?.filter?.((item) => !savedIds.includes(this.getItemId(item))).forEach((item, index) => { + if (maxEmits && index < maxEmits) { + this.$emit(item, this.getItemMetadata(item)); + } + savedIds.push(this.getItemId(item)); + }); + + this._setSavedIds(savedIds); + }, + }, + hooks: { + async deploy() { + await this.getAndProcessData(5); + }, + }, + async run() { + await this.getAndProcessData(); + }, }; From 9a35cece0fcb8fcdeb650ac61158a2f14d323a5d Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Mon, 9 Sep 2024 00:36:17 -0300 Subject: [PATCH 04/13] Adjustments to polling --- .../github/sources/common/common-polling.mjs | 7 +++++-- .../new-star-by-user/new-star-by-user.mjs | 20 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/components/github/sources/common/common-polling.mjs b/components/github/sources/common/common-polling.mjs index ca5bbd527ebcc..a6a56840cc9a5 100644 --- a/components/github/sources/common/common-polling.mjs +++ b/components/github/sources/common/common-polling.mjs @@ -27,8 +27,11 @@ export default { const items = await this.getItems(); items?.filter?.((item) => !savedIds.includes(this.getItemId(item))).forEach((item, index) => { - if (maxEmits && index < maxEmits) { - this.$emit(item, this.getItemMetadata(item)); + if ((!maxEmits) || (index < maxEmits)) { + this.$emit(item, { + id: this.getItemId(item), + ...this.getItemMetadata(item), + }); } savedIds.push(this.getItemId(item)); }); diff --git a/components/github/sources/new-star-by-user/new-star-by-user.mjs b/components/github/sources/new-star-by-user/new-star-by-user.mjs index d969eaed8570a..688f2a5f4358c 100644 --- a/components/github/sources/new-star-by-user/new-star-by-user.mjs +++ b/components/github/sources/new-star-by-user/new-star-by-user.mjs @@ -4,7 +4,7 @@ export default { ...common, key: "github-new-star-by-user", name: "New Star By User", - description: "Emit new events when the specified user stars a repository", + description: "Emit new events when the specified user stars a repository. [See the documentation](https://docs.github.com/en/rest/activity/starring?apiVersion=2022-11-28#list-repositories-starred-by-a-user)", version: "0.0.4", type: "source", dedupe: "unique", @@ -23,17 +23,15 @@ export default { const response = await this.github._client().request(`GET /users/${user}/starred`); return response.data; }, - }, - async run() { - const user = this.user ?? (await this.github.getAuthenticatedUser()).login; - const stars = await this.getUserStars(user); - - stars?.forEach((star) => { - this.$emit(star, { - id: star.id, + async getItems() { + const user = this.user ?? (await this.github.getAuthenticatedUser()).login; + return this.getUserStars(user); + }, + getItemMetadata(star) { + return { summary: `New star: ${star.full_name}`, ts: Date.now(), - }); - }); + }; + }, }, }; From 1dc80069b25e7b2ef516b41449345f0ae148d655 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Mon, 9 Sep 2024 10:31:01 -0300 Subject: [PATCH 05/13] Improving polling sources --- .../github/sources/new-gist/new-gist.mjs | 23 +++++++------- .../sources/new-mention/new-mention.mjs | 3 +- .../new-notification/new-notification.mjs | 31 ++++++++++--------- .../new-organization/new-organization.mjs | 23 +++++++------- .../sources/new-repository/new-repository.mjs | 2 +- .../new-star-by-user/new-star-by-user.mjs | 4 +-- .../github/sources/new-team/new-team.mjs | 23 +++++++------- 7 files changed, 57 insertions(+), 52 deletions(-) diff --git a/components/github/sources/new-gist/new-gist.mjs b/components/github/sources/new-gist/new-gist.mjs index a74f5fbb05319..42e26fb9e23b4 100644 --- a/components/github/sources/new-gist/new-gist.mjs +++ b/components/github/sources/new-gist/new-gist.mjs @@ -4,19 +4,20 @@ export default { ...common, key: "github-new-gist", name: "New Gist", - description: "Emit new events when new gists are created by the authenticated user", + description: "Emit new events when new gists are created by the authenticated user. [See the documentatoion](https://docs.github.com/en/rest/gists/gists?apiVersion=2022-11-28#list-gists-for-the-authenticated-user)", version: "0.1.17", type: "source", dedupe: "unique", - async run() { - const gists = await this.github.getGists(); - - gists.map((gist) => { - this.$emit(gist, { - id: gist.id, - summary: `New gist ${gist.id}`, - ts: Date.parse(gist.created_at), - }); - }); + methods: { + ...common.methods, + async getItems() { + return this.github.getGists(); + }, + getItemMetadata(item) { + return { + summary: `New gist: ${item.id}`, + ts: Date.parse(item.created_at), + }; + }, }, }; diff --git a/components/github/sources/new-mention/new-mention.mjs b/components/github/sources/new-mention/new-mention.mjs index f3ed4b7dfcf89..e4fbee7df573d 100644 --- a/components/github/sources/new-mention/new-mention.mjs +++ b/components/github/sources/new-mention/new-mention.mjs @@ -4,10 +4,11 @@ export default { ...common, key: "github-new-mention", name: "New Mention", - description: "Emit new events when you are @mentioned in a new commit, comment, issue or pull request", + description: "Emit new event when you are @mentioned in a new commit, comment, issue or pull request. [See the documentation](https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user)", version: "0.1.18", type: "source", hooks: { + ...common.hooks, async activate() { const user = await this.github.getAuthenticatedUser(); this._setUserLogin(user.login); diff --git a/components/github/sources/new-notification/new-notification.mjs b/components/github/sources/new-notification/new-notification.mjs index a8121547e1be3..db7f6ea35a00f 100644 --- a/components/github/sources/new-notification/new-notification.mjs +++ b/components/github/sources/new-notification/new-notification.mjs @@ -4,24 +4,25 @@ export default { ...common, key: "github-new-notification", name: "New Notification", - description: "Emit new events when you received a new notification", + description: "Emit new event when the authenticated user receives a new notification. [See the documentation](https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user)", version: "0.1.17", type: "source", dedupe: "unique", - async run() { - const notifications = await this.github.getFilteredNotifications({ - data: { - participating: true, - all: true, - }, - }); - - notifications.map((notification) => { - this.$emit(notification, { - id: notification.id, - summary: `New notification ${notification.id}`, - ts: Date.parse(notification.created_at), + methods: { + ...common.methods, + async getItems() { + return this.github.getFilteredNotifications({ + data: { + participating: true, + all: true, + }, }); - }); + }, + getItemMetadata(item) { + return { + summary: `New notification: ${item.id}`, + ts: Date.parse(item.created_at), + }; + }, }, }; diff --git a/components/github/sources/new-organization/new-organization.mjs b/components/github/sources/new-organization/new-organization.mjs index d16c5594971f1..45feb8dac6f6d 100644 --- a/components/github/sources/new-organization/new-organization.mjs +++ b/components/github/sources/new-organization/new-organization.mjs @@ -4,19 +4,20 @@ export default { ...common, key: "github-new-organization", name: "New Organization", - description: "Emit new events when the authenticated user is added to a new organization", + description: "Emit new event when the authenticated user is added to a new organization. [See the documentation](https://docs.github.com/en/rest/orgs/orgs?apiVersion=2022-11-28#list-organizations-for-the-authenticated-user)", version: "0.1.17", type: "source", dedupe: "unique", - async run() { - const organizations = await this.github.getOrganizations(); - - organizations.map((organization) => { - this.$emit(organization, { - id: organization.id, - summary: `New organization ${organization.id}`, - ts: new Date(), - }); - }); + methods: { + ...common.methods, + async getItems() { + return this.github.getOrganizations(); + }, + getItemMetadata(item) { + return { + summary: `New organization: "${item.login}"`, + ts: Date.now(), + }; + }, }, }; diff --git a/components/github/sources/new-repository/new-repository.mjs b/components/github/sources/new-repository/new-repository.mjs index 085e47ab63c71..e7ee734f5844c 100644 --- a/components/github/sources/new-repository/new-repository.mjs +++ b/components/github/sources/new-repository/new-repository.mjs @@ -4,7 +4,7 @@ export default { ...common, key: "github-new-repository", name: "New Repository", - description: "Emit new events when new repositories are created", + description: "Emit new event when a new repository is created or when the authenticated user receives access. [See the documentation](https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repositories-for-the-authenticated-user)", version: "0.1.17", type: "source", dedupe: "unique", diff --git a/components/github/sources/new-star-by-user/new-star-by-user.mjs b/components/github/sources/new-star-by-user/new-star-by-user.mjs index 688f2a5f4358c..1dc301eb8a5cf 100644 --- a/components/github/sources/new-star-by-user/new-star-by-user.mjs +++ b/components/github/sources/new-star-by-user/new-star-by-user.mjs @@ -27,9 +27,9 @@ export default { const user = this.user ?? (await this.github.getAuthenticatedUser()).login; return this.getUserStars(user); }, - getItemMetadata(star) { + getItemMetadata(item) { return { - summary: `New star: ${star.full_name}`, + summary: `New star: ${item.full_name}`, ts: Date.now(), }; }, diff --git a/components/github/sources/new-team/new-team.mjs b/components/github/sources/new-team/new-team.mjs index e51a212c11b81..6a9f4729b7463 100644 --- a/components/github/sources/new-team/new-team.mjs +++ b/components/github/sources/new-team/new-team.mjs @@ -4,19 +4,20 @@ export default { ...common, key: "github-new-team", name: "New Team", - description: "Emit new events when the user is added to a new team", + description: "Emit new event when the authenticated user is added to a new team. [See the documentation](https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#list-teams-for-the-authenticated-user)", version: "0.1.17", type: "source", dedupe: "unique", - async run() { - const teams = await this.github.getTeams(); - - teams.map((team) => { - this.$emit(team, { - id: team.id, - summary: `New team ${team.id}`, - ts: Date.parse(team.created_at), - }); - }); + methods: { + ...common.methods, + async getItems() { + return this.github.getTeams(); + }, + getItemMetadata(item) { + return { + summary: `New team: "${item.name ?? item.slug}"`, + ts: Date.now(), + }; + }, }, }; From 7ad2b8a074c7d8b573907cb5b74506b2561a9ff9 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Mon, 9 Sep 2024 22:15:29 -0300 Subject: [PATCH 06/13] New Repository improvements --- .../sources/new-repository/new-repository.mjs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/components/github/sources/new-repository/new-repository.mjs b/components/github/sources/new-repository/new-repository.mjs index e7ee734f5844c..fd9c678415750 100644 --- a/components/github/sources/new-repository/new-repository.mjs +++ b/components/github/sources/new-repository/new-repository.mjs @@ -8,15 +8,16 @@ export default { version: "0.1.17", type: "source", dedupe: "unique", - async run() { - const repositories = await this.github.getRepos(); - - repositories.map((repository) => { - this.$emit(repository, { - id: repository.id, - summary: `New repository ${repository.id}`, - ts: Date.parse(repository.created_at), - }); - }); + methods: { + ...common.methods, + async getItems() { + return this.github.getRepos(); + }, + getItemMetadata(item) { + return { + summary: `New repository: "${item.full_name}"`, + ts: Date.now(), + }; + }, }, }; From 3a0ad83d3b9adead8abe3576b0afebb6a533bd02 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Tue, 10 Sep 2024 02:56:44 -0300 Subject: [PATCH 07/13] Common interface for PR notifications sources --- .../common-polling-pr-notifications.mjs | 32 +++++++++++++++ .../new-review-request/new-review-request.mjs | 41 ++++++++----------- .../new-security-alert/new-security-alert.mjs | 2 +- 3 files changed, 51 insertions(+), 24 deletions(-) create mode 100644 components/github/sources/common/common-polling-pr-notifications.mjs diff --git a/components/github/sources/common/common-polling-pr-notifications.mjs b/components/github/sources/common/common-polling-pr-notifications.mjs new file mode 100644 index 0000000000000..8849c72da3e31 --- /dev/null +++ b/components/github/sources/common/common-polling-pr-notifications.mjs @@ -0,0 +1,32 @@ +import common from "./common/common-polling.mjs"; + +export default { + ...common, + async run(maxEmits = 0) { + const savedIds = this._getSavedIds(); + const items = await this.getItems(); + + const allPrData = new Map(); + + items?. + filter?.((item) => !savedIds.includes(this.getItemId(item))) + .forEach(async (item, index) => { + if (item?.subject?.notification !== null && ((!maxEmits) || (index < maxEmits))) { + const url = item.subject.url; + if (!allPrData.has(url)) { + allPrData.set(url, await this.github.getFromUrl({ + url: item.subject.url, + })); + } + const pullRequest = allPrData.get(url); + this.$emit(pullRequest, { + id: pullRequest.id, + ...this.getItemMetadata(item), + }); + } + savedIds.push(this.getItemId(item)); + }); + + this._setSavedIds(savedIds); + }, +}; diff --git a/components/github/sources/new-review-request/new-review-request.mjs b/components/github/sources/new-review-request/new-review-request.mjs index 9928ca3dc8f90..f54a374b8913c 100644 --- a/components/github/sources/new-review-request/new-review-request.mjs +++ b/components/github/sources/new-review-request/new-review-request.mjs @@ -1,34 +1,29 @@ -import common from "../common/common-polling.mjs"; +import common from "../common/common-polling-pr-notifications.mjs"; export default { ...common, key: "github-new-review-request", name: "New Review Request", - description: "Emit new events when you or a team you're a member of are requested to review a pull request", + description: "Emit new event for new review request notifications. [See the documentation](https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user)", version: "0.1.17", type: "source", dedupe: "unique", - async run() { - const notifications = await this.github.getFilteredNotifications({ - reason: "review_requested", - data: { - participating: true, - all: true, - }, - }); - - for (const notification of notifications) { - if (notification.subject.notification === null) continue; - - const pullRequest = await this.github.getFromUrl({ - url: notification.subject.url, - }); - - this.$emit(pullRequest, { - id: pullRequest.id, - summary: `New notification ${pullRequest.id}`, - ts: Date.parse(pullRequest.created_at), + methods: { + ...common.methods, + async getItems() { + return this.github.getFilteredNotifications({ + reason: "review_requested", + data: { + participating: true, + all: true, + }, }); - } + }, + getItemMetadata(item) { + return { + summary: `New review request: ${item.title ?? item.id}`, + ts: Date.now(), + }; + }, }, }; diff --git a/components/github/sources/new-security-alert/new-security-alert.mjs b/components/github/sources/new-security-alert/new-security-alert.mjs index f5d0ebabcd44b..769ffc7d8516d 100644 --- a/components/github/sources/new-security-alert/new-security-alert.mjs +++ b/components/github/sources/new-security-alert/new-security-alert.mjs @@ -4,7 +4,7 @@ export default { ...common, key: "github-new-security-alert", name: "New Security Alert", - description: "Emit new events when GitHub discovers a security vulnerability in one of your repositories", + description: "Emit new event for security alert notifications. [See the documentation](https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user)", version: "0.1.19", type: "source", dedupe: "unique", From a001d44c016dd1d6bb86dbb532c1360eb838bb98 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Tue, 10 Sep 2024 03:03:17 -0300 Subject: [PATCH 08/13] Reusing base for new security alert --- .../common-polling-pr-notifications.mjs | 2 +- .../new-security-alert/new-security-alert.mjs | 37 ++++++++----------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/components/github/sources/common/common-polling-pr-notifications.mjs b/components/github/sources/common/common-polling-pr-notifications.mjs index 8849c72da3e31..ae5dd16e4a507 100644 --- a/components/github/sources/common/common-polling-pr-notifications.mjs +++ b/components/github/sources/common/common-polling-pr-notifications.mjs @@ -1,4 +1,4 @@ -import common from "./common/common-polling.mjs"; +import common from "./common-polling.mjs"; export default { ...common, diff --git a/components/github/sources/new-security-alert/new-security-alert.mjs b/components/github/sources/new-security-alert/new-security-alert.mjs index 769ffc7d8516d..4c7f809dcf589 100644 --- a/components/github/sources/new-security-alert/new-security-alert.mjs +++ b/components/github/sources/new-security-alert/new-security-alert.mjs @@ -8,27 +8,22 @@ export default { version: "0.1.19", type: "source", dedupe: "unique", - async run() { - const notifications = await this.github.getFilteredNotifications({ - reason: "security_alert", - data: { - participating: true, - all: true, - }, - }); - - for (const notification of notifications) { - if (notification.subject.notification === null) continue; - - const pullRequest = await this.github.getFromUrl({ - url: notification.subject.url, - }); - - this.$emit(pullRequest, { - id: pullRequest.id, - summary: `New notification ${pullRequest.id}`, - ts: Date.parse(pullRequest.created_at), + methods: { + ...common.methods, + async getItems() { + return this.github.getFilteredNotifications({ + reason: "security_alert", + data: { + participating: true, + all: true, + }, }); - } + }, + getItemMetadata(item) { + return { + summary: `New security alert: ${item.title ?? item.id}`, + ts: Date.now(), + }; + }, }, }; From 4514224198d9b012844950581832c9ddc7ae8388 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Wed, 11 Sep 2024 04:22:14 -0300 Subject: [PATCH 09/13] "New mention" rewrite + adjustments --- .../common-polling-pr-notifications.mjs | 24 +++-- .../sources/new-mention/new-mention.mjs | 99 ++++++++++++------- 2 files changed, 79 insertions(+), 44 deletions(-) diff --git a/components/github/sources/common/common-polling-pr-notifications.mjs b/components/github/sources/common/common-polling-pr-notifications.mjs index ae5dd16e4a507..eb4e871bbf65b 100644 --- a/components/github/sources/common/common-polling-pr-notifications.mjs +++ b/components/github/sources/common/common-polling-pr-notifications.mjs @@ -6,23 +6,27 @@ export default { const savedIds = this._getSavedIds(); const items = await this.getItems(); - const allPrData = new Map(); + const urlData = new Map(); + let amountEmits = 0; items?. filter?.((item) => !savedIds.includes(this.getItemId(item))) - .forEach(async (item, index) => { - if (item?.subject?.notification !== null && ((!maxEmits) || (index < maxEmits))) { + .forEach(async (item) => { + if (item?.subject?.notification !== null) { const url = item.subject.url; - if (!allPrData.has(url)) { - allPrData.set(url, await this.github.getFromUrl({ + if (!urlData.has(url)) { + urlData.set(url, await this.github.getFromUrl({ url: item.subject.url, })); } - const pullRequest = allPrData.get(url); - this.$emit(pullRequest, { - id: pullRequest.id, - ...this.getItemMetadata(item), - }); + const pullRequest = urlData.get(url); + if (!maxEmits || (amountEmits < maxEmits)) { + this.$emit(pullRequest, { + id: pullRequest.id, + ...this.getItemMetadata(item), + }); + amountEmits++; + } } savedIds.push(this.getItemId(item)); }); diff --git a/components/github/sources/new-mention/new-mention.mjs b/components/github/sources/new-mention/new-mention.mjs index e4fbee7df573d..a3bf892cbfc28 100644 --- a/components/github/sources/new-mention/new-mention.mjs +++ b/components/github/sources/new-mention/new-mention.mjs @@ -7,13 +7,6 @@ export default { description: "Emit new event when you are @mentioned in a new commit, comment, issue or pull request. [See the documentation](https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user)", version: "0.1.18", type: "source", - hooks: { - ...common.hooks, - async activate() { - const user = await this.github.getAuthenticatedUser(); - this._setUserLogin(user.login); - }, - }, dedupe: "unique", methods: { ...common.methods, @@ -23,38 +16,76 @@ export default { _setUserLogin(userLogin) { this.db.set("userLogin", userLogin); }, + _getEmittedIds() { + return this.db.get("emittedIds") ?? []; + }, + _setEmittedIds(value) { + this.db.set("emittedIds", value); + }, + async retrieveUserLogin() { + let login = this._getUserLogin(); + if (!login) { + const user = await this.github.getAuthenticatedUser(); + login = user.login; + this._setUserLogin(login); + } + return login; + }, + async getItems() { + return this.github.getFilteredNotifications({ + reason: "mention", + data: { + participating: true, + all: true, + }, + }); + }, }, - async run() { - const login = this._getUserLogin(); - - const notifications = await this.github.getFilteredNotifications({ - reason: "mention", - data: { - participating: true, - all: true, - }, - }); + async run(maxEmits = 0) { + const login = this.retrieveUserLogin(); + const savedIds = this._getSavedIds(); + const emittedIds = this._getEmittedIds(); + const items = await this.getItems(); - for (const notification of notifications) { - const subject = await this.github.getFromUrl({ - url: notification?.subject?.url, - }); + const urlData = new Map(); + let amountEmits = 0; - if (!subject.comments_url) continue; + items?. + filter?.(({ id }) => !savedIds.includes(id)) + .forEach(async (item) => { + const url = item?.subject?.url; + if (!urlData.has(url)) { + urlData.set(url, await this.github.getFromUrl({ + url: item.subject.url, + })); + } + const subject = urlData.get(url); + const commentsUrl = subject.comments_url; + if (!commentsUrl) return; - const comments = await this.github.getFromUrl({ - url: subject.comments_url, + if (!urlData.has(commentsUrl)) { + urlData.set(commentsUrl, await this.github.getFromUrl({ + url: commentsUrl, + })); + } + const comments = urlData.get(commentsUrl); + comments?.filter?.((comment) => { + return !emittedIds.includes(comment.id) && comment.body?.includes(`@${login}`); + }).forEach((comment) => { + if (!maxEmits || (amountEmits < maxEmits)) { + this.$emit(comment, { + id: comment.id, + summary: `New mention: ${comment.id}`, + ts: Date.parse(comment.created_at), + }); + amountEmits++; + } + emittedIds.push(comment.id); + }); + savedIds.push(this.getItemId(item)); }); - for (const comment of comments) { - if (comment?.body?.includes(`@${login}`)) { - this.$emit(comment, { - id: comment.id, - summary: `New notification ${comment.id}`, - ts: Date.parse(comment.created_at), - }); - } - } - } + this._setEmittedIds(emittedIds); + this._setSavedIds(savedIds); }, }; From 9e1b303f3d3725d422cdc56a044fed2d602ad37a Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Wed, 11 Sep 2024 04:39:45 -0300 Subject: [PATCH 10/13] Behavior adjustments to notification sources --- .../common-polling-pr-notifications.mjs | 57 ++++++++++--------- .../new-review-request/new-review-request.mjs | 2 +- .../new-security-alert/new-security-alert.mjs | 2 +- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/components/github/sources/common/common-polling-pr-notifications.mjs b/components/github/sources/common/common-polling-pr-notifications.mjs index eb4e871bbf65b..e971d806038b7 100644 --- a/components/github/sources/common/common-polling-pr-notifications.mjs +++ b/components/github/sources/common/common-polling-pr-notifications.mjs @@ -2,35 +2,40 @@ import common from "./common-polling.mjs"; export default { ...common, - async run(maxEmits = 0) { - const savedIds = this._getSavedIds(); - const items = await this.getItems(); + methods: { + ...common.methods, + async getAndProcessData(maxEmits = 0) { + const savedIds = this._getSavedIds(); + const items = await this.getItems(); - const urlData = new Map(); - let amountEmits = 0; + const urlData = new Map(); + let amountEmits = 0; - items?. - filter?.((item) => !savedIds.includes(this.getItemId(item))) - .forEach(async (item) => { - if (item?.subject?.notification !== null) { - const url = item.subject.url; - if (!urlData.has(url)) { - urlData.set(url, await this.github.getFromUrl({ - url: item.subject.url, - })); + const promises = items?. + filter?.((item) => !savedIds.includes(this.getItemId(item))) + .map((item) => (async () => { + if (item?.subject?.notification !== null) { + const url = item.subject.url; + if (!urlData.has(url)) { + urlData.set(url, await this.github.getFromUrl({ + url: item.subject.url, + })); + } + const pullRequest = urlData.get(url); + if (!maxEmits || (amountEmits < maxEmits)) { + this.$emit(pullRequest, { + id: pullRequest.id, + ...this.getItemMetadata(pullRequest), + }); + amountEmits++; + } } - const pullRequest = urlData.get(url); - if (!maxEmits || (amountEmits < maxEmits)) { - this.$emit(pullRequest, { - id: pullRequest.id, - ...this.getItemMetadata(item), - }); - amountEmits++; - } - } - savedIds.push(this.getItemId(item)); - }); + savedIds.push(this.getItemId(item)); + })()); + + if (promises?.length) await Promise.allSettled(promises); - this._setSavedIds(savedIds); + this._setSavedIds(savedIds); + }, }, }; diff --git a/components/github/sources/new-review-request/new-review-request.mjs b/components/github/sources/new-review-request/new-review-request.mjs index f54a374b8913c..9e227bd9edd92 100644 --- a/components/github/sources/new-review-request/new-review-request.mjs +++ b/components/github/sources/new-review-request/new-review-request.mjs @@ -21,7 +21,7 @@ export default { }, getItemMetadata(item) { return { - summary: `New review request: ${item.title ?? item.id}`, + summary: `New review request: "${item.title ?? item.id}"`, ts: Date.now(), }; }, diff --git a/components/github/sources/new-security-alert/new-security-alert.mjs b/components/github/sources/new-security-alert/new-security-alert.mjs index 4c7f809dcf589..55f122054f1e4 100644 --- a/components/github/sources/new-security-alert/new-security-alert.mjs +++ b/components/github/sources/new-security-alert/new-security-alert.mjs @@ -21,7 +21,7 @@ export default { }, getItemMetadata(item) { return { - summary: `New security alert: ${item.title ?? item.id}`, + summary: `New security alert: "${item.title ?? item.id}"`, ts: Date.now(), }; }, From 7498588df4a2800c991af629f1383945bffda779 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Wed, 11 Sep 2024 05:05:58 -0300 Subject: [PATCH 11/13] Adjustments for mentions --- .../sources/new-mention/new-mention.mjs | 44 ++++++++++--------- .../new-review-request/new-review-request.mjs | 11 +++++ 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/components/github/sources/new-mention/new-mention.mjs b/components/github/sources/new-mention/new-mention.mjs index a3bf892cbfc28..663479f5697b9 100644 --- a/components/github/sources/new-mention/new-mention.mjs +++ b/components/github/sources/new-mention/new-mention.mjs @@ -16,11 +16,11 @@ export default { _setUserLogin(userLogin) { this.db.set("userLogin", userLogin); }, - _getEmittedIds() { - return this.db.get("emittedIds") ?? []; + _getLastDate() { + return this.db.get("lastDate"); }, - _setEmittedIds(value) { - this.db.set("emittedIds", value); + _setLastDate(value) { + this.db.set("lastDate", value); }, async retrieveUserLogin() { let login = this._getUserLogin(); @@ -32,27 +32,28 @@ export default { return login; }, async getItems() { + const date = this._getLastDate(); + this._setLastDate(new Date().toISOString()); return this.github.getFilteredNotifications({ reason: "mention", data: { participating: true, all: true, + ...(date && { + since: date, + }), }, }); }, - }, - async run(maxEmits = 0) { - const login = this.retrieveUserLogin(); - const savedIds = this._getSavedIds(); - const emittedIds = this._getEmittedIds(); - const items = await this.getItems(); + async getAndProcessData(maxEmits = 0) { + const login = await this.retrieveUserLogin(); + const savedIds = this._getSavedIds(); + const items = await this.getItems(); - const urlData = new Map(); - let amountEmits = 0; + const urlData = new Map(); + let amountEmits = 0; - items?. - filter?.(({ id }) => !savedIds.includes(id)) - .forEach(async (item) => { + const promises = items?.map((item) => (async () => { const url = item?.subject?.url; if (!urlData.has(url)) { urlData.set(url, await this.github.getFromUrl({ @@ -70,7 +71,7 @@ export default { } const comments = urlData.get(commentsUrl); comments?.filter?.((comment) => { - return !emittedIds.includes(comment.id) && comment.body?.includes(`@${login}`); + return !savedIds.includes(comment.id) && comment.body?.includes(`@${login}`); }).forEach((comment) => { if (!maxEmits || (amountEmits < maxEmits)) { this.$emit(comment, { @@ -80,12 +81,13 @@ export default { }); amountEmits++; } - emittedIds.push(comment.id); + savedIds.push(comment.id); }); - savedIds.push(this.getItemId(item)); - }); + })()); - this._setEmittedIds(emittedIds); - this._setSavedIds(savedIds); + if (promises?.length) await Promise.allSettled(promises); + + this._setSavedIds(savedIds); + }, }, }; diff --git a/components/github/sources/new-review-request/new-review-request.mjs b/components/github/sources/new-review-request/new-review-request.mjs index 9e227bd9edd92..bd6056c34d778 100644 --- a/components/github/sources/new-review-request/new-review-request.mjs +++ b/components/github/sources/new-review-request/new-review-request.mjs @@ -10,12 +10,23 @@ export default { dedupe: "unique", methods: { ...common.methods, + _getLastDate() { + return this.db.get("lastDate"); + }, + _setLastDate(value) { + this.db.set("lastDate", value); + }, async getItems() { + const date = this._getLastDate(); + this._setLastDate(new Date().toISOString()); return this.github.getFilteredNotifications({ reason: "review_requested", data: { participating: true, all: true, + ...(date && { + since: date, + }), }, }); }, From 22cf04551a1b5a9bc8a76fb1e35d821a1a288c50 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Wed, 11 Sep 2024 05:09:25 -0300 Subject: [PATCH 12/13] Version bumps --- components/github/package.json | 2 +- components/github/sources/new-branch/new-branch.mjs | 2 +- components/github/sources/new-collaborator/new-collaborator.mjs | 2 +- .../github/sources/new-commit-comment/new-commit-comment.mjs | 2 +- components/github/sources/new-commit/new-commit.mjs | 2 +- components/github/sources/new-discussion/new-discussion.mjs | 2 +- components/github/sources/new-fork/new-fork.mjs | 2 +- components/github/sources/new-gist/new-gist.mjs | 2 +- components/github/sources/new-label/new-label.mjs | 2 +- components/github/sources/new-mention/new-mention.mjs | 2 +- components/github/sources/new-notification/new-notification.mjs | 2 +- .../sources/new-or-updated-issue/new-or-updated-issue.mjs | 2 +- .../new-or-updated-milestone/new-or-updated-milestone.mjs | 2 +- .../new-or-updated-pull-request/new-or-updated-pull-request.mjs | 2 +- components/github/sources/new-organization/new-organization.mjs | 2 +- components/github/sources/new-repository/new-repository.mjs | 2 +- .../github/sources/new-review-request/new-review-request.mjs | 2 +- .../github/sources/new-security-alert/new-security-alert.mjs | 2 +- components/github/sources/new-star-by-user/new-star-by-user.mjs | 2 +- components/github/sources/new-star/new-star.mjs | 2 +- components/github/sources/new-team/new-team.mjs | 2 +- components/github/sources/webhook-events/webhook-events.mjs | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/components/github/package.json b/components/github/package.json index 9330129886223..9c9555b2c0a24 100644 --- a/components/github/package.json +++ b/components/github/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/github", - "version": "1.3.0", + "version": "1.4.0", "description": "Pipedream Github Components", "main": "github.app.mjs", "keywords": [ diff --git a/components/github/sources/new-branch/new-branch.mjs b/components/github/sources/new-branch/new-branch.mjs index f3326221044c7..15a0324a2b253 100644 --- a/components/github/sources/new-branch/new-branch.mjs +++ b/components/github/sources/new-branch/new-branch.mjs @@ -8,7 +8,7 @@ export default { key: "github-new-branch", name: "New Branch Created", description: "Emit new event when a branch is created.", - version: "1.0.4", + version: "1.0.5", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-collaborator/new-collaborator.mjs b/components/github/sources/new-collaborator/new-collaborator.mjs index e18b62c14a1ad..97e4d83a7b6df 100644 --- a/components/github/sources/new-collaborator/new-collaborator.mjs +++ b/components/github/sources/new-collaborator/new-collaborator.mjs @@ -8,7 +8,7 @@ export default { key: "github-new-collaborator", name: "New Collaborator", description: "Emit new event when a collaborator is added", - version: "1.0.4", + version: "1.0.5", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-commit-comment/new-commit-comment.mjs b/components/github/sources/new-commit-comment/new-commit-comment.mjs index 0ebe9c4c73854..418601cfbf92b 100644 --- a/components/github/sources/new-commit-comment/new-commit-comment.mjs +++ b/components/github/sources/new-commit-comment/new-commit-comment.mjs @@ -8,7 +8,7 @@ export default { key: "github-new-commit-comment", name: "New Commit Comment", description: "Emit new event when a commit comment is created", - version: "1.0.4", + version: "1.0.5", type: "source", dedupe: "unique", props: { diff --git a/components/github/sources/new-commit/new-commit.mjs b/components/github/sources/new-commit/new-commit.mjs index a0347e6f5bdba..eb1c6332b7be3 100644 --- a/components/github/sources/new-commit/new-commit.mjs +++ b/components/github/sources/new-commit/new-commit.mjs @@ -8,7 +8,7 @@ export default { key: "github-new-commit", name: "New Commit", description: "Emit new event when commits are pushed to a branch", - version: "1.0.5", + version: "1.0.6", type: "source", dedupe: "unique", props: { diff --git a/components/github/sources/new-discussion/new-discussion.mjs b/components/github/sources/new-discussion/new-discussion.mjs index c9baf3f6d90b8..c4295dccb2e7f 100644 --- a/components/github/sources/new-discussion/new-discussion.mjs +++ b/components/github/sources/new-discussion/new-discussion.mjs @@ -8,7 +8,7 @@ export default { key: "github-new-discussion", name: "New Discussion", description: "Emit new event when a discussion is created", - version: "1.0.4", + version: "1.0.5", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-fork/new-fork.mjs b/components/github/sources/new-fork/new-fork.mjs index 953b15f3ee02c..c702ccc5d2cf8 100644 --- a/components/github/sources/new-fork/new-fork.mjs +++ b/components/github/sources/new-fork/new-fork.mjs @@ -8,7 +8,7 @@ export default { key: "github-new-fork", name: "New Fork", description: "Emit new event when a repository is forked", - version: "1.0.4", + version: "1.0.5", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-gist/new-gist.mjs b/components/github/sources/new-gist/new-gist.mjs index 42e26fb9e23b4..5d580c57640b8 100644 --- a/components/github/sources/new-gist/new-gist.mjs +++ b/components/github/sources/new-gist/new-gist.mjs @@ -5,7 +5,7 @@ export default { key: "github-new-gist", name: "New Gist", description: "Emit new events when new gists are created by the authenticated user. [See the documentatoion](https://docs.github.com/en/rest/gists/gists?apiVersion=2022-11-28#list-gists-for-the-authenticated-user)", - version: "0.1.17", + version: "0.2.0", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-label/new-label.mjs b/components/github/sources/new-label/new-label.mjs index 4c06bc4d28815..35d116c44f2cb 100644 --- a/components/github/sources/new-label/new-label.mjs +++ b/components/github/sources/new-label/new-label.mjs @@ -8,7 +8,7 @@ export default { key: "github-new-label", name: "New Label", description: "Emit new event when a new label is created", - version: "1.0.4", + version: "1.0.5", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-mention/new-mention.mjs b/components/github/sources/new-mention/new-mention.mjs index 663479f5697b9..40c2e3939bc29 100644 --- a/components/github/sources/new-mention/new-mention.mjs +++ b/components/github/sources/new-mention/new-mention.mjs @@ -5,7 +5,7 @@ export default { key: "github-new-mention", name: "New Mention", description: "Emit new event when you are @mentioned in a new commit, comment, issue or pull request. [See the documentation](https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user)", - version: "0.1.18", + version: "0.2.0", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-notification/new-notification.mjs b/components/github/sources/new-notification/new-notification.mjs index db7f6ea35a00f..c5c3b579c52a7 100644 --- a/components/github/sources/new-notification/new-notification.mjs +++ b/components/github/sources/new-notification/new-notification.mjs @@ -5,7 +5,7 @@ export default { key: "github-new-notification", name: "New Notification", description: "Emit new event when the authenticated user receives a new notification. [See the documentation](https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user)", - version: "0.1.17", + version: "0.2.0", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-or-updated-issue/new-or-updated-issue.mjs b/components/github/sources/new-or-updated-issue/new-or-updated-issue.mjs index 4e2ad133eb847..884d927ad03b9 100644 --- a/components/github/sources/new-or-updated-issue/new-or-updated-issue.mjs +++ b/components/github/sources/new-or-updated-issue/new-or-updated-issue.mjs @@ -9,7 +9,7 @@ export default { key: "github-new-or-updated-issue", name: "New or Updated Issue", description: "Emit new events when an issue is created or updated", - version: "1.1.1", + version: "1.1.2", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-or-updated-milestone/new-or-updated-milestone.mjs b/components/github/sources/new-or-updated-milestone/new-or-updated-milestone.mjs index bce8bef94b23e..7a27786dd7f9a 100644 --- a/components/github/sources/new-or-updated-milestone/new-or-updated-milestone.mjs +++ b/components/github/sources/new-or-updated-milestone/new-or-updated-milestone.mjs @@ -9,7 +9,7 @@ export default { key: "github-new-or-updated-milestone", name: "New or Updated Milestone", description: "Emit new event when a milestone is created or updated", - version: "1.1.1", + version: "1.1.2", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-or-updated-pull-request/new-or-updated-pull-request.mjs b/components/github/sources/new-or-updated-pull-request/new-or-updated-pull-request.mjs index 5e1e36572fd34..68683030f3bc7 100644 --- a/components/github/sources/new-or-updated-pull-request/new-or-updated-pull-request.mjs +++ b/components/github/sources/new-or-updated-pull-request/new-or-updated-pull-request.mjs @@ -9,7 +9,7 @@ export default { key: "github-new-or-updated-pull-request", name: "New or Updated Pull Request", description: "Emit new event when a pull request is opened or updated", - version: "1.2.1", + version: "1.2.2", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-organization/new-organization.mjs b/components/github/sources/new-organization/new-organization.mjs index 45feb8dac6f6d..d1a79328906e8 100644 --- a/components/github/sources/new-organization/new-organization.mjs +++ b/components/github/sources/new-organization/new-organization.mjs @@ -5,7 +5,7 @@ export default { key: "github-new-organization", name: "New Organization", description: "Emit new event when the authenticated user is added to a new organization. [See the documentation](https://docs.github.com/en/rest/orgs/orgs?apiVersion=2022-11-28#list-organizations-for-the-authenticated-user)", - version: "0.1.17", + version: "0.2.0", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-repository/new-repository.mjs b/components/github/sources/new-repository/new-repository.mjs index fd9c678415750..70b01cf45089e 100644 --- a/components/github/sources/new-repository/new-repository.mjs +++ b/components/github/sources/new-repository/new-repository.mjs @@ -5,7 +5,7 @@ export default { key: "github-new-repository", name: "New Repository", description: "Emit new event when a new repository is created or when the authenticated user receives access. [See the documentation](https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repositories-for-the-authenticated-user)", - version: "0.1.17", + version: "0.2.0", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-review-request/new-review-request.mjs b/components/github/sources/new-review-request/new-review-request.mjs index bd6056c34d778..e725cd6dc1555 100644 --- a/components/github/sources/new-review-request/new-review-request.mjs +++ b/components/github/sources/new-review-request/new-review-request.mjs @@ -5,7 +5,7 @@ export default { key: "github-new-review-request", name: "New Review Request", description: "Emit new event for new review request notifications. [See the documentation](https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user)", - version: "0.1.17", + version: "0.2.0", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-security-alert/new-security-alert.mjs b/components/github/sources/new-security-alert/new-security-alert.mjs index 55f122054f1e4..e793c93378525 100644 --- a/components/github/sources/new-security-alert/new-security-alert.mjs +++ b/components/github/sources/new-security-alert/new-security-alert.mjs @@ -5,7 +5,7 @@ export default { key: "github-new-security-alert", name: "New Security Alert", description: "Emit new event for security alert notifications. [See the documentation](https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user)", - version: "0.1.19", + version: "0.2.0", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-star-by-user/new-star-by-user.mjs b/components/github/sources/new-star-by-user/new-star-by-user.mjs index 1dc301eb8a5cf..50fdf353d6ceb 100644 --- a/components/github/sources/new-star-by-user/new-star-by-user.mjs +++ b/components/github/sources/new-star-by-user/new-star-by-user.mjs @@ -5,7 +5,7 @@ export default { key: "github-new-star-by-user", name: "New Star By User", description: "Emit new events when the specified user stars a repository. [See the documentation](https://docs.github.com/en/rest/activity/starring?apiVersion=2022-11-28#list-repositories-starred-by-a-user)", - version: "0.0.4", + version: "0.0.5", type: "source", dedupe: "unique", props: { diff --git a/components/github/sources/new-star/new-star.mjs b/components/github/sources/new-star/new-star.mjs index 7aafc7e9ae320..1c28c8f79c4b5 100644 --- a/components/github/sources/new-star/new-star.mjs +++ b/components/github/sources/new-star/new-star.mjs @@ -8,7 +8,7 @@ export default { key: "github-new-star", name: "New Stars", description: "Emit new event when a repository is starred", - version: "1.0.4", + version: "1.0.5", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/new-team/new-team.mjs b/components/github/sources/new-team/new-team.mjs index 6a9f4729b7463..5c36526a123fb 100644 --- a/components/github/sources/new-team/new-team.mjs +++ b/components/github/sources/new-team/new-team.mjs @@ -5,7 +5,7 @@ export default { key: "github-new-team", name: "New Team", description: "Emit new event when the authenticated user is added to a new team. [See the documentation](https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#list-teams-for-the-authenticated-user)", - version: "0.1.17", + version: "0.2.0", type: "source", dedupe: "unique", methods: { diff --git a/components/github/sources/webhook-events/webhook-events.mjs b/components/github/sources/webhook-events/webhook-events.mjs index 649e980a446c6..7dc65a0e40af1 100644 --- a/components/github/sources/webhook-events/webhook-events.mjs +++ b/components/github/sources/webhook-events/webhook-events.mjs @@ -8,7 +8,7 @@ export default { name: "New Webhook Event (Instant)", description: "Emit new event for each selected event type", type: "source", - version: "1.0.4", + version: "1.0.5", props: { docsInfo: { type: "alert", From 3960837eb29255a50bc55428744d93f6a5f0c28f Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Wed, 11 Sep 2024 05:11:20 -0300 Subject: [PATCH 13/13] version bump --- components/github/sources/new-release/new-release.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/github/sources/new-release/new-release.mjs b/components/github/sources/new-release/new-release.mjs index 370496a5c4555..1cc2fbba8bb27 100644 --- a/components/github/sources/new-release/new-release.mjs +++ b/components/github/sources/new-release/new-release.mjs @@ -8,7 +8,7 @@ export default { key: "github-new-release", name: "New release", description: "Emit new event when a new release is created", - version: "1.0.4", + version: "1.0.5", type: "source", dedupe: "unique", methods: {