@sanoma-ai/connector-github 0.6.1 → 0.7.1
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/README.md +20 -2
- package/dist/connector.d.ts +249 -0
- package/dist/connector.js +107 -1
- package/dist/connector.js.map +1 -1
- package/dist/driver.d.ts +6 -3
- package/dist/driver.js +188 -6
- package/dist/driver.js.map +1 -1
- package/dist/fake.d.ts +586 -315
- package/dist/fake.js +146 -3
- package/dist/fake.js.map +1 -1
- package/dist/index.d.ts +442 -3
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/remote.d.ts +1 -8
- package/dist/remote.js +7 -87
- package/dist/remote.js.map +1 -1
- package/dist/rest.d.ts +41 -0
- package/dist/rest.js +112 -0
- package/dist/rest.js.map +1 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @sanoma-ai/connector-github
|
|
2
2
|
|
|
3
|
-
GitHub resources for [`@sanoma-ai/workflows`](https://www.npmjs.com/package/@sanoma-ai/workflows): repositories, branch protection rules, team memberships and deploy keys, read through the [`integrations/github`](https://github.com/integrations/terraform-provider-github) OpenTofu provider (6.13.0) on [provider-bridge](https://github.com/Sanoma-AI/provider-bridge), and the company repository's pull requests, through its [remote half](#remote-half).
|
|
3
|
+
GitHub resources for [`@sanoma-ai/workflows`](https://www.npmjs.com/package/@sanoma-ai/workflows): repositories, branch protection rules, team memberships and deploy keys, read through the [`integrations/github`](https://github.com/integrations/terraform-provider-github) OpenTofu provider (6.13.0) on [provider-bridge](https://github.com/Sanoma-AI/provider-bridge); operations a workflow calls [through Sanoma's GitHub App](#through-the-app) (a repository generated from a template, files committed, a deploy key added); and the company repository's pull requests, through its [remote half](#remote-half).
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
@@ -74,6 +74,24 @@ Every call is plain `fetch` with GitHub's media type and `X-GitHub-Api-Version:
|
|
|
74
74
|
|
|
75
75
|
`@sanoma-ai/connector-github/remote` exports `githubRemote`, `githubToken`, `appJwt` and `GITHUB_APP_SECRETS`.
|
|
76
76
|
|
|
77
|
+
## Through the App
|
|
78
|
+
|
|
79
|
+
Five operations act through Sanoma's GitHub App, for a workflow to call (`github.repository.generate` and the others, imported from the package root like any operation). Each signs a JWT with the App's keys, `SANOMA_GITHUB_APP_ID` and `SANOMA_GITHUB_APP_PEM`, read from the call's secrets when called (what the app's **Create GitHub App** stores), and, but for `installation.get`, mints an installation token with it for that call alone (for the one repository named, when there is one). The token is never stored, logged or returned. Without the keys, a call fails, not retryable, `vendorCode` `no_app`.
|
|
80
|
+
|
|
81
|
+
| Operation | Input | Output | GitHub's REST API |
|
|
82
|
+
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
83
|
+
| `github.installation.get` | `{ id: number }` | `{ id, account: { login, id, type: "User" \| "Organization" }, repositorySelection: "all" \| "selected" }` | `GET /app/installations/{id}`, with the App's JWT. Effect `read`, idempotent |
|
|
84
|
+
| `github.repository.generate` | `{ installation: number, template: { owner, repository }, owner, name, private?: boolean (true), description? }` | `{ id, fullName, cloneUrl, sshUrl, defaultBranch }` | `POST /repos/{template owner}/{template}/generate`, its default branch only (`include_all_branches: false`). Effect `write` |
|
|
85
|
+
| `github.repository.commit` | `{ installation: number, repository: "owner/name", branch, message, files: Record<path, text> }` | `{ sha }` | One commit with Git's data API: the branch's head and tree (`GET …/branches/{branch}`), a tree over it with the files' contents, a commit, the ref moved (`PATCH`), or made (`POST`) for a branch not there yet, which starts from the default branch. Effect `write` |
|
|
86
|
+
| `github.repository.head` | `{ installation: number, repository: "owner/name", branch }` | `{ sha }` | `GET /repos/{owner}/{repo}/branches/{branch}`: the commit the branch is at. Effect `read`, idempotent |
|
|
87
|
+
| `github.repository.addDeployKey` | `{ installation: number, repository: "owner/name", title, key, readOnly?: boolean (true) }` | `{ id }` | `POST /repos/{owner}/{repo}/keys`. Effect `write` |
|
|
88
|
+
|
|
89
|
+
All five are idempotent, so a call that fails retryably is tried again: a try after one whose answer was lost repeats nothing. `generate` answers the repository already there when GitHub says the name exists and that repository was made from the same template; `commit` makes no commit when the branch's head already has the same tree and message; `addDeployKey` answers the key already on the repository when GitHub says it is in use. A failure is a `DriverError` with GitHub's status and message (a 422's validation errors after it, such as "Validation Failed: name already exists on this account"), retryable on a server error or a rate limit, as the remote half's are. A repository just generated fills from its template in the background, so a commit that starts a branch waits up to ten seconds for the default branch, then fails retryably (`vendorCode` `no_branch`). `commit` writes each file as a regular file (mode `100644`), so a file it rewrites loses an executable bit. The template must be public or one the installation reaches.
|
|
90
|
+
|
|
91
|
+
The App needs, on the accounts it is installed on: **Contents: write** (the commit), **Administration: write** (deploy keys, and generate until the narrower permission is granted), **Repository creation: write** (generate; a GitHub App permission since 2026-10-13) and **Metadata: read**. Whether an installation token may generate a repository under a personal account, not only an organization, is what #513's first step checks live.
|
|
92
|
+
|
|
93
|
+
The fake answers these from `fake.app` (`fakeGithubApp`), an in-memory GitHub with its own state: installation 7 on the personal account `acme` (account id 7), 9 on the organization `acme-inc` (account id 9), and the template `Sanoma-AI/company-template`. Its faults (`failNext` and the others) reach the operations through the App by their ids too.
|
|
94
|
+
|
|
77
95
|
## Resource types
|
|
78
96
|
|
|
79
97
|
`src/resources.gen.ts` is generated from the provider's schema by `pnpm generate`, which runs [`@sanoma-ai/bridge/tfschema`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/bridge/src/tfschema/AGENTS.md) with `src/resources.config.ts`: the provider (its release, sha256 and recorded schema are `@sanoma-ai/bridge`'s pin and fixture), the types to generate, and the attributes whose change replaces the object (ForceNew in the provider's source, which the schema does not carry). It is checked in and never edited by hand; `pnpm generate` on a clean tree changes nothing. `src/connector.ts` is the rest, one `tfConnector` record from [`@sanoma-ai/bridge/connector`](https://github.com/Sanoma-AI/sanoma/blob/main/packages/bridge/README.md#connectors-for-opentofu-providers): each type's title, identity, `find` and `bindingId`, the fields that name another resource (`branch_protection.repository_id`, `repository_deploy_key.repository`), and GitHub's title, logo and package. The connector, the constructors, the driver and the fake all derive from it.
|
|
@@ -102,7 +120,7 @@ Read on every call, never when the config loads:
|
|
|
102
120
|
| -------------- | --------------------------------------------------------------------- |
|
|
103
121
|
| `GITHUB_TOKEN` | A GitHub token that can read the repositories, rules and teams named. |
|
|
104
122
|
|
|
105
|
-
|
|
123
|
+
It is optional, since the operations [through the App](#through-the-app) need none: when it is unset, a resource operation fails, not retryable, naming it; the worker starts regardless, and the app's connector page shows and sets it. The bridge passes the token and the owner to the provider through its config only, never through the provider's environment. The default bridge's binary comes with `@sanoma-ai/bridge` or from `SANOMA_BRIDGE_BIN` (see [the bridge](https://www.npmjs.com/package/@sanoma-ai/bridge#the-binary)), not a credential of the connector.
|
|
106
124
|
|
|
107
125
|
### Errors and retries
|
|
108
126
|
|
package/dist/connector.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Connector } from "@sanoma-ai/workflows";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
/**
|
|
3
4
|
* GitHub, through the `integrations/github` OpenTofu provider: the generated resource types,
|
|
@@ -332,3 +333,251 @@ export declare const githubTf: import("@sanoma-ai/bridge/connector").TfConnector
|
|
|
332
333
|
};
|
|
333
334
|
};
|
|
334
335
|
}>;
|
|
336
|
+
/** The account an installation of the App is on: its login, and its id, which a rename keeps. */
|
|
337
|
+
export declare const Account: z.ZodObject<{
|
|
338
|
+
login: z.ZodString;
|
|
339
|
+
id: z.ZodNumber;
|
|
340
|
+
type: z.ZodEnum<{
|
|
341
|
+
Organization: "Organization";
|
|
342
|
+
User: "User";
|
|
343
|
+
}>;
|
|
344
|
+
}, z.core.$strip>;
|
|
345
|
+
/**
|
|
346
|
+
* The operations through Sanoma's GitHub App, for a workflow to call: each mints an installation
|
|
347
|
+
* token from the App's keys when called, which is never stored or returned.
|
|
348
|
+
*/
|
|
349
|
+
declare const appSpecs: {
|
|
350
|
+
installation: {
|
|
351
|
+
get: {
|
|
352
|
+
effect: "read";
|
|
353
|
+
idempotent: true;
|
|
354
|
+
description: string;
|
|
355
|
+
input: z.ZodObject<{
|
|
356
|
+
id: z.ZodNumber;
|
|
357
|
+
}, z.core.$strip>;
|
|
358
|
+
output: z.ZodObject<{
|
|
359
|
+
id: z.ZodNumber;
|
|
360
|
+
account: z.ZodObject<{
|
|
361
|
+
login: z.ZodString;
|
|
362
|
+
id: z.ZodNumber;
|
|
363
|
+
type: z.ZodEnum<{
|
|
364
|
+
Organization: "Organization";
|
|
365
|
+
User: "User";
|
|
366
|
+
}>;
|
|
367
|
+
}, z.core.$strip>;
|
|
368
|
+
repositorySelection: z.ZodEnum<{
|
|
369
|
+
all: "all";
|
|
370
|
+
selected: "selected";
|
|
371
|
+
}>;
|
|
372
|
+
}, z.core.$strip>;
|
|
373
|
+
target: ({ id }: {
|
|
374
|
+
id: number;
|
|
375
|
+
}) => string;
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
repository: {
|
|
379
|
+
generate: {
|
|
380
|
+
effect: "write";
|
|
381
|
+
idempotent: true;
|
|
382
|
+
description: string;
|
|
383
|
+
input: z.ZodObject<{
|
|
384
|
+
installation: z.ZodNumber;
|
|
385
|
+
template: z.ZodObject<{
|
|
386
|
+
owner: z.ZodString;
|
|
387
|
+
repository: z.ZodString;
|
|
388
|
+
}, z.core.$strip>;
|
|
389
|
+
owner: z.ZodString;
|
|
390
|
+
name: z.ZodString;
|
|
391
|
+
private: z.ZodDefault<z.ZodBoolean>;
|
|
392
|
+
description: z.ZodOptional<z.ZodString>;
|
|
393
|
+
}, z.core.$strip>;
|
|
394
|
+
output: z.ZodObject<{
|
|
395
|
+
id: z.ZodNumber;
|
|
396
|
+
fullName: z.ZodString;
|
|
397
|
+
cloneUrl: z.ZodString;
|
|
398
|
+
sshUrl: z.ZodString;
|
|
399
|
+
defaultBranch: z.ZodString;
|
|
400
|
+
}, z.core.$strip>;
|
|
401
|
+
target: ({ owner, name }: {
|
|
402
|
+
owner: string;
|
|
403
|
+
name: string;
|
|
404
|
+
}) => string;
|
|
405
|
+
};
|
|
406
|
+
commit: {
|
|
407
|
+
effect: "write";
|
|
408
|
+
idempotent: true;
|
|
409
|
+
description: string;
|
|
410
|
+
input: z.ZodObject<{
|
|
411
|
+
installation: z.ZodNumber;
|
|
412
|
+
repository: z.ZodString;
|
|
413
|
+
branch: z.ZodString;
|
|
414
|
+
message: z.ZodString;
|
|
415
|
+
files: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
416
|
+
}, z.core.$strip>;
|
|
417
|
+
output: z.ZodObject<{
|
|
418
|
+
sha: z.ZodString;
|
|
419
|
+
}, z.core.$strip>;
|
|
420
|
+
target: ({ repository }: {
|
|
421
|
+
repository: string;
|
|
422
|
+
}) => string;
|
|
423
|
+
};
|
|
424
|
+
head: {
|
|
425
|
+
effect: "read";
|
|
426
|
+
idempotent: true;
|
|
427
|
+
description: string;
|
|
428
|
+
input: z.ZodObject<{
|
|
429
|
+
installation: z.ZodNumber;
|
|
430
|
+
repository: z.ZodString;
|
|
431
|
+
branch: z.ZodString;
|
|
432
|
+
}, z.core.$strip>;
|
|
433
|
+
output: z.ZodObject<{
|
|
434
|
+
sha: z.ZodString;
|
|
435
|
+
}, z.core.$strip>;
|
|
436
|
+
target: ({ repository }: {
|
|
437
|
+
repository: string;
|
|
438
|
+
}) => string;
|
|
439
|
+
};
|
|
440
|
+
addDeployKey: {
|
|
441
|
+
effect: "write";
|
|
442
|
+
idempotent: true;
|
|
443
|
+
description: string;
|
|
444
|
+
input: z.ZodObject<{
|
|
445
|
+
installation: z.ZodNumber;
|
|
446
|
+
repository: z.ZodString;
|
|
447
|
+
title: z.ZodString;
|
|
448
|
+
key: z.ZodString;
|
|
449
|
+
readOnly: z.ZodDefault<z.ZodBoolean>;
|
|
450
|
+
}, z.core.$strip>;
|
|
451
|
+
output: z.ZodObject<{
|
|
452
|
+
id: z.ZodNumber;
|
|
453
|
+
}, z.core.$strip>;
|
|
454
|
+
target: ({ repository }: {
|
|
455
|
+
repository: string;
|
|
456
|
+
}) => string;
|
|
457
|
+
};
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
/** The operations through the App alone: what the driver's and the fake's App halves implement. */
|
|
461
|
+
export declare const githubApp: Connector<"github", {
|
|
462
|
+
installation: {
|
|
463
|
+
get: {
|
|
464
|
+
effect: "read";
|
|
465
|
+
idempotent: true;
|
|
466
|
+
description: string;
|
|
467
|
+
input: z.ZodObject<{
|
|
468
|
+
id: z.ZodNumber;
|
|
469
|
+
}, z.core.$strip>;
|
|
470
|
+
output: z.ZodObject<{
|
|
471
|
+
id: z.ZodNumber;
|
|
472
|
+
account: z.ZodObject<{
|
|
473
|
+
login: z.ZodString;
|
|
474
|
+
id: z.ZodNumber;
|
|
475
|
+
type: z.ZodEnum<{
|
|
476
|
+
Organization: "Organization";
|
|
477
|
+
User: "User";
|
|
478
|
+
}>;
|
|
479
|
+
}, z.core.$strip>;
|
|
480
|
+
repositorySelection: z.ZodEnum<{
|
|
481
|
+
all: "all";
|
|
482
|
+
selected: "selected";
|
|
483
|
+
}>;
|
|
484
|
+
}, z.core.$strip>;
|
|
485
|
+
target: ({ id }: {
|
|
486
|
+
id: number;
|
|
487
|
+
}) => string;
|
|
488
|
+
};
|
|
489
|
+
};
|
|
490
|
+
repository: {
|
|
491
|
+
generate: {
|
|
492
|
+
effect: "write";
|
|
493
|
+
idempotent: true;
|
|
494
|
+
description: string;
|
|
495
|
+
input: z.ZodObject<{
|
|
496
|
+
installation: z.ZodNumber;
|
|
497
|
+
template: z.ZodObject<{
|
|
498
|
+
owner: z.ZodString;
|
|
499
|
+
repository: z.ZodString;
|
|
500
|
+
}, z.core.$strip>;
|
|
501
|
+
owner: z.ZodString;
|
|
502
|
+
name: z.ZodString;
|
|
503
|
+
private: z.ZodDefault<z.ZodBoolean>;
|
|
504
|
+
description: z.ZodOptional<z.ZodString>;
|
|
505
|
+
}, z.core.$strip>;
|
|
506
|
+
output: z.ZodObject<{
|
|
507
|
+
id: z.ZodNumber;
|
|
508
|
+
fullName: z.ZodString;
|
|
509
|
+
cloneUrl: z.ZodString;
|
|
510
|
+
sshUrl: z.ZodString;
|
|
511
|
+
defaultBranch: z.ZodString;
|
|
512
|
+
}, z.core.$strip>;
|
|
513
|
+
target: ({ owner, name }: {
|
|
514
|
+
owner: string;
|
|
515
|
+
name: string;
|
|
516
|
+
}) => string;
|
|
517
|
+
};
|
|
518
|
+
commit: {
|
|
519
|
+
effect: "write";
|
|
520
|
+
idempotent: true;
|
|
521
|
+
description: string;
|
|
522
|
+
input: z.ZodObject<{
|
|
523
|
+
installation: z.ZodNumber;
|
|
524
|
+
repository: z.ZodString;
|
|
525
|
+
branch: z.ZodString;
|
|
526
|
+
message: z.ZodString;
|
|
527
|
+
files: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
528
|
+
}, z.core.$strip>;
|
|
529
|
+
output: z.ZodObject<{
|
|
530
|
+
sha: z.ZodString;
|
|
531
|
+
}, z.core.$strip>;
|
|
532
|
+
target: ({ repository }: {
|
|
533
|
+
repository: string;
|
|
534
|
+
}) => string;
|
|
535
|
+
};
|
|
536
|
+
head: {
|
|
537
|
+
effect: "read";
|
|
538
|
+
idempotent: true;
|
|
539
|
+
description: string;
|
|
540
|
+
input: z.ZodObject<{
|
|
541
|
+
installation: z.ZodNumber;
|
|
542
|
+
repository: z.ZodString;
|
|
543
|
+
branch: z.ZodString;
|
|
544
|
+
}, z.core.$strip>;
|
|
545
|
+
output: z.ZodObject<{
|
|
546
|
+
sha: z.ZodString;
|
|
547
|
+
}, z.core.$strip>;
|
|
548
|
+
target: ({ repository }: {
|
|
549
|
+
repository: string;
|
|
550
|
+
}) => string;
|
|
551
|
+
};
|
|
552
|
+
addDeployKey: {
|
|
553
|
+
effect: "write";
|
|
554
|
+
idempotent: true;
|
|
555
|
+
description: string;
|
|
556
|
+
input: z.ZodObject<{
|
|
557
|
+
installation: z.ZodNumber;
|
|
558
|
+
repository: z.ZodString;
|
|
559
|
+
title: z.ZodString;
|
|
560
|
+
key: z.ZodString;
|
|
561
|
+
readOnly: z.ZodDefault<z.ZodBoolean>;
|
|
562
|
+
}, z.core.$strip>;
|
|
563
|
+
output: z.ZodObject<{
|
|
564
|
+
id: z.ZodNumber;
|
|
565
|
+
}, z.core.$strip>;
|
|
566
|
+
target: ({ repository }: {
|
|
567
|
+
repository: string;
|
|
568
|
+
}) => string;
|
|
569
|
+
};
|
|
570
|
+
};
|
|
571
|
+
}>;
|
|
572
|
+
/** The connector's specs: the resource types, the repository's group with the operations through the App, and the installation's. */
|
|
573
|
+
type GithubSpecs = Omit<typeof githubTf.resources, "repository"> & {
|
|
574
|
+
repository: (typeof githubTf.resources)["repository"]["ops"] & typeof appSpecs.repository;
|
|
575
|
+
installation: typeof appSpecs.installation;
|
|
576
|
+
};
|
|
577
|
+
/**
|
|
578
|
+
* The connector's operations: each resource type's (`github.repository.read`, …), and those
|
|
579
|
+
* through the App, `installation.get` and, in the repository's group, `generate`, `commit`, `head` and
|
|
580
|
+
* `addDeployKey` (Neon's pattern for operations beside a type's).
|
|
581
|
+
*/
|
|
582
|
+
export declare const githubOps: Connector<"github", GithubSpecs>;
|
|
583
|
+
export {};
|
package/dist/connector.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tfConnector } from "@sanoma-ai/bridge/connector";
|
|
2
|
-
import { vendorInfo } from "@sanoma-ai/workflows";
|
|
2
|
+
import { defineConnector, vendorInfo } from "@sanoma-ai/workflows";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { github_branch_protection, github_repository, github_repository_deploy_key, github_team_membership, provider, } from "./resources.gen.js";
|
|
5
5
|
/**
|
|
@@ -65,4 +65,110 @@ export const githubTf = tfConnector({
|
|
|
65
65
|
(e.code === "failed_precondition" && e.diagnostics.some((d) => d.summary.startsWith("could not find "))),
|
|
66
66
|
info: vendorInfo(import.meta.url),
|
|
67
67
|
});
|
|
68
|
+
/** The account an installation of the App is on: its login, and its id, which a rename keeps. */
|
|
69
|
+
export const Account = z.object({ login: z.string(), id: z.number(), type: z.enum(["User", "Organization"]) });
|
|
70
|
+
/** An account's or a repository's name: GitHub's characters, never `.` or `..` alone (a path's own). */
|
|
71
|
+
const part = z.string().regex(/^(?!\.\.?$)[\w.-]+$/, "a GitHub name: letters, digits, `-`, `_` and `.`");
|
|
72
|
+
/** `<owner>/<name>`, as GitHub's `full_name`. */
|
|
73
|
+
const fullName = z
|
|
74
|
+
.string()
|
|
75
|
+
.regex(/^(?!\.\.?\/)[\w.-]+\/(?!\.\.?$)[\w.-]+$/, "a repository as <owner>/<name>")
|
|
76
|
+
.describe("The repository, as <owner>/<name>");
|
|
77
|
+
const installation = z.number().int().positive().describe("The id of the App's installation that acts");
|
|
78
|
+
/**
|
|
79
|
+
* The operations through Sanoma's GitHub App, for a workflow to call: each mints an installation
|
|
80
|
+
* token from the App's keys when called, which is never stored or returned.
|
|
81
|
+
*/
|
|
82
|
+
const appSpecs = {
|
|
83
|
+
installation: {
|
|
84
|
+
get: {
|
|
85
|
+
effect: "read",
|
|
86
|
+
idempotent: true,
|
|
87
|
+
description: "Read an installation of the GitHub App: the account it is on and which repositories it covers",
|
|
88
|
+
input: z.object({ id: z.number().int().positive().describe("The installation's id") }),
|
|
89
|
+
output: z.object({
|
|
90
|
+
id: z.number(),
|
|
91
|
+
account: Account,
|
|
92
|
+
repositorySelection: z.enum(["all", "selected"]),
|
|
93
|
+
}),
|
|
94
|
+
target: ({ id }) => String(id),
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
repository: {
|
|
98
|
+
generate: {
|
|
99
|
+
effect: "write",
|
|
100
|
+
// The driver finds what an earlier try of the same step made, so a retry repeats nothing.
|
|
101
|
+
idempotent: true,
|
|
102
|
+
description: "Make a repository from a template repository, through an installation of the GitHub App",
|
|
103
|
+
input: z.object({
|
|
104
|
+
installation,
|
|
105
|
+
template: z.object({ owner: part, repository: part }).describe("The template"),
|
|
106
|
+
owner: part.describe("The account the new repository belongs to"),
|
|
107
|
+
name: part.describe("The new repository's name"),
|
|
108
|
+
private: z.boolean().default(true).describe("Whether it is private (the default)"),
|
|
109
|
+
description: z.string().optional(),
|
|
110
|
+
}),
|
|
111
|
+
output: z.object({
|
|
112
|
+
id: z.number(),
|
|
113
|
+
fullName: z.string(),
|
|
114
|
+
cloneUrl: z.string(),
|
|
115
|
+
sshUrl: z.string(),
|
|
116
|
+
defaultBranch: z.string(),
|
|
117
|
+
}),
|
|
118
|
+
target: ({ owner, name }) => `${owner}/${name}`,
|
|
119
|
+
},
|
|
120
|
+
commit: {
|
|
121
|
+
effect: "write",
|
|
122
|
+
// The driver finds what an earlier try of the same step made, so a retry repeats nothing.
|
|
123
|
+
idempotent: true,
|
|
124
|
+
description: "Commit files (path to text) on top of a branch, through an installation of the GitHub App; a branch not there yet starts from the default branch",
|
|
125
|
+
input: z.object({
|
|
126
|
+
installation,
|
|
127
|
+
repository: fullName,
|
|
128
|
+
branch: z.string().min(1),
|
|
129
|
+
message: z.string().min(1),
|
|
130
|
+
files: z.record(z.string().min(1), z.string()).describe("Each file's path and its whole text"),
|
|
131
|
+
}),
|
|
132
|
+
output: z.object({ sha: z.string().describe("The new commit's") }),
|
|
133
|
+
target: ({ repository }) => repository,
|
|
134
|
+
},
|
|
135
|
+
head: {
|
|
136
|
+
effect: "read",
|
|
137
|
+
idempotent: true,
|
|
138
|
+
description: "Read the commit a branch is at, through an installation of the GitHub App",
|
|
139
|
+
input: z.object({ installation, repository: fullName, branch: z.string().min(1) }),
|
|
140
|
+
output: z.object({ sha: z.string().describe("The branch's head commit") }),
|
|
141
|
+
target: ({ repository }) => repository,
|
|
142
|
+
},
|
|
143
|
+
addDeployKey: {
|
|
144
|
+
effect: "write",
|
|
145
|
+
// The driver finds what an earlier try of the same step made, so a retry repeats nothing.
|
|
146
|
+
idempotent: true,
|
|
147
|
+
description: "Add an SSH deploy key to a repository, through an installation of the GitHub App",
|
|
148
|
+
input: z.object({
|
|
149
|
+
installation,
|
|
150
|
+
repository: fullName,
|
|
151
|
+
title: z.string().min(1),
|
|
152
|
+
key: z.string().min(1).describe("The public key, as `<type> <base64>`"),
|
|
153
|
+
readOnly: z.boolean().default(true).describe("Whether it may only fetch (the default)"),
|
|
154
|
+
}),
|
|
155
|
+
output: z.object({ id: z.number() }),
|
|
156
|
+
target: ({ repository }) => repository,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
/** The operations through the App alone: what the driver's and the fake's App halves implement. */
|
|
161
|
+
export const githubApp = defineConnector("github", appSpecs);
|
|
162
|
+
const types = githubTf.connector;
|
|
163
|
+
/**
|
|
164
|
+
* The connector's operations: each resource type's (`github.repository.read`, …), and those
|
|
165
|
+
* through the App, `installation.get` and, in the repository's group, `generate`, `commit`, `head` and
|
|
166
|
+
* `addDeployKey` (Neon's pattern for operations beside a type's).
|
|
167
|
+
*/
|
|
168
|
+
export const githubOps = {
|
|
169
|
+
...githubApp,
|
|
170
|
+
// `types` last: its vendor (who GitHub is, and its resource types) is the connector's.
|
|
171
|
+
...types,
|
|
172
|
+
repository: { ...types.repository, ...githubApp.repository },
|
|
173
|
+
};
|
|
68
174
|
//# sourceMappingURL=connector.js.map
|
package/dist/connector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.js","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"connector.js","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAkB,eAAe,EAAe,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,CAAC,EAAE,MAAM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YACF,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YACpC,MAAM,EAAE,CAAC,EAAE,UAAU,EAA0B,EAAE,EAAE,CAAC,UAAU;SAC/D;KACF;CAC+C,CAAC;AAEnD,mGAAmG;AACnG,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE7D,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC;AAQjC;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,GAAG,SAAS;IACZ,uFAAuF;IACvF,GAAG,KAAK;IACR,UAAU,EAAE,EAAE,GAAG,KAAK,CAAC,UAAU,EAAE,GAAG,SAAS,CAAC,UAAU,EAAE;CACd,CAAC"}
|
package/dist/driver.d.ts
CHANGED
|
@@ -13,13 +13,16 @@ export interface GithubDriverOptions {
|
|
|
13
13
|
* the owner each call names (`owned`): the provider is configured with `{ owner, token }` on the
|
|
14
14
|
* first call, and again when either changes or the provider has exited; a call for another owner
|
|
15
15
|
* waits for those running for the one configured. A repository's or a rule's node id (its
|
|
16
|
-
* binding id) is resolved first, by GraphQL (`resolveNode`).
|
|
16
|
+
* binding id) is resolved first, by GraphQL (`resolveNode`). The operations through the App
|
|
17
|
+
* (`appDriver`) sign in with the App's keys instead.
|
|
17
18
|
*/
|
|
18
19
|
export declare function githubDriver({ bridge }?: GithubDriverOptions): Readonly<{
|
|
19
20
|
vendor: string;
|
|
20
|
-
ops: Readonly<Record<string, import("@sanoma-ai/workflows").DriverFn>>;
|
|
21
21
|
authentication?: readonly string[];
|
|
22
|
+
ops: Readonly<{
|
|
23
|
+
[x: string]: import("@sanoma-ai/workflows").DriverFn<any, unknown>;
|
|
24
|
+
}>;
|
|
22
25
|
env: z.ZodObject<{
|
|
23
|
-
GITHUB_TOKEN: z.ZodString
|
|
26
|
+
GITHUB_TOKEN: z.ZodOptional<z.ZodString>;
|
|
24
27
|
}, z.core.$strip>;
|
|
25
28
|
}>;
|