@relayflows/github-primitive 0.1.0
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/DESIGN.md +1054 -0
- package/README.md +129 -0
- package/dist/actions/branches.d.ts +13 -0
- package/dist/actions/branches.d.ts.map +1 -0
- package/dist/actions/branches.js +59 -0
- package/dist/actions/branches.js.map +1 -0
- package/dist/actions/commits.d.ts +15 -0
- package/dist/actions/commits.d.ts.map +1 -0
- package/dist/actions/commits.js +71 -0
- package/dist/actions/commits.js.map +1 -0
- package/dist/actions/files.d.ts +40 -0
- package/dist/actions/files.d.ts.map +1 -0
- package/dist/actions/files.js +133 -0
- package/dist/actions/files.js.map +1 -0
- package/dist/actions/issues.d.ts +29 -0
- package/dist/actions/issues.d.ts.map +1 -0
- package/dist/actions/issues.js +120 -0
- package/dist/actions/issues.js.map +1 -0
- package/dist/actions/pulls.d.ts +40 -0
- package/dist/actions/pulls.d.ts.map +1 -0
- package/dist/actions/pulls.js +169 -0
- package/dist/actions/pulls.js.map +1 -0
- package/dist/actions/repos.d.ts +18 -0
- package/dist/actions/repos.d.ts.map +1 -0
- package/dist/actions/repos.js +70 -0
- package/dist/actions/repos.js.map +1 -0
- package/dist/actions/users.d.ts +13 -0
- package/dist/actions/users.d.ts.map +1 -0
- package/dist/actions/users.js +51 -0
- package/dist/actions/users.js.map +1 -0
- package/dist/actions/utils.d.ts +39 -0
- package/dist/actions/utils.d.ts.map +1 -0
- package/dist/actions/utils.js +173 -0
- package/dist/actions/utils.js.map +1 -0
- package/dist/adapter.d.ts +49 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +493 -0
- package/dist/adapter.js.map +1 -0
- package/dist/client.d.ts +149 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +254 -0
- package/dist/client.js.map +1 -0
- package/dist/cloud-runtime.d.ts +31 -0
- package/dist/cloud-runtime.d.ts.map +1 -0
- package/dist/cloud-runtime.js +202 -0
- package/dist/cloud-runtime.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/local-runtime.d.ts +46 -0
- package/dist/local-runtime.d.ts.map +1 -0
- package/dist/local-runtime.js +225 -0
- package/dist/local-runtime.js.map +1 -0
- package/dist/types.d.ts +513 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +50 -0
- package/dist/types.js.map +1 -0
- package/docs/actions.md +49 -0
- package/examples/github-client.ts +38 -0
- package/package.json +43 -0
- package/templates/repository-inspection.yaml +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# @relayflows/github-primitive
|
|
2
|
+
|
|
3
|
+
GitHub workflow primitive for Agent Relay. It exposes a typed client and a
|
|
4
|
+
workflow integration step that can run through the local `gh` CLI or a cloud
|
|
5
|
+
GitHub proxy.
|
|
6
|
+
|
|
7
|
+
## Runtime Selection
|
|
8
|
+
|
|
9
|
+
The primitive supports three runtime modes:
|
|
10
|
+
|
|
11
|
+
- `auto`: prefer cloud when Nango or relay-cloud credentials are present,
|
|
12
|
+
otherwise use the local `gh` CLI when available.
|
|
13
|
+
- `local`: use `gh api` from the current machine.
|
|
14
|
+
- `cloud`: use Nango first, then relay-cloud proxy when configured.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { GitHubClient } from '@relayflows/github-primitive';
|
|
18
|
+
|
|
19
|
+
const github = await GitHubClient.create({
|
|
20
|
+
runtime: 'auto',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const repo = await github.getRepo('AgentWorkforce', 'relay');
|
|
24
|
+
console.log(repo.defaultBranch);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Actions
|
|
28
|
+
|
|
29
|
+
The client and workflow step support:
|
|
30
|
+
|
|
31
|
+
- Repositories: `listRepos`, `getRepo`
|
|
32
|
+
- Issues: `listIssues`, `createIssue`, `updateIssue`, `closeIssue`
|
|
33
|
+
- Pull requests: `listPRs`, `getPR`, `createPR`, `updatePR`, `mergePR`
|
|
34
|
+
- Files: `listFiles`, `readFile`, `createFile`, `updateFile`, `deleteFile`
|
|
35
|
+
- Branches and commits: `listBranches`, `createBranch`, `listCommits`, `createCommit`
|
|
36
|
+
- Identity: `getUser`, `listOrganizations`
|
|
37
|
+
|
|
38
|
+
## End-to-end PR workflow
|
|
39
|
+
|
|
40
|
+
`examples/end-to-end-pr-workflow.ts` walks the full PR lifecycle against
|
|
41
|
+
a single runtime:
|
|
42
|
+
|
|
43
|
+
1. `getRepo` — inspect + log the selected runtime.
|
|
44
|
+
2. `createBranch` off the base branch.
|
|
45
|
+
3. `createFile` — write a marker file on the new branch.
|
|
46
|
+
4. `createPR` — the core integration step cloud workflows migrate to.
|
|
47
|
+
5. `getPR` — round-trip verify.
|
|
48
|
+
6. `updatePR` — edit the PR body without code changes.
|
|
49
|
+
7. `listPRs` — confirm indexability.
|
|
50
|
+
8. (commented) `mergePR` — off by default so the example never merges
|
|
51
|
+
anything real.
|
|
52
|
+
|
|
53
|
+
Run against a scratch repo:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
GITHUB_REPO=AgentWorkforce/scratch npx tsx \
|
|
57
|
+
packages/github-primitive/examples/end-to-end-pr-workflow.ts
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Runtime selection is automatic:
|
|
61
|
+
|
|
62
|
+
| Path | Triggered when |
|
|
63
|
+
| ----------- | ----------------------------------------------------------------------------------------------------- |
|
|
64
|
+
| Local `gh` | `gh auth status` succeeds and no cloud creds are set |
|
|
65
|
+
| Nango | `NANGO_SECRET_KEY` + `NANGO_GITHUB_CONNECTION_ID` + `NANGO_GITHUB_PROVIDER_CONFIG_KEY` present |
|
|
66
|
+
| relay-cloud | `RELAY_CLOUD_API_URL` + `RELAY_CLOUD_API_TOKEN` + `WORKSPACE_ID` present (fallback when Nango absent) |
|
|
67
|
+
|
|
68
|
+
## Multi-tenant routing
|
|
69
|
+
|
|
70
|
+
In cloud, every workspace has its own GitHub App install — one Nango
|
|
71
|
+
connection per tenant. `createGitHubStep` accepts a per-step `config`
|
|
72
|
+
field so a single workflow can route different actions through
|
|
73
|
+
different connections. One workflow, many tenants.
|
|
74
|
+
|
|
75
|
+
`examples/multi-tenant-pr-workflow.ts` demonstrates this: it opens PRs
|
|
76
|
+
in `AgentWorkforce/cloud` (via the AgentWorkforce app) AND in an
|
|
77
|
+
MSD-owned repo (via MSD's app), from the same workflow definition, by
|
|
78
|
+
varying the `config:` field on each step.
|
|
79
|
+
|
|
80
|
+
### Cloud adoption: the resolver helper
|
|
81
|
+
|
|
82
|
+
The primitive stays tenant-unaware — it takes a `GitHubRuntimeConfig`
|
|
83
|
+
and does what it's told. The tenant lookup lives in cloud, in a small
|
|
84
|
+
helper:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
// cloud/packages/web/lib/github/connection-resolver.ts
|
|
88
|
+
import type { GitHubRuntimeConfig } from '@relayflows/github-primitive';
|
|
89
|
+
|
|
90
|
+
export async function githubConfigForRepo(opts: {
|
|
91
|
+
repo: string; // "owner/repo"
|
|
92
|
+
workspaceId?: string; // optional — cloud-owned repos default
|
|
93
|
+
}): Promise<GitHubRuntimeConfig> {
|
|
94
|
+
const connection = await resolveWorkspaceIntegration(opts.workspaceId, 'github', opts.repo);
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
runtime: 'auto',
|
|
98
|
+
nango: {
|
|
99
|
+
connectionId: connection.connectionId,
|
|
100
|
+
providerConfigKey: connection.providerConfigKey, // 'github-agentworkforce' | 'github-msd' | 'github-nightcto' | ...
|
|
101
|
+
secretKey: process.env.NANGO_SECRET_KEY,
|
|
102
|
+
},
|
|
103
|
+
relayCloud: {
|
|
104
|
+
apiUrl: process.env.CLOUD_API_URL,
|
|
105
|
+
accessToken: process.env.CLOUD_API_TOKEN,
|
|
106
|
+
workspaceId: opts.workspaceId,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Workflow authors in cloud then write:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
createGitHubStep({
|
|
116
|
+
name: 'open-pr',
|
|
117
|
+
action: 'createPR',
|
|
118
|
+
repo: 'AgentWorkforce/cloud',
|
|
119
|
+
params: { title, head, base, body },
|
|
120
|
+
config: await githubConfigForRepo({
|
|
121
|
+
repo: 'AgentWorkforce/cloud',
|
|
122
|
+
workspaceId: process.env.RELAY_WORKSPACE_ID,
|
|
123
|
+
}),
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
One resolver, one call-site shape. Adding a new GitHub App install is a
|
|
128
|
+
`workspace_integrations` row + (optionally) a `NANGO_*` secret — no
|
|
129
|
+
code change in the workflows that create PRs.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BranchInfo, CreateBranchParams } from '../types.js';
|
|
2
|
+
import { type GitHubActionAdapter } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* List branches for a repository.
|
|
5
|
+
*/
|
|
6
|
+
export declare function listBranches(adapter: GitHubActionAdapter, owner: string, repo: string): Promise<BranchInfo[]>;
|
|
7
|
+
/**
|
|
8
|
+
* Create a branch from another branch, or from the repository default branch.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createBranch(adapter: GitHubActionAdapter, params: CreateBranchParams): Promise<void>;
|
|
11
|
+
export declare function getBranch(adapter: GitHubActionAdapter, owner: string, repo: string, branch: string): Promise<BranchInfo>;
|
|
12
|
+
export declare function mapBranch(value: unknown): BranchInfo;
|
|
13
|
+
//# sourceMappingURL=branches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branches.d.ts","sourceRoot":"","sources":["../../src/actions/branches.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAiB,MAAM,aAAa,CAAC;AACjF,OAAO,EAWL,KAAK,mBAAmB,EACzB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,UAAU,EAAE,CAAC,CAMvB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB1G;AAED,wBAAsB,SAAS,CAC7B,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC,CAGrB;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAYpD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { asArray, asRecord, assertNonEmptyString, assertOwnerRepo, booleanValue, branchEndpoint, numberValue, repoEndpoint, stringValue, withActionError, } from './utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* List branches for a repository.
|
|
4
|
+
*/
|
|
5
|
+
export async function listBranches(adapter, owner, repo) {
|
|
6
|
+
return withActionError(`list GitHub branches for ${owner}/${repo}`, async () => {
|
|
7
|
+
assertOwnerRepo(owner, repo);
|
|
8
|
+
const response = await adapter.request('GET', repoEndpoint(owner, repo, '/branches'));
|
|
9
|
+
return asArray(response, 'branches').map(mapBranch);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create a branch from another branch, or from the repository default branch.
|
|
14
|
+
*/
|
|
15
|
+
export async function createBranch(adapter, params) {
|
|
16
|
+
const { owner, repo } = params;
|
|
17
|
+
return withActionError(`create GitHub branch ${params.branch} in ${owner}/${repo}`, async () => {
|
|
18
|
+
assertOwnerRepo(owner, repo);
|
|
19
|
+
const branch = assertNonEmptyString(params.branch, 'branch');
|
|
20
|
+
const sourceBranch = params.fromBranch ?? (await getDefaultBranch(adapter, params));
|
|
21
|
+
const source = await getBranch(adapter, owner, repo, sourceBranch);
|
|
22
|
+
const sha = assertNonEmptyString(source.commit.sha, 'source branch sha');
|
|
23
|
+
await adapter.request('POST', repoEndpoint(owner, repo, '/git/refs'), {
|
|
24
|
+
body: {
|
|
25
|
+
ref: `refs/heads/${branch}`,
|
|
26
|
+
sha,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export async function getBranch(adapter, owner, repo, branch) {
|
|
32
|
+
const response = await adapter.request('GET', branchEndpoint(owner, repo, branch));
|
|
33
|
+
return mapBranch(response);
|
|
34
|
+
}
|
|
35
|
+
export function mapBranch(value) {
|
|
36
|
+
const branch = asRecord(value, 'branch');
|
|
37
|
+
const commit = asRecord(branch.commit, 'branch commit');
|
|
38
|
+
return {
|
|
39
|
+
name: stringValue(branch.name),
|
|
40
|
+
commit: {
|
|
41
|
+
sha: stringValue(commit.sha),
|
|
42
|
+
url: stringValue(commit.url),
|
|
43
|
+
},
|
|
44
|
+
protected: booleanValue(branch.protected),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async function getDefaultBranch(adapter, params) {
|
|
48
|
+
const response = await adapter.request('GET', repoEndpoint(params.owner, params.repo));
|
|
49
|
+
const repository = asRecord(response, 'repository');
|
|
50
|
+
const branch = stringValue(repository.default_branch);
|
|
51
|
+
if (!branch) {
|
|
52
|
+
const id = numberValue(repository.id);
|
|
53
|
+
throw new Error(id
|
|
54
|
+
? `Repository ${params.owner}/${params.repo} did not include a default branch.`
|
|
55
|
+
: `Repository ${params.owner}/${params.repo} was not a valid repository response.`);
|
|
56
|
+
}
|
|
57
|
+
return branch;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=branches.js.map
|
|
@@ -0,0 +1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,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAChG,MAAM,UAAU,GAAG,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IAEtD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,EAAE,GAAG,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,EAAE;YACA,CAAC,CAAC,cAAc,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,oCAAoC;YAC/E,CAAC,CAAC,cAAc,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,uCAAuC,CACrF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CommitInfo, CreateCommitParams, ListCommitsParams } from '../types.js';
|
|
2
|
+
import { type GitHubActionAdapter } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* List commits for a repository.
|
|
5
|
+
*/
|
|
6
|
+
export declare function listCommits(adapter: GitHubActionAdapter, params: ListCommitsParams): Promise<CommitInfo[]>;
|
|
7
|
+
/**
|
|
8
|
+
* Create a Git commit object.
|
|
9
|
+
*
|
|
10
|
+
* This creates the commit object only. Updating a branch ref is intentionally a
|
|
11
|
+
* separate operation so callers can decide when to move refs.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createCommit(adapter: GitHubActionAdapter, params: CreateCommitParams): Promise<CommitInfo>;
|
|
14
|
+
export declare function mapCommit(value: unknown): CommitInfo;
|
|
15
|
+
//# sourceMappingURL=commits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commits.d.ts","sourceRoot":"","sources":["../../src/actions/commits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAGlB,iBAAiB,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAYL,KAAK,mBAAmB,EACzB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,UAAU,EAAE,CAAC,CAoBvB;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,UAAU,CAAC,CAwBrB;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAcpD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { asArray, asRecord, assertNonEmptyString, assertOwnerRepo, normalizePerPage, optionalRecord, optionalString, removeUndefinedValues, repoEndpoint, stringValue, withActionError, } from './utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* List commits for a repository.
|
|
4
|
+
*/
|
|
5
|
+
export async function listCommits(adapter, params) {
|
|
6
|
+
const { owner, repo } = params;
|
|
7
|
+
return withActionError(`list GitHub commits for ${owner}/${repo}`, async () => {
|
|
8
|
+
assertOwnerRepo(owner, repo);
|
|
9
|
+
const query = {
|
|
10
|
+
sha: params.sha,
|
|
11
|
+
path: params.path,
|
|
12
|
+
author: params.author,
|
|
13
|
+
since: params.since,
|
|
14
|
+
until: params.until,
|
|
15
|
+
per_page: normalizePerPage(params.perPage),
|
|
16
|
+
};
|
|
17
|
+
const response = await adapter.request('GET', repoEndpoint(owner, repo, '/commits'), {
|
|
18
|
+
query,
|
|
19
|
+
});
|
|
20
|
+
return asArray(response, 'commits').map(mapCommit);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a Git commit object.
|
|
25
|
+
*
|
|
26
|
+
* This creates the commit object only. Updating a branch ref is intentionally a
|
|
27
|
+
* separate operation so callers can decide when to move refs.
|
|
28
|
+
*/
|
|
29
|
+
export async function createCommit(adapter, params) {
|
|
30
|
+
const { owner, repo } = params;
|
|
31
|
+
return withActionError(`create GitHub commit in ${owner}/${repo}`, async () => {
|
|
32
|
+
assertOwnerRepo(owner, repo);
|
|
33
|
+
const message = assertNonEmptyString(params.message, 'commit message');
|
|
34
|
+
const tree = assertNonEmptyString(params.tree, 'commit tree');
|
|
35
|
+
if (!Array.isArray(params.parents)) {
|
|
36
|
+
throw new Error('GitHub commit parents must be an array of parent SHAs.');
|
|
37
|
+
}
|
|
38
|
+
const response = await adapter.request('POST', repoEndpoint(owner, repo, '/git/commits'), {
|
|
39
|
+
body: removeUndefinedValues({
|
|
40
|
+
message,
|
|
41
|
+
tree,
|
|
42
|
+
parents: params.parents.map((parent) => assertNonEmptyString(parent, 'parent sha')),
|
|
43
|
+
author: params.author,
|
|
44
|
+
committer: params.committer,
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
return mapCommit(response);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function mapCommit(value) {
|
|
51
|
+
const topLevel = asRecord(value, 'commit');
|
|
52
|
+
const nestedCommit = optionalRecord(topLevel.commit);
|
|
53
|
+
const author = optionalRecord(nestedCommit?.author ?? topLevel.author);
|
|
54
|
+
const committer = optionalRecord(nestedCommit?.committer ?? topLevel.committer);
|
|
55
|
+
return {
|
|
56
|
+
sha: stringValue(topLevel.sha),
|
|
57
|
+
url: optionalString(topLevel.url),
|
|
58
|
+
htmlUrl: optionalString(topLevel.html_url),
|
|
59
|
+
message: optionalString(nestedCommit?.message ?? topLevel.message),
|
|
60
|
+
author: author ? mapCommitAuthor(author) : undefined,
|
|
61
|
+
committer: committer ? mapCommitAuthor(committer) : undefined,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function mapCommitAuthor(value) {
|
|
65
|
+
return {
|
|
66
|
+
name: stringValue(value.name),
|
|
67
|
+
email: stringValue(value.email),
|
|
68
|
+
date: optionalString(value.date),
|
|
69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,MAAM,CAAC,CAAC;IACvE,MAAM,SAAS,GAAG,cAAc,CAAC,YAAY,EAAE,SAAS,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC;IAEhF,OAAO;QACL,GAAG,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC;QAC9B,GAAG,EAAE,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC;QACjC,OAAO,EAAE,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC1C,OAAO,EAAE,cAAc,CAAC,YAAY,EAAE,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC;QAClE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;QACpD,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;KAC9D,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,KAA8B;IACrD,OAAO;QACL,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC;QAC7B,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC;QAC/B,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CreateFileParams, DeleteFileParams, GitHubFile, ListFilesParams, UpdateFileParams } from '../types.js';
|
|
2
|
+
import { type GitHubActionAdapter } from './utils.js';
|
|
3
|
+
export type ListFileOptions = Omit<ListFilesParams, 'owner' | 'repo' | 'path'>;
|
|
4
|
+
export type CreateFileOptions = Omit<CreateFileParams, 'owner' | 'repo' | 'path' | 'content' | 'message'>;
|
|
5
|
+
export type UpdateFileOptions = Omit<UpdateFileParams, 'owner' | 'repo' | 'path' | 'content' | 'message' | 'sha'>;
|
|
6
|
+
export type DeleteFileOptions = Omit<DeleteFileParams, 'owner' | 'repo' | 'path' | 'sha' | 'message'>;
|
|
7
|
+
/**
|
|
8
|
+
* List files or directories at a repository path.
|
|
9
|
+
*
|
|
10
|
+
* Directory responses are returned as a file list. If the path points at a
|
|
11
|
+
* single file, the file is returned as a one-item list.
|
|
12
|
+
*/
|
|
13
|
+
export declare function listFiles(adapter: GitHubActionAdapter, owner: string, repo: string, path?: string, options?: ListFileOptions): Promise<GitHubFile[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Read a repository file and return decoded UTF-8 content.
|
|
16
|
+
*
|
|
17
|
+
* The GitHub contents API returns base64 encoded file data; this action decodes
|
|
18
|
+
* the payload before returning it to callers.
|
|
19
|
+
*/
|
|
20
|
+
export declare function readFile(adapter: GitHubActionAdapter, owner: string, repo: string, path: string, ref?: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Create a file in a repository.
|
|
23
|
+
*
|
|
24
|
+
* Content is encoded as base64 and committed with the supplied message. The
|
|
25
|
+
* action resolves when GitHub accepts the create request.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createFile(adapter: GitHubActionAdapter, owner: string, repo: string, path: string, content: string, message: string, options?: CreateFileOptions): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Update an existing repository file.
|
|
30
|
+
*
|
|
31
|
+
* The file SHA is required by the GitHub contents API to avoid overwriting an
|
|
32
|
+
* unexpected version.
|
|
33
|
+
*/
|
|
34
|
+
export declare function updateFile(adapter: GitHubActionAdapter, owner: string, repo: string, path: string, content: string, message: string, sha: string, options?: UpdateFileOptions): Promise<GitHubFile>;
|
|
35
|
+
/**
|
|
36
|
+
* Delete a repository file with a commit message.
|
|
37
|
+
*/
|
|
38
|
+
export declare function deleteFile(adapter: GitHubActionAdapter, owner: string, repo: string, path: string, sha: string, message: string, options?: DeleteFileOptions): Promise<void>;
|
|
39
|
+
export declare function mapFile(value: unknown): GitHubFile;
|
|
40
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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E,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAef;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,UAAU,CAAC,CAoBrB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAkBlD"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { asArray, asRecord, assertNonEmptyString, assertOwnerRepo, contentsEndpoint, normalizeRepoPath, numberValue, optionalString, removeUndefinedValues, stringValue, withActionError, } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* List files or directories at a repository path.
|
|
5
|
+
*
|
|
6
|
+
* Directory responses are returned as a file list. If the path points at a
|
|
7
|
+
* single file, the file is returned as a one-item list.
|
|
8
|
+
*/
|
|
9
|
+
export async function listFiles(adapter, owner, repo, path = '', options = {}) {
|
|
10
|
+
return withActionError(`list GitHub files at ${owner}/${repo}/${path}`, async () => {
|
|
11
|
+
assertOwnerRepo(owner, repo);
|
|
12
|
+
const response = await adapter.request('GET', contentsEndpoint(owner, repo, path), {
|
|
13
|
+
query: {
|
|
14
|
+
ref: options.ref,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
return Array.isArray(response)
|
|
18
|
+
? asArray(response, 'repository contents').map(mapFile)
|
|
19
|
+
: [mapFile(response)];
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Read a repository file and return decoded UTF-8 content.
|
|
24
|
+
*
|
|
25
|
+
* The GitHub contents API returns base64 encoded file data; this action decodes
|
|
26
|
+
* the payload before returning it to callers.
|
|
27
|
+
*/
|
|
28
|
+
export async function readFile(adapter, owner, repo, path, ref) {
|
|
29
|
+
return withActionError(`read GitHub file ${owner}/${repo}/${path}`, async () => {
|
|
30
|
+
assertOwnerRepo(owner, repo);
|
|
31
|
+
assertNonEmptyString(normalizeRepoPath(path), 'file path');
|
|
32
|
+
const response = await adapter.request('GET', contentsEndpoint(owner, repo, path), {
|
|
33
|
+
query: {
|
|
34
|
+
ref,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const file = mapFile(response);
|
|
38
|
+
if (file.type !== 'file') {
|
|
39
|
+
throw new Error(`GitHub path "${path}" is not a file.`);
|
|
40
|
+
}
|
|
41
|
+
if (!file.content) {
|
|
42
|
+
throw new Error(`GitHub file "${path}" did not include content in the API response.`);
|
|
43
|
+
}
|
|
44
|
+
if (file.encoding && file.encoding !== 'base64') {
|
|
45
|
+
throw new Error(`GitHub file "${path}" used unsupported encoding "${file.encoding}".`);
|
|
46
|
+
}
|
|
47
|
+
return Buffer.from(file.content.replace(/\s/g, ''), 'base64').toString('utf8');
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a file in a repository.
|
|
52
|
+
*
|
|
53
|
+
* Content is encoded as base64 and committed with the supplied message. The
|
|
54
|
+
* action resolves when GitHub accepts the create request.
|
|
55
|
+
*/
|
|
56
|
+
export async function createFile(adapter, owner, repo, path, content, message, options = {}) {
|
|
57
|
+
return withActionError(`create GitHub file ${owner}/${repo}/${path}`, async () => {
|
|
58
|
+
assertOwnerRepo(owner, repo);
|
|
59
|
+
const normalizedPath = assertNonEmptyString(normalizeRepoPath(path), 'file path');
|
|
60
|
+
const commitMessage = assertNonEmptyString(message, 'commit message');
|
|
61
|
+
await adapter.request('PUT', contentsEndpoint(owner, repo, normalizedPath), {
|
|
62
|
+
body: removeUndefinedValues({
|
|
63
|
+
message: commitMessage,
|
|
64
|
+
content: Buffer.from(content, 'utf8').toString('base64'),
|
|
65
|
+
branch: options.branch,
|
|
66
|
+
author: options.author,
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Update an existing repository file.
|
|
73
|
+
*
|
|
74
|
+
* The file SHA is required by the GitHub contents API to avoid overwriting an
|
|
75
|
+
* unexpected version.
|
|
76
|
+
*/
|
|
77
|
+
export async function updateFile(adapter, owner, repo, path, content, message, sha, options = {}) {
|
|
78
|
+
return withActionError(`update GitHub file ${owner}/${repo}/${path}`, async () => {
|
|
79
|
+
assertOwnerRepo(owner, repo);
|
|
80
|
+
const normalizedPath = assertNonEmptyString(normalizeRepoPath(path), 'file path');
|
|
81
|
+
const commitMessage = assertNonEmptyString(message, 'commit message');
|
|
82
|
+
const fileSha = assertNonEmptyString(sha, 'file sha');
|
|
83
|
+
const response = await adapter.request('PUT', contentsEndpoint(owner, repo, normalizedPath), {
|
|
84
|
+
body: removeUndefinedValues({
|
|
85
|
+
message: commitMessage,
|
|
86
|
+
content: Buffer.from(content, 'utf8').toString('base64'),
|
|
87
|
+
sha: fileSha,
|
|
88
|
+
branch: options.branch,
|
|
89
|
+
author: options.author,
|
|
90
|
+
}),
|
|
91
|
+
});
|
|
92
|
+
const contentRecord = asRecord(response, 'update file response').content;
|
|
93
|
+
return mapFile(contentRecord);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Delete a repository file with a commit message.
|
|
98
|
+
*/
|
|
99
|
+
export async function deleteFile(adapter, owner, repo, path, sha, message, options = {}) {
|
|
100
|
+
return withActionError(`delete GitHub file ${owner}/${repo}/${path}`, async () => {
|
|
101
|
+
assertOwnerRepo(owner, repo);
|
|
102
|
+
const normalizedPath = assertNonEmptyString(normalizeRepoPath(path), 'file path');
|
|
103
|
+
const fileSha = assertNonEmptyString(sha, 'file sha');
|
|
104
|
+
const commitMessage = assertNonEmptyString(message, 'commit message');
|
|
105
|
+
await adapter.request('DELETE', contentsEndpoint(owner, repo, normalizedPath), {
|
|
106
|
+
body: removeUndefinedValues({
|
|
107
|
+
message: commitMessage,
|
|
108
|
+
sha: fileSha,
|
|
109
|
+
branch: options.branch,
|
|
110
|
+
author: options.author,
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
export function mapFile(value) {
|
|
116
|
+
const file = asRecord(value, 'repository content');
|
|
117
|
+
const type = stringValue(file.type) === 'dir' ? 'dir' : 'file';
|
|
118
|
+
return {
|
|
119
|
+
name: stringValue(file.name),
|
|
120
|
+
path: stringValue(file.path),
|
|
121
|
+
sha: stringValue(file.sha),
|
|
122
|
+
size: numberValue(file.size),
|
|
123
|
+
url: stringValue(file.url),
|
|
124
|
+
htmlUrl: stringValue(file.html_url),
|
|
125
|
+
gitUrl: stringValue(file.git_url),
|
|
126
|
+
downloadUrl: optionalString(file.download_url),
|
|
127
|
+
type,
|
|
128
|
+
content: optionalString(file.content),
|
|
129
|
+
encoding: optionalString(file.encoding),
|
|
130
|
+
target: optionalString(file.target),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/actions/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC,OAAO,EACL,OAAO,EACP,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,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IAAI,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;IAE/D,OAAO;QACL,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5B,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5B,GAAG,EAAE,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC;QAC1B,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5B,GAAG,EAAE,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC;QAC1B,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC;QACnC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC;QACjC,WAAW,EAAE,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC;QAC9C,IAAI;QACJ,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;QACrC,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC;QACvC,MAAM,EAAE,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC;KACpC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CreateIssueParams, Issue, ListIssuesParams, UpdateIssueParams } from '../types.js';
|
|
2
|
+
import { type GitHubActionAdapter } from './utils.js';
|
|
3
|
+
export type ListIssueOptions = Omit<ListIssuesParams, 'owner' | 'repo'>;
|
|
4
|
+
export type CreateIssueOptions = Omit<CreateIssueParams, 'owner' | 'repo' | 'title' | 'body'>;
|
|
5
|
+
export type IssueUpdates = Omit<UpdateIssueParams, 'owner' | 'repo' | 'issueNumber'>;
|
|
6
|
+
/**
|
|
7
|
+
* List repository issues.
|
|
8
|
+
*
|
|
9
|
+
* Pull requests are excluded from the repository issues endpoint response so
|
|
10
|
+
* callers receive only true issues. Local and cloud runtimes are handled by the
|
|
11
|
+
* provided adapter.
|
|
12
|
+
*/
|
|
13
|
+
export declare function listIssues(adapter: GitHubActionAdapter, owner: string, repo: string, options?: ListIssueOptions): Promise<Issue[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Create an issue in a repository.
|
|
16
|
+
*
|
|
17
|
+
* The request body is sent through the adapter request layer, allowing the
|
|
18
|
+
* local `gh api` runtime and the cloud proxy runtime to share the same action.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createIssue(adapter: GitHubActionAdapter, owner: string, repo: string, title: string, body?: string, options?: CreateIssueOptions): Promise<Issue>;
|
|
21
|
+
/**
|
|
22
|
+
* Update an existing issue.
|
|
23
|
+
*
|
|
24
|
+
* At least one update field must be supplied. Supported updates include title,
|
|
25
|
+
* body, state, assignee, and labels.
|
|
26
|
+
*/
|
|
27
|
+
export declare function updateIssue(adapter: GitHubActionAdapter, owner: string, repo: string, number: number, updates: IssueUpdates): Promise<Issue>;
|
|
28
|
+
export declare function mapIssue(value: unknown): Issue;
|
|
29
|
+
//# sourceMappingURL=issues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issues.d.ts","sourceRoot":"","sources":["../../src/actions/issues.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACjG,OAAO,EAoBL,KAAK,mBAAmB,EACzB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;AACxE,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,CAAC;AAC9F,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,EAAE,OAAO,GAAG,MAAM,GAAG,aAAa,CAAC,CAAC;AAErF;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,O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