Skip to content

Commit d257a1b

Browse files
authored
GitHub sources usability improvements (#13895)
* Docs link updates for sources * Adding docs info alerts * Improvements for common polling interface * Adjustments to polling * Improving polling sources * New Repository improvements * Common interface for PR notifications sources * Reusing base for new security alert * "New mention" rewrite + adjustments * Behavior adjustments to notification sources * Adjustments for mentions * Version bumps * version bump
1 parent a46999e commit d257a1b

File tree

26 files changed

+408
-226
lines changed

26 files changed

+408
-226
lines changed

components/github/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/github",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "Pipedream Github Components",
55
"main": "github.app.mjs",
66
"keywords": [

components/github/sources/common/common-flex.mjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@ export default {
1717
db: "$.service.db",
1818
},
1919
async additionalProps() {
20+
const getDocsInfo = (docsLink) => ({
21+
type: "alert",
22+
alertType: "info",
23+
content: `[See the GitHub documentation](${docsLink}) for more information on the event format.`,
24+
});
2025
if (await this.checkAdminPermission()) {
2126
return {
2227
http: {
2328
type: "$.interface.http",
2429
},
2530
...this.getHttpAdditionalProps(),
31+
docsInfo: getDocsInfo(this.getHttpDocsLink()),
2632
};
2733
} else {
2834
return {
2935
info: {
3036
type: "alert",
31-
alertType: "info",
37+
alertType: "warning",
3238
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.",
3339
},
3440
timer: {
@@ -38,6 +44,7 @@ export default {
3844
},
3945
},
4046
...this.getTimerAdditionalProps(),
47+
docsInfo: getDocsInfo(this.getTimerDocsLink()),
4148
};
4249
}
4350
},
@@ -196,6 +203,12 @@ export default {
196203

197204
this._setSavedItems(savedItems);
198205
},
206+
getHttpDocsLink() {
207+
return "https://docs.github.com/en/webhooks/webhook-events-and-payloads";
208+
},
209+
getTimerDocsLink() {
210+
return "https://docs.github.com/en/rest?apiVersion=2022-11-28";
211+
},
199212
},
200213
hooks: {
201214
async activate() {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import common from "./common-polling.mjs";
2+
3+
export default {
4+
...common,
5+
methods: {
6+
...common.methods,
7+
async getAndProcessData(maxEmits = 0) {
8+
const savedIds = this._getSavedIds();
9+
const items = await this.getItems();
10+
11+
const urlData = new Map();
12+
let amountEmits = 0;
13+
14+
const promises = items?.
15+
filter?.((item) => !savedIds.includes(this.getItemId(item)))
16+
.map((item) => (async () => {
17+
if (item?.subject?.notification !== null) {
18+
const url = item.subject.url;
19+
if (!urlData.has(url)) {
20+
urlData.set(url, await this.github.getFromUrl({
21+
url: item.subject.url,
22+
}));
23+
}
24+
const pullRequest = urlData.get(url);
25+
if (!maxEmits || (amountEmits < maxEmits)) {
26+
this.$emit(pullRequest, {
27+
id: pullRequest.id,
28+
...this.getItemMetadata(pullRequest),
29+
});
30+
amountEmits++;
31+
}
32+
}
33+
savedIds.push(this.getItemId(item));
34+
})());
35+
36+
if (promises?.length) await Promise.allSettled(promises);
37+
38+
this._setSavedIds(savedIds);
39+
},
40+
},
41+
};

components/github/sources/common/common-polling.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,39 @@ export default {
1212
},
1313
db: "$.service.db",
1414
},
15+
methods: {
16+
_getSavedIds() {
17+
return this.db.get("savedIds") || [];
18+
},
19+
_setSavedIds(value) {
20+
this.db.set("savedIds", value);
21+
},
22+
getItemId(item) {
23+
return item.id;
24+
},
25+
async getAndProcessData(maxEmits = 0) {
26+
const savedIds = this._getSavedIds();
27+
const items = await this.getItems();
28+
29+
items?.filter?.((item) => !savedIds.includes(this.getItemId(item))).forEach((item, index) => {
30+
if ((!maxEmits) || (index < maxEmits)) {
31+
this.$emit(item, {
32+
id: this.getItemId(item),
33+
...this.getItemMetadata(item),
34+
});
35+
}
36+
savedIds.push(this.getItemId(item));
37+
});
38+
39+
this._setSavedIds(savedIds);
40+
},
41+
},
42+
hooks: {
43+
async deploy() {
44+
await this.getAndProcessData(5);
45+
},
46+
},
47+
async run() {
48+
await this.getAndProcessData();
49+
},
1550
};

components/github/sources/new-branch/new-branch.mjs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ import {
33
getSampleTimerEvent, getSampleWebhookEvent,
44
} from "./common-sample-events.mjs";
55

6-
const DOCS_LINK =
7-
"https://docs.github.com/en/webhooks/webhook-events-and-payloads#create";
8-
96
export default {
107
...common,
118
key: "github-new-branch",
12-
name: "New Branch",
13-
description: `Emit new event when a branch is created [See the documentation](${DOCS_LINK})`,
14-
version: "1.0.4",
9+
name: "New Branch Created",
10+
description: "Emit new event when a branch is created.",
11+
version: "1.0.5",
1512
type: "source",
1613
dedupe: "unique",
1714
methods: {
@@ -35,5 +32,11 @@ export default {
3532
getPollingData(args) {
3633
return this.github.getBranches(args);
3734
},
35+
getHttpDocsLink() {
36+
return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#create";
37+
},
38+
getTimerDocsLink() {
39+
return "https://docs.github.com/en/rest/branches/branches?apiVersion=2022-11-28#list-branches";
40+
},
3841
},
3942
};

components/github/sources/new-collaborator/new-collaborator.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ import {
33
getSampleTimerEvent, getSampleWebhookEvent,
44
} from "./common-sample-events.mjs";
55

6-
const DOCS_LINK =
7-
"https://docs.github.com/en/webhooks/webhook-events-and-payloads#member";
8-
96
export default {
107
...common,
118
key: "github-new-collaborator",
129
name: "New Collaborator",
13-
description: `Emit new event when a collaborator is added [See the documentation](${DOCS_LINK})`,
14-
version: "1.0.4",
10+
description: "Emit new event when a collaborator is added",
11+
version: "1.0.5",
1512
type: "source",
1613
dedupe: "unique",
1714
methods: {
@@ -35,5 +32,11 @@ export default {
3532
getPollingData(args) {
3633
return this.github.getRepositoryLatestCollaborators(args);
3734
},
35+
getHttpDocsLink() {
36+
return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#member";
37+
},
38+
getTimerDocsLink() {
39+
return "https://docs.github.com/en/rest/collaborators/collaborators?apiVersion=2022-11-28#list-repository-collaborators";
40+
},
3841
},
3942
};

components/github/sources/new-commit-comment/new-commit-comment.mjs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@ import {
33
getSampleTimerEvent, getSampleWebhookEvent,
44
} from "./common-sample-events.mjs";
55

6-
const DOCS_LINK =
7-
"https://docs.github.com/en/webhooks/webhook-events-and-payloads#commit_comment";
8-
96
export default {
107
...common,
118
key: "github-new-commit-comment",
129
name: "New Commit Comment",
13-
description: `Emit new event when a commit comment is created [See the documentation](${DOCS_LINK})`,
14-
version: "1.0.4",
10+
description: "Emit new event when a commit comment is created",
11+
version: "1.0.5",
1512
type: "source",
1613
dedupe: "unique",
14+
props: {
15+
eventTypeInfo: {
16+
type: "alert",
17+
alertType: "info",
18+
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.",
19+
},
20+
...common.props,
21+
},
1722
methods: {
1823
...common.methods,
1924
getSampleTimerEvent,
@@ -35,5 +40,11 @@ export default {
3540
getPollingData(args) {
3641
return this.github.getRepositoryLatestCommitComments(args);
3742
},
43+
getHttpDocsLink() {
44+
return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#commit_comment";
45+
},
46+
getTimerDocsLink() {
47+
return "https://docs.github.com/en/rest/commits/comments?apiVersion=2022-11-28#list-commit-comments-for-a-repository";
48+
},
3849
},
3950
};

components/github/sources/new-commit/new-commit.mjs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ import {
33
getSampleTimerEvent, getSampleWebhookEvent,
44
} from "./common-sample-events.mjs";
55

6-
const DOCS_LINK =
7-
"https://docs.github.com/en/webhooks/webhook-events-and-payloads#push";
8-
96
export default {
107
...common,
118
key: "github-new-commit",
129
name: "New Commit",
13-
description: `Emit new event when commits are pushed to a branch [See the documentation](${DOCS_LINK})`,
14-
version: "1.0.5",
10+
description: "Emit new event when commits are pushed to a branch",
11+
version: "1.0.6",
1512
type: "source",
1613
dedupe: "unique",
1714
props: {
15+
eventTypeInfo: {
16+
type: "alert",
17+
alertType: "info",
18+
content: "**Note:** one event is emitted for each individual commit, even if they are received at the same time.",
19+
},
1820
...common.props,
1921
branch: {
2022
propDefinition: [
@@ -95,5 +97,11 @@ export default {
9597
this._setSavedItems(savedItems);
9698
this._setLastTimestamp(Date.now());
9799
},
100+
getHttpDocsLink() {
101+
return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#push";
102+
},
103+
getTimerDocsLink() {
104+
return "https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-commits";
105+
},
98106
},
99107
};

components/github/sources/new-discussion/new-discussion.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ import {
33
getSampleTimerEvent, getSampleWebhookEvent,
44
} from "./common-sample-events.mjs";
55

6-
const DOCS_LINK =
7-
"https://docs.github.com/en/webhooks/webhook-events-and-payloads#discussion";
8-
96
export default {
107
...common,
118
key: "github-new-discussion",
129
name: "New Discussion",
13-
description: `Emit new event when a discussion is created [See the documentation](${DOCS_LINK})`,
14-
version: "1.0.4",
10+
description: "Emit new event when a discussion is created",
11+
version: "1.0.5",
1512
type: "source",
1613
dedupe: "unique",
1714
methods: {
@@ -42,5 +39,11 @@ export default {
4239
return dateA - dateB;
4340
});
4441
},
42+
getHttpDocsLink() {
43+
return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#discussion";
44+
},
45+
getTimerDocsLink() {
46+
return "https://docs.github.com/en/graphql/reference/objects#discussion";
47+
},
4548
},
4649
};

components/github/sources/new-fork/new-fork.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ import {
33
getSampleTimerEvent, getSampleWebhookEvent,
44
} from "./common-sample-events.mjs";
55

6-
const DOCS_LINK =
7-
"https://docs.github.com/en/webhooks/webhook-events-and-payloads#fork";
8-
96
export default {
107
...common,
118
key: "github-new-fork",
129
name: "New Fork",
13-
description: `Emit new event when a repository is forked [See the documentation](${DOCS_LINK})`,
14-
version: "1.0.4",
10+
description: "Emit new event when a repository is forked",
11+
version: "1.0.5",
1512
type: "source",
1613
dedupe: "unique",
1714
methods: {
@@ -35,5 +32,11 @@ export default {
3532
getPollingData(args) {
3633
return this.github.getRepositoryForks(args);
3734
},
35+
getHttpDocsLink() {
36+
return "https://docs.github.com/en/webhooks/webhook-events-and-payloads#fork";
37+
},
38+
getTimerDocsLink() {
39+
return "https://docs.github.com/en/rest/repos/forks?apiVersion=2022-11-28#list-forks";
40+
},
3841
},
3942
};

0 commit comments

Comments
 (0)