@slates-integrations/github 0.2.0-rc.4 → 0.2.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +3 -0
- package/dist/sourcemap-register.cjs +1 -0
- package/docs/SPEC.md +219 -3
- package/package.json +14 -5
- package/slate.json +1 -4
- package/src/auth.ts +0 -347
- package/src/config.ts +0 -4
- package/src/index.ts +0 -78
- package/src/lib/client.ts +0 -991
- package/src/spec.ts +0 -13
- package/src/tools/comment-on-issue.ts +0 -46
- package/src/tools/create-commit-status.ts +0 -97
- package/src/tools/create-release.ts +0 -69
- package/src/tools/create-repository.ts +0 -70
- package/src/tools/get-issue.ts +0 -67
- package/src/tools/get-repository.ts +0 -75
- package/src/tools/get-user.ts +0 -64
- package/src/tools/index.ts +0 -24
- package/src/tools/list-branches.ts +0 -54
- package/src/tools/list-commits.ts +0 -70
- package/src/tools/list-issues.ts +0 -90
- package/src/tools/list-pull-requests.ts +0 -82
- package/src/tools/list-repositories.ts +0 -102
- package/src/tools/manage-collaborators.ts +0 -88
- package/src/tools/manage-file-content.ts +0 -117
- package/src/tools/manage-gist.ts +0 -183
- package/src/tools/manage-issue.ts +0 -94
- package/src/tools/manage-labels.ts +0 -93
- package/src/tools/manage-pull-request.ts +0 -111
- package/src/tools/manage-workflow.ts +0 -242
- package/src/tools/merge-pull-request.ts +0 -61
- package/src/tools/review-pull-request.ts +0 -90
- package/src/tools/search.ts +0 -72
- package/src/tools/star-repository.ts +0 -57
- package/src/tools/update-repository.ts +0 -56
- package/src/triggers/index.ts +0 -8
- package/src/triggers/issue-comment.ts +0 -94
- package/src/triggers/issues.ts +0 -111
- package/src/triggers/pull-request-review.ts +0 -95
- package/src/triggers/pull-request.ts +0 -123
- package/src/triggers/push.ts +0 -117
- package/src/triggers/release.ts +0 -103
- package/src/triggers/star.ts +0 -71
- package/src/triggers/workflow-run.ts +0 -112
- package/tsconfig.json +0 -23
package/src/auth.ts
DELETED
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
import { SlateAuth, createAxios } from 'slates';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
let outputSchema = z.object({
|
|
5
|
-
token: z.string(),
|
|
6
|
-
refreshToken: z.string().optional(),
|
|
7
|
-
instanceUrl: z.string()
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
type AuthOutput = z.infer<typeof outputSchema>;
|
|
11
|
-
|
|
12
|
-
let scopes = [
|
|
13
|
-
{
|
|
14
|
-
title: 'Repository',
|
|
15
|
-
description: 'Full access to public and private repositories',
|
|
16
|
-
scope: 'repo'
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
title: 'Repository Status',
|
|
20
|
-
description: 'Read/write access to commit statuses',
|
|
21
|
-
scope: 'repo:status'
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
title: 'Public Repository',
|
|
25
|
-
description: 'Access to public repositories only',
|
|
26
|
-
scope: 'public_repo'
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
title: 'Admin: Organization',
|
|
30
|
-
description: 'Full management of organizations and teams',
|
|
31
|
-
scope: 'admin:org'
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
title: 'Write Organization',
|
|
35
|
-
description: 'Write access to organization membership',
|
|
36
|
-
scope: 'write:org'
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
title: 'Read Organization',
|
|
40
|
-
description: 'Read access to organization membership',
|
|
41
|
-
scope: 'read:org'
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
title: 'Admin: Repo Hook',
|
|
45
|
-
description: 'Full access to repository webhooks',
|
|
46
|
-
scope: 'admin:repo_hook'
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
title: 'Admin: Org Hook',
|
|
50
|
-
description: 'Full access to organization webhooks',
|
|
51
|
-
scope: 'admin:org_hook'
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
title: 'User',
|
|
55
|
-
description: 'Read/write access to user profile, email, and follow',
|
|
56
|
-
scope: 'user'
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
title: 'User Email',
|
|
60
|
-
description: 'Read access to email addresses',
|
|
61
|
-
scope: 'user:email'
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
title: 'Gist',
|
|
65
|
-
description: 'Write access to gists',
|
|
66
|
-
scope: 'gist'
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
title: 'Notifications',
|
|
70
|
-
description: 'Access to notifications',
|
|
71
|
-
scope: 'notifications'
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
title: 'Workflow',
|
|
75
|
-
description: 'Manage GitHub Actions workflow files',
|
|
76
|
-
scope: 'workflow'
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
title: 'Write Packages',
|
|
80
|
-
description: 'Upload packages to GitHub Packages',
|
|
81
|
-
scope: 'write:packages'
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
title: 'Read Packages',
|
|
85
|
-
description: 'Download packages from GitHub Packages',
|
|
86
|
-
scope: 'read:packages'
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
title: 'Delete Packages',
|
|
90
|
-
description: 'Delete packages from GitHub Packages',
|
|
91
|
-
scope: 'delete:packages'
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
title: 'Project',
|
|
95
|
-
description: 'Full access to user and organization projects',
|
|
96
|
-
scope: 'project'
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
title: 'Read Project',
|
|
100
|
-
description: 'Read-only access to user and organization projects',
|
|
101
|
-
scope: 'read:project'
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
title: 'Delete Repository',
|
|
105
|
-
description: 'Delete repositories',
|
|
106
|
-
scope: 'delete_repo'
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
title: 'Security Events',
|
|
110
|
-
description: 'Access to code scanning API',
|
|
111
|
-
scope: 'security_events'
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
title: 'Read Audit Log',
|
|
115
|
-
description: 'Read audit log data',
|
|
116
|
-
scope: 'read:audit_log'
|
|
117
|
-
}
|
|
118
|
-
];
|
|
119
|
-
|
|
120
|
-
function normalizeBaseUrl(url: string) {
|
|
121
|
-
return url.replace(/\/+$/, '');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function getApiBaseUrl(instanceUrl: string) {
|
|
125
|
-
let baseUrl = normalizeBaseUrl(instanceUrl);
|
|
126
|
-
return baseUrl === 'https://github.com' ? 'https://api.github.com' : `${baseUrl}/api/v3`;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function createGithubOauth(opts: {
|
|
130
|
-
name: string;
|
|
131
|
-
key: string;
|
|
132
|
-
hardcodedInstanceUrl: string | null;
|
|
133
|
-
}) {
|
|
134
|
-
let inputSchema = opts.hardcodedInstanceUrl
|
|
135
|
-
? z.object({})
|
|
136
|
-
: z.object({
|
|
137
|
-
instanceUrl: z
|
|
138
|
-
.string()
|
|
139
|
-
.describe('Your GitHub Enterprise URL (e.g. https://github.example.com).')
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
return {
|
|
143
|
-
type: 'auth.oauth' as const,
|
|
144
|
-
name: opts.name,
|
|
145
|
-
key: opts.key,
|
|
146
|
-
scopes,
|
|
147
|
-
inputSchema,
|
|
148
|
-
|
|
149
|
-
getAuthorizationUrl: async (ctx: any) => {
|
|
150
|
-
let baseUrl = opts.hardcodedInstanceUrl
|
|
151
|
-
? opts.hardcodedInstanceUrl
|
|
152
|
-
: normalizeBaseUrl(ctx.input.instanceUrl);
|
|
153
|
-
|
|
154
|
-
let params = new URLSearchParams({
|
|
155
|
-
client_id: ctx.clientId,
|
|
156
|
-
redirect_uri: ctx.redirectUri,
|
|
157
|
-
state: ctx.state,
|
|
158
|
-
scope: ctx.scopes.join(' ')
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
url: `${baseUrl}/login/oauth/authorize?${params.toString()}`,
|
|
163
|
-
input: opts.hardcodedInstanceUrl ? {} : { instanceUrl: ctx.input.instanceUrl }
|
|
164
|
-
};
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
handleCallback: async (ctx: any) => {
|
|
168
|
-
let baseUrl = opts.hardcodedInstanceUrl
|
|
169
|
-
? opts.hardcodedInstanceUrl
|
|
170
|
-
: normalizeBaseUrl(ctx.input.instanceUrl);
|
|
171
|
-
|
|
172
|
-
let http = createAxios({ baseURL: baseUrl });
|
|
173
|
-
let response = await http.post(
|
|
174
|
-
'/login/oauth/access_token',
|
|
175
|
-
{
|
|
176
|
-
client_id: ctx.clientId,
|
|
177
|
-
client_secret: ctx.clientSecret,
|
|
178
|
-
code: ctx.code,
|
|
179
|
-
redirect_uri: ctx.redirectUri
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
headers: {
|
|
183
|
-
Accept: 'application/json'
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
let data = response.data;
|
|
189
|
-
|
|
190
|
-
return {
|
|
191
|
-
output: {
|
|
192
|
-
token: data.access_token,
|
|
193
|
-
refreshToken: data.refresh_token,
|
|
194
|
-
instanceUrl: baseUrl
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
handleTokenRefresh: async (ctx: any) => {
|
|
200
|
-
if (!ctx.output.refreshToken) {
|
|
201
|
-
return { output: ctx.output };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
let baseUrl = ctx.output.instanceUrl
|
|
205
|
-
? normalizeBaseUrl(ctx.output.instanceUrl)
|
|
206
|
-
: opts.hardcodedInstanceUrl || 'https://github.com';
|
|
207
|
-
|
|
208
|
-
let http = createAxios({ baseURL: baseUrl });
|
|
209
|
-
let response = await http.post(
|
|
210
|
-
'/login/oauth/access_token',
|
|
211
|
-
{
|
|
212
|
-
client_id: ctx.clientId,
|
|
213
|
-
client_secret: ctx.clientSecret,
|
|
214
|
-
grant_type: 'refresh_token',
|
|
215
|
-
refresh_token: ctx.output.refreshToken
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
headers: {
|
|
219
|
-
Accept: 'application/json'
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
let data = response.data;
|
|
225
|
-
|
|
226
|
-
return {
|
|
227
|
-
output: {
|
|
228
|
-
token: data.access_token,
|
|
229
|
-
refreshToken: data.refresh_token ?? ctx.output.refreshToken,
|
|
230
|
-
instanceUrl: baseUrl
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
},
|
|
234
|
-
|
|
235
|
-
getProfile: async (ctx: { output: AuthOutput }) => {
|
|
236
|
-
let http = createAxios({
|
|
237
|
-
baseURL: getApiBaseUrl(ctx.output.instanceUrl),
|
|
238
|
-
headers: {
|
|
239
|
-
Authorization: `Bearer ${ctx.output.token}`,
|
|
240
|
-
Accept: 'application/vnd.github+json'
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
let response = await http.get('/user');
|
|
245
|
-
let user = response.data;
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
profile: {
|
|
249
|
-
id: String(user.id),
|
|
250
|
-
email: user.email ?? undefined,
|
|
251
|
-
name: user.name ?? user.login,
|
|
252
|
-
imageUrl: user.avatar_url
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
} as any;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function createGithubPat(opts: {
|
|
260
|
-
name: string;
|
|
261
|
-
key: string;
|
|
262
|
-
hardcodedInstanceUrl: string | null;
|
|
263
|
-
}) {
|
|
264
|
-
let inputSchema = opts.hardcodedInstanceUrl
|
|
265
|
-
? z.object({
|
|
266
|
-
token: z.string().describe('GitHub Personal Access Token (classic or fine-grained)')
|
|
267
|
-
})
|
|
268
|
-
: z.object({
|
|
269
|
-
token: z.string().describe('GitHub Personal Access Token (classic or fine-grained)'),
|
|
270
|
-
instanceUrl: z
|
|
271
|
-
.string()
|
|
272
|
-
.describe('Your GitHub Enterprise URL (e.g. https://github.example.com).')
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
return {
|
|
276
|
-
type: 'auth.token' as const,
|
|
277
|
-
name: opts.name,
|
|
278
|
-
key: opts.key,
|
|
279
|
-
inputSchema,
|
|
280
|
-
|
|
281
|
-
getOutput: async (ctx: any) => {
|
|
282
|
-
let instanceUrl = opts.hardcodedInstanceUrl
|
|
283
|
-
? opts.hardcodedInstanceUrl
|
|
284
|
-
: normalizeBaseUrl(ctx.input.instanceUrl);
|
|
285
|
-
|
|
286
|
-
return {
|
|
287
|
-
output: {
|
|
288
|
-
token: ctx.input.token,
|
|
289
|
-
instanceUrl
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
},
|
|
293
|
-
|
|
294
|
-
getProfile: async (ctx: { output: AuthOutput }) => {
|
|
295
|
-
let http = createAxios({
|
|
296
|
-
baseURL: getApiBaseUrl(ctx.output.instanceUrl),
|
|
297
|
-
headers: {
|
|
298
|
-
Authorization: `Bearer ${ctx.output.token}`,
|
|
299
|
-
Accept: 'application/vnd.github+json'
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
let response = await http.get('/user');
|
|
304
|
-
let user = response.data;
|
|
305
|
-
|
|
306
|
-
return {
|
|
307
|
-
profile: {
|
|
308
|
-
id: String(user.id),
|
|
309
|
-
email: user.email ?? undefined,
|
|
310
|
-
name: user.name ?? user.login,
|
|
311
|
-
imageUrl: user.avatar_url
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
} as any;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
export let auth = SlateAuth.create()
|
|
319
|
-
.output(outputSchema)
|
|
320
|
-
.addOauth(
|
|
321
|
-
createGithubOauth({
|
|
322
|
-
name: 'GitHub.com',
|
|
323
|
-
key: 'oauth',
|
|
324
|
-
hardcodedInstanceUrl: 'https://github.com'
|
|
325
|
-
})
|
|
326
|
-
)
|
|
327
|
-
.addOauth(
|
|
328
|
-
createGithubOauth({
|
|
329
|
-
name: 'Enterprise',
|
|
330
|
-
key: 'oauth_enterprise',
|
|
331
|
-
hardcodedInstanceUrl: null
|
|
332
|
-
})
|
|
333
|
-
)
|
|
334
|
-
.addTokenAuth(
|
|
335
|
-
createGithubPat({
|
|
336
|
-
name: 'Personal Access Token (GitHub.com)',
|
|
337
|
-
key: 'personal_access_token',
|
|
338
|
-
hardcodedInstanceUrl: 'https://github.com'
|
|
339
|
-
})
|
|
340
|
-
)
|
|
341
|
-
.addTokenAuth(
|
|
342
|
-
createGithubPat({
|
|
343
|
-
name: 'Personal Access Token (Enterprise)',
|
|
344
|
-
key: 'pat_enterprise',
|
|
345
|
-
hardcodedInstanceUrl: null
|
|
346
|
-
})
|
|
347
|
-
);
|
package/src/config.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Slate } from 'slates';
|
|
2
|
-
import { spec } from './spec';
|
|
3
|
-
import {
|
|
4
|
-
getRepository,
|
|
5
|
-
listRepositories,
|
|
6
|
-
createRepository,
|
|
7
|
-
updateRepository,
|
|
8
|
-
starRepository,
|
|
9
|
-
manageIssue,
|
|
10
|
-
listIssues,
|
|
11
|
-
getIssue,
|
|
12
|
-
commentOnIssue,
|
|
13
|
-
managePullRequest,
|
|
14
|
-
listPullRequests,
|
|
15
|
-
mergePullRequest,
|
|
16
|
-
reviewPullRequest,
|
|
17
|
-
search,
|
|
18
|
-
manageFileContent,
|
|
19
|
-
manageWorkflow,
|
|
20
|
-
createRelease,
|
|
21
|
-
listCommits,
|
|
22
|
-
listBranches,
|
|
23
|
-
manageLabels,
|
|
24
|
-
manageGist,
|
|
25
|
-
manageCollaborators,
|
|
26
|
-
getUser,
|
|
27
|
-
createCommitStatus
|
|
28
|
-
} from './tools';
|
|
29
|
-
import {
|
|
30
|
-
pushTrigger,
|
|
31
|
-
pullRequestTrigger,
|
|
32
|
-
pullRequestReviewTrigger,
|
|
33
|
-
issuesTrigger,
|
|
34
|
-
issueCommentTrigger,
|
|
35
|
-
workflowRunTrigger,
|
|
36
|
-
releaseTrigger,
|
|
37
|
-
starTrigger
|
|
38
|
-
} from './triggers';
|
|
39
|
-
|
|
40
|
-
export let provider = Slate.create({
|
|
41
|
-
spec,
|
|
42
|
-
tools: [
|
|
43
|
-
getRepository,
|
|
44
|
-
listRepositories,
|
|
45
|
-
createRepository,
|
|
46
|
-
updateRepository,
|
|
47
|
-
starRepository,
|
|
48
|
-
manageIssue,
|
|
49
|
-
listIssues,
|
|
50
|
-
getIssue,
|
|
51
|
-
commentOnIssue,
|
|
52
|
-
managePullRequest,
|
|
53
|
-
listPullRequests,
|
|
54
|
-
mergePullRequest,
|
|
55
|
-
reviewPullRequest,
|
|
56
|
-
search,
|
|
57
|
-
manageFileContent,
|
|
58
|
-
manageWorkflow,
|
|
59
|
-
createRelease,
|
|
60
|
-
listCommits,
|
|
61
|
-
listBranches,
|
|
62
|
-
manageLabels,
|
|
63
|
-
manageGist,
|
|
64
|
-
manageCollaborators,
|
|
65
|
-
getUser,
|
|
66
|
-
createCommitStatus
|
|
67
|
-
],
|
|
68
|
-
triggers: [
|
|
69
|
-
pushTrigger,
|
|
70
|
-
pullRequestTrigger,
|
|
71
|
-
pullRequestReviewTrigger,
|
|
72
|
-
issuesTrigger,
|
|
73
|
-
issueCommentTrigger,
|
|
74
|
-
workflowRunTrigger,
|
|
75
|
-
releaseTrigger,
|
|
76
|
-
starTrigger
|
|
77
|
-
]
|
|
78
|
-
});
|