forked from PipedreamHQ/pipedream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.app.js
More file actions
66 lines (65 loc) · 1.73 KB
/
Copy pathgithub.app.js
File metadata and controls
66 lines (65 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const axios = require("axios")
const WEBHOOKS = require("@octokit/webhooks-definitions")
const listOfEvents = WEBHOOKS.map(webhook => webhook.name)
module.exports = {
type: "app",
app: "github",
propDefinitions: {
repoFullName: {
type: "string",
label: "Repo",
async options({ page }) {
const repos = await this.getRepos({
page: page + 1, // pipedream page 0-indexed, github is 1
})
return repos.map(repo => repo.full_name)
},
},
events: {
type: "string[]",
label: "Events",
options: listOfEvents,
},
},
methods: {
async _makeRequest(opts) {
if (!opts.headers) opts.headers = {}
opts.headers.authorization = `token ${this.$auth.oauth_access_token}`
opts.headers["user-agent"] = "@PipedreamHQ/pipedream v0.1"
const { path } = opts
delete opts.path
opts.url = `https://api.github.com${path[0] === "/" ? "" : "/"}${path}`
return await axios(opts)
},
async getRepos({ page }) {
return (await this._makeRequest({
path: "/user/repos",
params: {
per_page: 100,
page,
},
})).data
},
async createHook({ repoFullName, endpoint, events, secret }) {
return (await this._makeRequest({
method: "post",
path: `/repos/${repoFullName}/hooks`,
data: {
name: "web",
config: {
url: endpoint,
content_type: "json",
secret,
},
events,
},
})).data
},
async deleteHook({ repoFullName, hookId }) {
return (await this._makeRequest({
method: "delete",
path: `/repos/${repoFullName}/hooks/${hookId}`,
})).data
},
},
}