-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.zod.ts
More file actions
528 lines (453 loc) · 13.5 KB
/
github.zod.ts
File metadata and controls
528 lines (453 loc) · 13.5 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
import {
ConnectorSchema,
} from '../connector.zod';
/**
* GitHub Connector Protocol
*
* Specialized connector for GitHub integration enabling automated
* version control operations, CI/CD workflows, and release management.
*
* Use Cases:
* - Automated code commits and pull requests
* - GitHub Actions workflow management
* - Issue and project tracking
* - Release and tag management
* - Repository administration
*
* @example
* ```typescript
* import { GitHubConnector } from '@objectstack/spec/integration';
*
* const githubConnector: GitHubConnector = {
* name: 'github_enterprise',
* label: 'GitHub Enterprise',
* type: 'saas',
* provider: 'github',
* baseUrl: 'https://api.github.com',
* authentication: {
* type: 'oauth2',
* clientId: '${GITHUB_CLIENT_ID}',
* clientSecret: '${GITHUB_CLIENT_SECRET}',
* authorizationUrl: 'https://github.com/login/oauth/authorize',
* tokenUrl: 'https://github.com/login/oauth/access_token',
* grantType: 'authorization_code',
* scopes: ['repo', 'workflow', 'admin:org'],
* },
* repositories: [
* {
* owner: 'objectstack-ai',
* name: 'spec',
* defaultBranch: 'main',
* autoMerge: false,
* },
* ],
* };
* ```
*/
/**
* GitHub Provider Type
*/
export const GitHubProviderSchema = z.enum([
'github', // GitHub.com
'github_enterprise', // GitHub Enterprise Server
]).describe('GitHub provider type');
export type GitHubProvider = z.infer<typeof GitHubProviderSchema>;
/**
* GitHub Repository Configuration
* Defines a repository to integrate with
*/
export const GitHubRepositorySchema = z.object({
/**
* Repository owner (organization or user)
*/
owner: z.string().describe('Repository owner (organization or username)'),
/**
* Repository name
*/
name: z.string().describe('Repository name'),
/**
* Default branch name
*/
defaultBranch: z.string().optional().default('main').describe('Default branch name'),
/**
* Enable auto-merge for PRs
*/
autoMerge: z.boolean().optional().default(false).describe('Enable auto-merge for pull requests'),
/**
* Branch protection rules
*/
branchProtection: z.object({
requiredReviewers: z.number().int().min(0).optional().default(1).describe('Required number of reviewers'),
requireStatusChecks: z.boolean().optional().default(true).describe('Require status checks to pass'),
enforceAdmins: z.boolean().optional().default(false).describe('Enforce protections for admins'),
allowForcePushes: z.boolean().optional().default(false).describe('Allow force pushes'),
allowDeletions: z.boolean().optional().default(false).describe('Allow branch deletions'),
}).optional().describe('Branch protection configuration'),
/**
* Repository topics/tags
*/
topics: z.array(z.string()).optional().describe('Repository topics'),
});
export type GitHubRepository = z.infer<typeof GitHubRepositorySchema>;
/**
* GitHub Commit Configuration
*/
export const GitHubCommitConfigSchema = z.object({
/**
* Commit author name
*/
authorName: z.string().optional().describe('Commit author name'),
/**
* Commit author email
*/
authorEmail: z.string().email().optional().describe('Commit author email'),
/**
* GPG sign commits
*/
signCommits: z.boolean().optional().default(false).describe('Sign commits with GPG'),
/**
* Commit message template
*/
messageTemplate: z.string().optional().describe('Commit message template'),
/**
* Conventional commits format
*/
useConventionalCommits: z.boolean().optional().default(true).describe('Use conventional commits format'),
});
export type GitHubCommitConfig = z.infer<typeof GitHubCommitConfigSchema>;
/**
* GitHub Pull Request Configuration
*/
export const GitHubPullRequestConfigSchema = z.object({
/**
* Default PR title template
*/
titleTemplate: z.string().optional().describe('PR title template'),
/**
* Default PR body template
*/
bodyTemplate: z.string().optional().describe('PR body template'),
/**
* Default reviewers
*/
defaultReviewers: z.array(z.string()).optional().describe('Default reviewers (usernames)'),
/**
* Default assignees
*/
defaultAssignees: z.array(z.string()).optional().describe('Default assignees (usernames)'),
/**
* Default labels
*/
defaultLabels: z.array(z.string()).optional().describe('Default labels'),
/**
* Enable draft PRs by default
*/
draftByDefault: z.boolean().optional().default(false).describe('Create draft PRs by default'),
/**
* Auto-delete head branch after merge
*/
deleteHeadBranch: z.boolean().optional().default(true).describe('Delete head branch after merge'),
});
export type GitHubPullRequestConfig = z.infer<typeof GitHubPullRequestConfigSchema>;
/**
* GitHub Actions Workflow Configuration
*/
export const GitHubActionsWorkflowSchema = z.object({
/**
* Workflow name
*/
name: z.string().describe('Workflow name'),
/**
* Workflow file path
*/
path: z.string().describe('Workflow file path (e.g., .github/workflows/ci.yml)'),
/**
* Enable workflow
*/
enabled: z.boolean().optional().default(true).describe('Enable workflow'),
/**
* Workflow triggers
*/
triggers: z.array(z.enum([
'push',
'pull_request',
'release',
'schedule',
'workflow_dispatch',
'repository_dispatch',
])).optional().describe('Workflow triggers'),
/**
* Environment variables
*/
env: z.record(z.string(), z.string()).optional().describe('Environment variables'),
/**
* Secrets required
*/
secrets: z.array(z.string()).optional().describe('Required secrets'),
});
export type GitHubActionsWorkflow = z.infer<typeof GitHubActionsWorkflowSchema>;
/**
* GitHub Release Configuration
*/
export const GitHubReleaseConfigSchema = z.object({
/**
* Tag name pattern
*/
tagPattern: z.string().optional().default('v*').describe('Tag name pattern (e.g., v*, release/*)'),
/**
* Use semantic versioning
*/
semanticVersioning: z.boolean().optional().default(true).describe('Use semantic versioning'),
/**
* Generate release notes automatically
*/
autoReleaseNotes: z.boolean().optional().default(true).describe('Generate release notes automatically'),
/**
* Release name template
*/
releaseNameTemplate: z.string().optional().describe('Release name template'),
/**
* Pre-release pattern
*/
preReleasePattern: z.string().optional().describe('Pre-release pattern (e.g., *-alpha, *-beta)'),
/**
* Create draft releases
*/
draftByDefault: z.boolean().optional().default(false).describe('Create draft releases by default'),
});
export type GitHubReleaseConfig = z.infer<typeof GitHubReleaseConfigSchema>;
/**
* GitHub Issue Tracking Configuration
*/
export const GitHubIssueTrackingSchema = z.object({
/**
* Enable issue tracking
*/
enabled: z.boolean().optional().default(true).describe('Enable issue tracking'),
/**
* Default issue labels
*/
defaultLabels: z.array(z.string()).optional().describe('Default issue labels'),
/**
* Issue template paths
*/
templatePaths: z.array(z.string()).optional().describe('Issue template paths'),
/**
* Auto-assign issues
*/
autoAssign: z.boolean().optional().default(false).describe('Auto-assign issues'),
/**
* Auto-close stale issues
*/
autoCloseStale: z.object({
enabled: z.boolean().default(false),
daysBeforeStale: z.number().int().min(1).optional().default(60),
daysBeforeClose: z.number().int().min(1).optional().default(7),
staleLabel: z.string().optional().default('stale'),
}).optional().describe('Auto-close stale issues configuration'),
});
export type GitHubIssueTracking = z.infer<typeof GitHubIssueTrackingSchema>;
/**
* GitHub Connector Schema
* Complete GitHub integration configuration
*/
export const GitHubConnectorSchema = ConnectorSchema.extend({
type: z.literal('saas'),
/**
* GitHub provider type
*/
provider: GitHubProviderSchema.describe('GitHub provider'),
/**
* GitHub API base URL
*/
baseUrl: z.string().url().optional().default('https://api.github.com').describe('GitHub API base URL'),
/**
* Repositories to integrate
*/
repositories: z.array(GitHubRepositorySchema).describe('Repositories to manage'),
/**
* Commit configuration
*/
commitConfig: GitHubCommitConfigSchema.optional().describe('Commit configuration'),
/**
* Pull request configuration
*/
pullRequestConfig: GitHubPullRequestConfigSchema.optional().describe('Pull request configuration'),
/**
* GitHub Actions workflows
*/
workflows: z.array(GitHubActionsWorkflowSchema).optional().describe('GitHub Actions workflows'),
/**
* Release configuration
*/
releaseConfig: GitHubReleaseConfigSchema.optional().describe('Release configuration'),
/**
* Issue tracking configuration
*/
issueTracking: GitHubIssueTrackingSchema.optional().describe('Issue tracking configuration'),
/**
* Enable webhooks
*/
enableWebhooks: z.boolean().optional().default(true).describe('Enable GitHub webhooks'),
/**
* Webhook events to subscribe
*/
webhookEvents: z.array(z.enum([
'push',
'pull_request',
'issues',
'issue_comment',
'release',
'workflow_run',
'deployment',
'deployment_status',
'check_run',
'check_suite',
'status',
])).optional().describe('Webhook events to subscribe to'),
});
export type GitHubConnector = z.infer<typeof GitHubConnectorSchema>;
// ============================================================================
// Helper Functions & Examples
// ============================================================================
/**
* Example: GitHub.com Connector Configuration
*/
export const githubPublicConnectorExample = {
name: 'github_public',
label: 'GitHub.com',
type: 'saas',
provider: 'github',
baseUrl: 'https://api.github.com',
authentication: {
type: 'oauth2',
clientId: '${GITHUB_CLIENT_ID}',
clientSecret: '${GITHUB_CLIENT_SECRET}',
authorizationUrl: 'https://github.com/login/oauth/authorize',
tokenUrl: 'https://github.com/login/oauth/access_token',
scopes: ['repo', 'workflow', 'write:packages'],
},
repositories: [
{
owner: 'objectstack-ai',
name: 'spec',
defaultBranch: 'main',
autoMerge: false,
branchProtection: {
requiredReviewers: 1,
requireStatusChecks: true,
enforceAdmins: false,
allowForcePushes: false,
allowDeletions: false,
},
topics: ['objectstack', 'low-code', 'metadata-driven'],
},
],
commitConfig: {
authorName: 'ObjectStack Bot',
authorEmail: 'bot@objectstack.ai',
signCommits: false,
useConventionalCommits: true,
},
pullRequestConfig: {
titleTemplate: '{{type}}: {{description}}',
defaultReviewers: ['team-lead'],
defaultLabels: ['automated', 'ai-generated'],
draftByDefault: false,
deleteHeadBranch: true,
},
workflows: [
{
name: 'CI',
path: '.github/workflows/ci.yml',
enabled: true,
triggers: ['push', 'pull_request'],
},
{
name: 'Release',
path: '.github/workflows/release.yml',
enabled: true,
triggers: ['release'],
},
],
releaseConfig: {
tagPattern: 'v*',
semanticVersioning: true,
autoReleaseNotes: true,
releaseNameTemplate: 'Release {{version}}',
draftByDefault: false,
},
issueTracking: {
enabled: true,
defaultLabels: ['needs-triage'],
autoAssign: false,
autoCloseStale: {
enabled: true,
daysBeforeStale: 60,
daysBeforeClose: 7,
staleLabel: 'stale',
},
},
enableWebhooks: true,
webhookEvents: ['push', 'pull_request', 'release', 'workflow_run'],
status: 'active',
enabled: true,
};
/**
* Example: GitHub Enterprise Connector Configuration
*/
export const githubEnterpriseConnectorExample = {
name: 'github_enterprise',
label: 'GitHub Enterprise',
type: 'saas',
provider: 'github_enterprise',
baseUrl: 'https://github.enterprise.com/api/v3',
authentication: {
type: 'oauth2',
clientId: '${GITHUB_ENTERPRISE_CLIENT_ID}',
clientSecret: '${GITHUB_ENTERPRISE_CLIENT_SECRET}',
authorizationUrl: 'https://github.enterprise.com/login/oauth/authorize',
tokenUrl: 'https://github.enterprise.com/login/oauth/access_token',
scopes: ['repo', 'admin:org', 'workflow'],
},
repositories: [
{
owner: 'enterprise-org',
name: 'internal-app',
defaultBranch: 'develop',
autoMerge: true,
branchProtection: {
requiredReviewers: 2,
requireStatusChecks: true,
enforceAdmins: true,
allowForcePushes: false,
allowDeletions: false,
},
},
],
commitConfig: {
authorName: 'CI Bot',
authorEmail: 'ci-bot@enterprise.com',
signCommits: true,
useConventionalCommits: true,
},
pullRequestConfig: {
titleTemplate: '[{{branch}}] {{description}}',
bodyTemplate: `## Changes\n\n{{changes}}\n\n## Testing\n\n{{testing}}`,
defaultReviewers: ['tech-lead', 'security-team'],
defaultLabels: ['automated'],
draftByDefault: true,
deleteHeadBranch: true,
},
releaseConfig: {
tagPattern: 'release/*',
semanticVersioning: true,
autoReleaseNotes: true,
preReleasePattern: '*-rc*',
draftByDefault: true,
},
status: 'active',
enabled: true,
};