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/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/common/common-polling-pr-notifications.mjs b/components/github/sources/common/common-polling-pr-notifications.mjs new file mode 100644 index 0000000000000..e971d806038b7 --- /dev/null +++ b/components/github/sources/common/common-polling-pr-notifications.mjs @@ -0,0 +1,41 @@ +import common from "./common-polling.mjs"; + +export default { + ...common, + methods: { + ...common.methods, + async getAndProcessData(maxEmits = 0) { + const savedIds = this._getSavedIds(); + const items = await this.getItems(); + + const urlData = new Map(); + let amountEmits = 0; + + 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++; + } + } + savedIds.push(this.getItemId(item)); + })()); + + if (promises?.length) await Promise.allSettled(promises); + + this._setSavedIds(savedIds); + }, + }, +}; diff --git a/components/github/sources/common/common-polling.mjs b/components/github/sources/common/common-polling.mjs index 7c58a15f35955..a6a56840cc9a5 100644 --- a/components/github/sources/common/common-polling.mjs +++ b/components/github/sources/common/common-polling.mjs @@ -12,4 +12,39 @@ 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, { + id: this.getItemId(item), + ...this.getItemMetadata(item), + }); + } + savedIds.push(this.getItemId(item)); + }); + + this._setSavedIds(savedIds); + }, + }, + hooks: { + async deploy() { + await this.getAndProcessData(5); + }, + }, + async run() { + await this.getAndProcessData(); + }, }; diff --git a/components/github/sources/new-branch/new-branch.mjs b/components/github/sources/new-branch/new-branch.mjs index 76f705162cde5..15a0324a2b253 100644 --- a/components/github/sources/new-branch/new-branch.mjs +++ b/components/github/sources/new-branch/new-branch.mjs @@ -3,15 +3,12 @@ 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})`, - version: "1.0.4", + name: "New Branch Created", + description: "Emit new event when a branch is created.", + version: "1.0.5", type: "source", dedupe: "unique", methods: { @@ -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..97e4d83a7b6df 100644 --- a/components/github/sources/new-collaborator/new-collaborator.mjs +++ b/components/github/sources/new-collaborator/new-collaborator.mjs @@ -3,15 +3,12 @@ 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})`, - version: "1.0.4", + description: "Emit new event when a collaborator is added", + version: "1.0.5", type: "source", dedupe: "unique", methods: { @@ -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..418601cfbf92b 100644 --- a/components/github/sources/new-commit-comment/new-commit-comment.mjs +++ b/components/github/sources/new-commit-comment/new-commit-comment.mjs @@ -3,17 +3,22 @@ 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})`, - version: "1.0.4", + description: "Emit new event when a commit comment is created", + version: "1.0.5", 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, @@ -35,5 +40,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..eb1c6332b7be3 100644 --- a/components/github/sources/new-commit/new-commit.mjs +++ b/components/github/sources/new-commit/new-commit.mjs @@ -3,18 +3,20 @@ 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})`, - version: "1.0.5", + description: "Emit new event when commits are pushed to a branch", + version: "1.0.6", 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: [ @@ -95,5 +97,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..c4295dccb2e7f 100644 --- a/components/github/sources/new-discussion/new-discussion.mjs +++ b/components/github/sources/new-discussion/new-discussion.mjs @@ -3,15 +3,12 @@ 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})`, - version: "1.0.4", + description: "Emit new event when a discussion is created", + version: "1.0.5", type: "source", dedupe: "unique", methods: { @@ -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..c702ccc5d2cf8 100644 --- a/components/github/sources/new-fork/new-fork.mjs +++ b/components/github/sources/new-fork/new-fork.mjs @@ -3,15 +3,12 @@ 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})`, - version: "1.0.4", + description: "Emit new event when a repository is forked", + version: "1.0.5", type: "source", dedupe: "unique", methods: { @@ -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-gist/new-gist.mjs b/components/github/sources/new-gist/new-gist.mjs index a74f5fbb05319..5d580c57640b8 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", - version: "0.1.17", + 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.2.0", 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-label/new-label.mjs b/components/github/sources/new-label/new-label.mjs index 8a7127bffc9c9..35d116c44f2cb 100644 --- a/components/github/sources/new-label/new-label.mjs +++ b/components/github/sources/new-label/new-label.mjs @@ -3,15 +3,12 @@ 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})`, - version: "1.0.4", + description: "Emit new event when a new label is created", + version: "1.0.5", type: "source", dedupe: "unique", methods: { @@ -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-mention/new-mention.mjs b/components/github/sources/new-mention/new-mention.mjs index f3ed4b7dfcf89..40c2e3939bc29 100644 --- a/components/github/sources/new-mention/new-mention.mjs +++ b/components/github/sources/new-mention/new-mention.mjs @@ -4,15 +4,9 @@ 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", - version: "0.1.18", + 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.2.0", type: "source", - hooks: { - async activate() { - const user = await this.github.getAuthenticatedUser(); - this._setUserLogin(user.login); - }, - }, dedupe: "unique", methods: { ...common.methods, @@ -22,38 +16,78 @@ export default { _setUserLogin(userLogin) { this.db.set("userLogin", userLogin); }, - }, - async run() { - const login = this._getUserLogin(); - - const notifications = await this.github.getFilteredNotifications({ - reason: "mention", - data: { - participating: true, - all: true, - }, - }); - - for (const notification of notifications) { - const subject = await this.github.getFromUrl({ - url: notification?.subject?.url, + _getLastDate() { + return this.db.get("lastDate"); + }, + _setLastDate(value) { + this.db.set("lastDate", 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() { + const date = this._getLastDate(); + this._setLastDate(new Date().toISOString()); + return this.github.getFilteredNotifications({ + reason: "mention", + data: { + participating: true, + all: true, + ...(date && { + since: date, + }), + }, }); + }, + async getAndProcessData(maxEmits = 0) { + const login = await this.retrieveUserLogin(); + const savedIds = this._getSavedIds(); + const items = await this.getItems(); - if (!subject.comments_url) continue; + const urlData = new Map(); + let amountEmits = 0; - const comments = await this.github.getFromUrl({ - url: subject.comments_url, - }); + const promises = items?.map((item) => (async () => { + 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; - 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), - }); + if (!urlData.has(commentsUrl)) { + urlData.set(commentsUrl, await this.github.getFromUrl({ + url: commentsUrl, + })); } - } - } + const comments = urlData.get(commentsUrl); + comments?.filter?.((comment) => { + return !savedIds.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++; + } + savedIds.push(comment.id); + }); + })()); + + if (promises?.length) await Promise.allSettled(promises); + + this._setSavedIds(savedIds); + }, }, }; diff --git a/components/github/sources/new-notification/new-notification.mjs b/components/github/sources/new-notification/new-notification.mjs index a8121547e1be3..c5c3b579c52a7 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", - version: "0.1.17", + 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.2.0", 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-or-updated-issue/new-or-updated-issue.mjs b/components/github/sources/new-or-updated-issue/new-or-updated-issue.mjs index f3085cc42e434..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 @@ -4,15 +4,12 @@ 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})`, - version: "1.1.1", + description: "Emit new events when an issue is created or updated", + version: "1.1.2", type: "source", dedupe: "unique", methods: { @@ -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..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 @@ -4,15 +4,12 @@ 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})`, - version: "1.1.1", + description: "Emit new event when a milestone is created or updated", + version: "1.1.2", type: "source", dedupe: "unique", methods: { @@ -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..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 @@ -4,15 +4,12 @@ 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})`, - version: "1.2.1", + description: "Emit new event when a pull request is opened or updated", + version: "1.2.2", type: "source", dedupe: "unique", methods: { @@ -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-organization/new-organization.mjs b/components/github/sources/new-organization/new-organization.mjs index d16c5594971f1..d1a79328906e8 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", - version: "0.1.17", + 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.2.0", 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-release/new-release.mjs b/components/github/sources/new-release/new-release.mjs index 334e795c9a603..1cc2fbba8bb27 100644 --- a/components/github/sources/new-release/new-release.mjs +++ b/components/github/sources/new-release/new-release.mjs @@ -3,15 +3,12 @@ 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})`, - version: "1.0.4", + description: "Emit new event when a new release is created", + version: "1.0.5", type: "source", dedupe: "unique", methods: { @@ -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-repository/new-repository.mjs b/components/github/sources/new-repository/new-repository.mjs index 085e47ab63c71..70b01cf45089e 100644 --- a/components/github/sources/new-repository/new-repository.mjs +++ b/components/github/sources/new-repository/new-repository.mjs @@ -4,19 +4,20 @@ export default { ...common, key: "github-new-repository", name: "New Repository", - description: "Emit new events when new repositories are created", - version: "0.1.17", + 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.2.0", 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(), + }; + }, }, }; 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..e725cd6dc1555 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,40 @@ -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", - version: "0.1.17", + 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.2.0", 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, + _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, + }), + }, }); - } + }, + 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..e793c93378525 100644 --- a/components/github/sources/new-security-alert/new-security-alert.mjs +++ b/components/github/sources/new-security-alert/new-security-alert.mjs @@ -4,31 +4,26 @@ 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", - version: "0.1.19", + 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.2.0", 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(), + }; + }, }, }; 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..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 @@ -4,8 +4,8 @@ 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", - version: "0.0.4", + 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.5", type: "source", dedupe: "unique", props: { @@ -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, - summary: `New star: ${star.full_name}`, + async getItems() { + const user = this.user ?? (await this.github.getAuthenticatedUser()).login; + return this.getUserStars(user); + }, + getItemMetadata(item) { + return { + summary: `New star: ${item.full_name}`, ts: Date.now(), - }); - }); + }; + }, }, }; diff --git a/components/github/sources/new-star/new-star.mjs b/components/github/sources/new-star/new-star.mjs index f76dbe72e81eb..1c28c8f79c4b5 100644 --- a/components/github/sources/new-star/new-star.mjs +++ b/components/github/sources/new-star/new-star.mjs @@ -3,14 +3,12 @@ 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})`, - version: "1.0.4", + description: "Emit new event when a repository is starred", + version: "1.0.5", type: "source", dedupe: "unique", methods: { @@ -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"; + }, }, }; diff --git a/components/github/sources/new-team/new-team.mjs b/components/github/sources/new-team/new-team.mjs index e51a212c11b81..5c36526a123fb 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", - version: "0.1.17", + 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.2.0", 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(), + }; + }, }, }; diff --git a/components/github/sources/webhook-events/webhook-events.mjs b/components/github/sources/webhook-events/webhook-events.mjs index 21abfd4f6931a..7dc65a0e40af1 100644 --- a/components/github/sources/webhook-events/webhook-events.mjs +++ b/components/github/sources/webhook-events/webhook-events.mjs @@ -8,8 +8,13 @@ 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", + 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",