@agent-relay/github-primitive 4.0.9 → 4.0.40
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/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 +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -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/dist/workflow-step.d.ts +79 -0
- package/dist/workflow-step.d.ts.map +1 -0
- package/dist/workflow-step.js +459 -0
- package/dist/workflow-step.js.map +1 -0
- package/package.json +2 -2
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { BranchInfo, CommitInfo, CreateBranchParams, CreateCommitParams, CreateFileParams, CreateIssueParams, CreatePRParams, DeleteFileParams, GitHubFile, GitHubAction, GitHubActionName, GitHubActionOutputMap, GitHubActionParamsMap, GitHubActionResult, GitHubApiRequestMethod, GitHubApiRequestOptions, GitHubClientInterface, GitHubRuntime, GitHubRuntimeConfig, GitHubRuntimeDetectionResult, GitHubUserSummary, Issue, ListCommitsParams, ListFilesParams, ListIssuesParams, ListOrganizationsParams, ListPRsParams, ListReposParams, MergePRParams, OrganizationInfo, PR, Repo, UpdateFileParams, UpdateIssueParams, UpdatePRParams } from './types.js';
|
|
2
|
+
export type GitHubListIssueOptions = Omit<ListIssuesParams, 'owner' | 'repo'>;
|
|
3
|
+
export type GitHubCreateIssueOptions = Omit<CreateIssueParams, 'owner' | 'repo' | 'title' | 'body'>;
|
|
4
|
+
export type GitHubIssueUpdates = Omit<UpdateIssueParams, 'owner' | 'repo' | 'issueNumber'>;
|
|
5
|
+
export type GitHubListPROptions = Omit<ListPRsParams, 'owner' | 'repo'>;
|
|
6
|
+
export type GitHubCreatePROptions = Omit<CreatePRParams, 'owner' | 'repo' | 'title' | 'body' | 'base' | 'head'>;
|
|
7
|
+
export type GitHubListFileOptions = Omit<ListFilesParams, 'owner' | 'repo' | 'path'>;
|
|
8
|
+
export type GitHubCreateFileOptions = Omit<CreateFileParams, 'owner' | 'repo' | 'path' | 'content' | 'message'>;
|
|
9
|
+
export type GitHubUpdatePROptions = Omit<UpdatePRParams, 'owner' | 'repo' | 'pullNumber'>;
|
|
10
|
+
export type GitHubMergePROptions = Omit<MergePRParams, 'owner' | 'repo' | 'pullNumber'>;
|
|
11
|
+
export type GitHubUpdateFileOptions = Omit<UpdateFileParams, 'owner' | 'repo' | 'path' | 'content' | 'message' | 'sha'>;
|
|
12
|
+
export type GitHubDeleteFileOptions = Omit<DeleteFileParams, 'owner' | 'repo' | 'path' | 'sha' | 'message'>;
|
|
13
|
+
export type GitHubCreateBranchOptions = Omit<CreateBranchParams, 'owner' | 'repo' | 'branch'>;
|
|
14
|
+
export type GitHubListCommitOptions = Omit<ListCommitsParams, 'owner' | 'repo'>;
|
|
15
|
+
export type GitHubCreateCommitOptions = Omit<CreateCommitParams, 'owner' | 'repo' | 'message' | 'tree' | 'parents'>;
|
|
16
|
+
export type GitHubListOrganizationOptions = Omit<ListOrganizationsParams, 'username'>;
|
|
17
|
+
/**
|
|
18
|
+
* High-level GitHub primitive client.
|
|
19
|
+
*
|
|
20
|
+
* The client lazily auto-detects the runtime using the adapter factory and then
|
|
21
|
+
* delegates typed action methods to the selected local `gh` or cloud runtime.
|
|
22
|
+
*/
|
|
23
|
+
export declare class GitHubClient {
|
|
24
|
+
private readonly adapterPromise;
|
|
25
|
+
constructor(config?: GitHubRuntimeConfig);
|
|
26
|
+
/**
|
|
27
|
+
* Create a GitHub client and eagerly resolve runtime detection.
|
|
28
|
+
*/
|
|
29
|
+
static create(config?: GitHubRuntimeConfig): Promise<GitHubClient>;
|
|
30
|
+
/**
|
|
31
|
+
* Inspect runtime availability without creating a client.
|
|
32
|
+
*/
|
|
33
|
+
static detect(config?: GitHubRuntimeConfig): Promise<GitHubRuntimeDetectionResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Detect the runtime that would be selected for the supplied configuration.
|
|
36
|
+
*/
|
|
37
|
+
static detectRuntime(config?: GitHubRuntimeConfig): Promise<GitHubRuntime>;
|
|
38
|
+
/**
|
|
39
|
+
* Return the selected low-level adapter.
|
|
40
|
+
*/
|
|
41
|
+
getAdapter(): Promise<GitHubClientInterface>;
|
|
42
|
+
/**
|
|
43
|
+
* Return the runtime selected by auto-detection or explicit configuration.
|
|
44
|
+
*/
|
|
45
|
+
getRuntime(): Promise<GitHubRuntime>;
|
|
46
|
+
/**
|
|
47
|
+
* Check whether the selected runtime is authenticated.
|
|
48
|
+
*/
|
|
49
|
+
isAuthenticated(): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Fetch the authenticated GitHub user for the selected runtime.
|
|
52
|
+
*/
|
|
53
|
+
getCurrentUser(): Promise<GitHubUserSummary>;
|
|
54
|
+
/**
|
|
55
|
+
* Execute a raw GitHub API request through the selected adapter.
|
|
56
|
+
*/
|
|
57
|
+
request<TResponse = unknown>(method: GitHubApiRequestMethod, path: string, options?: GitHubApiRequestOptions): Promise<TResponse>;
|
|
58
|
+
executeAction<Name extends GitHubAction>(action: Name, params: GitHubActionParamsMap[Name]): Promise<GitHubActionResult<GitHubActionOutputMap[Name]>>;
|
|
59
|
+
executeAction<TOutput = unknown>(action: GitHubAction | GitHubActionName, params?: unknown): Promise<GitHubActionResult<TOutput>>;
|
|
60
|
+
/**
|
|
61
|
+
* List repositories visible to the authenticated GitHub identity.
|
|
62
|
+
*/
|
|
63
|
+
listRepos(options?: ListReposParams): Promise<Repo[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Fetch a repository by owner and name.
|
|
66
|
+
*/
|
|
67
|
+
getRepo(owner: string, repo: string): Promise<Repo>;
|
|
68
|
+
/**
|
|
69
|
+
* List issues for a repository.
|
|
70
|
+
*/
|
|
71
|
+
listIssues(owner: string, repo: string, options?: GitHubListIssueOptions): Promise<Issue[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Create an issue in a repository.
|
|
74
|
+
*/
|
|
75
|
+
createIssue(owner: string, repo: string, title: string, body?: string, options?: GitHubCreateIssueOptions): Promise<Issue>;
|
|
76
|
+
/**
|
|
77
|
+
* Update an existing issue by issue number.
|
|
78
|
+
*/
|
|
79
|
+
updateIssue(owner: string, repo: string, number: number, updates: GitHubIssueUpdates): Promise<Issue>;
|
|
80
|
+
/**
|
|
81
|
+
* Close an issue by issue number.
|
|
82
|
+
*/
|
|
83
|
+
closeIssue(owner: string, repo: string, number: number): Promise<Issue>;
|
|
84
|
+
/**
|
|
85
|
+
* List pull requests for a repository.
|
|
86
|
+
*/
|
|
87
|
+
listPRs(owner: string, repo: string, options?: GitHubListPROptions): Promise<PR[]>;
|
|
88
|
+
/**
|
|
89
|
+
* Fetch a pull request by pull request number.
|
|
90
|
+
*/
|
|
91
|
+
getPR(owner: string, repo: string, number: number): Promise<PR>;
|
|
92
|
+
/**
|
|
93
|
+
* Create a pull request.
|
|
94
|
+
*/
|
|
95
|
+
createPR(owner: string, repo: string, title: string, body: string | undefined, base: string, head: string, options?: GitHubCreatePROptions): Promise<PR>;
|
|
96
|
+
/**
|
|
97
|
+
* Update an existing pull request by pull request number.
|
|
98
|
+
*/
|
|
99
|
+
updatePR(owner: string, repo: string, number: number, updates: GitHubUpdatePROptions): Promise<PR>;
|
|
100
|
+
/**
|
|
101
|
+
* Merge a pull request and return the refreshed pull request.
|
|
102
|
+
*/
|
|
103
|
+
mergePR(owner: string, repo: string, number: number, options?: GitHubMergePROptions): Promise<PR>;
|
|
104
|
+
/**
|
|
105
|
+
* List files or directories at a repository path.
|
|
106
|
+
*/
|
|
107
|
+
listFiles(owner: string, repo: string, path?: string, options?: GitHubListFileOptions): Promise<GitHubFile[]>;
|
|
108
|
+
/**
|
|
109
|
+
* Read a repository file and return decoded UTF-8 content.
|
|
110
|
+
*/
|
|
111
|
+
readFile(owner: string, repo: string, path: string, ref?: string): Promise<string>;
|
|
112
|
+
/**
|
|
113
|
+
* Create a repository file with a commit message.
|
|
114
|
+
*/
|
|
115
|
+
createFile(owner: string, repo: string, path: string, content: string, message: string, options?: GitHubCreateFileOptions): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Update a repository file with a commit message.
|
|
118
|
+
*/
|
|
119
|
+
updateFile(owner: string, repo: string, path: string, content: string, message: string, sha: string, options?: GitHubUpdateFileOptions): Promise<GitHubFile>;
|
|
120
|
+
/**
|
|
121
|
+
* Delete a repository file with a commit message.
|
|
122
|
+
*/
|
|
123
|
+
deleteFile(owner: string, repo: string, path: string, sha: string, message: string, options?: GitHubDeleteFileOptions): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* List repository branches.
|
|
126
|
+
*/
|
|
127
|
+
listBranches(owner: string, repo: string): Promise<BranchInfo[]>;
|
|
128
|
+
/**
|
|
129
|
+
* Create a branch from another branch, or from the repository default branch.
|
|
130
|
+
*/
|
|
131
|
+
createBranch(owner: string, repo: string, branch: string, options?: GitHubCreateBranchOptions): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* List repository commits.
|
|
134
|
+
*/
|
|
135
|
+
listCommits(owner: string, repo: string, options?: GitHubListCommitOptions): Promise<CommitInfo[]>;
|
|
136
|
+
/**
|
|
137
|
+
* Create a Git commit object.
|
|
138
|
+
*/
|
|
139
|
+
createCommit(owner: string, repo: string, message: string, tree: string, parents: string[], options?: GitHubCreateCommitOptions): Promise<CommitInfo>;
|
|
140
|
+
/**
|
|
141
|
+
* Fetch the authenticated user, or a public user by username.
|
|
142
|
+
*/
|
|
143
|
+
getUser(username?: string): Promise<GitHubUserSummary>;
|
|
144
|
+
/**
|
|
145
|
+
* List organizations for the authenticated user, or for a public user.
|
|
146
|
+
*/
|
|
147
|
+
listOrganizations(username?: string, options?: GitHubListOrganizationOptions): Promise<OrganizationInfo[]>;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=client.d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GAAE,uBAA4B,GACpC,OAAO,CAAC,UAAU,EAAE,CAAC;IAIxB;;OAEG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,UAAU,CAAC;IAWtB;;OAEG;IACG,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI5D;;OAEG;IACG,iBAAiB,CACrB,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,GAAE,6BAAkC,GAC1C,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAG/B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { GitHubAdapterFactory } from './adapter.js';
|
|
2
|
+
/**
|
|
3
|
+
* High-level GitHub primitive client.
|
|
4
|
+
*
|
|
5
|
+
* The client lazily auto-detects the runtime using the adapter factory and then
|
|
6
|
+
* delegates typed action methods to the selected local `gh` or cloud runtime.
|
|
7
|
+
*/
|
|
8
|
+
export class GitHubClient {
|
|
9
|
+
adapterPromise;
|
|
10
|
+
constructor(config = {}) {
|
|
11
|
+
this.adapterPromise = GitHubAdapterFactory.create(config);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a GitHub client and eagerly resolve runtime detection.
|
|
15
|
+
*/
|
|
16
|
+
static async create(config = {}) {
|
|
17
|
+
const client = new GitHubClient(config);
|
|
18
|
+
await client.getAdapter();
|
|
19
|
+
return client;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Inspect runtime availability without creating a client.
|
|
23
|
+
*/
|
|
24
|
+
static detect(config = {}) {
|
|
25
|
+
return GitHubAdapterFactory.detect(config);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Detect the runtime that would be selected for the supplied configuration.
|
|
29
|
+
*/
|
|
30
|
+
static detectRuntime(config = {}) {
|
|
31
|
+
return GitHubAdapterFactory.detectRuntime(config);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Return the selected low-level adapter.
|
|
35
|
+
*/
|
|
36
|
+
getAdapter() {
|
|
37
|
+
return this.adapterPromise;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Return the runtime selected by auto-detection or explicit configuration.
|
|
41
|
+
*/
|
|
42
|
+
async getRuntime() {
|
|
43
|
+
return (await this.getAdapter()).getRuntime();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check whether the selected runtime is authenticated.
|
|
47
|
+
*/
|
|
48
|
+
async isAuthenticated() {
|
|
49
|
+
return (await this.getAdapter()).isAuthenticated();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Fetch the authenticated GitHub user for the selected runtime.
|
|
53
|
+
*/
|
|
54
|
+
async getCurrentUser() {
|
|
55
|
+
return (await this.getAdapter()).getCurrentUser();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Execute a raw GitHub API request through the selected adapter.
|
|
59
|
+
*/
|
|
60
|
+
async request(method, path, options) {
|
|
61
|
+
return (await this.getAdapter()).request(method, path, options);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Execute any registered GitHub primitive action by action name.
|
|
65
|
+
*/
|
|
66
|
+
async executeAction(action, params) {
|
|
67
|
+
return (await this.getAdapter()).executeAction(action, params);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* List repositories visible to the authenticated GitHub identity.
|
|
71
|
+
*/
|
|
72
|
+
async listRepos(options = {}) {
|
|
73
|
+
return (await this.getAdapter()).listRepositories(options);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Fetch a repository by owner and name.
|
|
77
|
+
*/
|
|
78
|
+
async getRepo(owner, repo) {
|
|
79
|
+
return (await this.getAdapter()).getRepository({ owner, repo });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* List issues for a repository.
|
|
83
|
+
*/
|
|
84
|
+
async listIssues(owner, repo, options = {}) {
|
|
85
|
+
return (await this.getAdapter()).listIssues({ owner, repo, ...options });
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create an issue in a repository.
|
|
89
|
+
*/
|
|
90
|
+
async createIssue(owner, repo, title, body, options = {}) {
|
|
91
|
+
return (await this.getAdapter()).createIssue({ owner, repo, title, body, ...options });
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Update an existing issue by issue number.
|
|
95
|
+
*/
|
|
96
|
+
async updateIssue(owner, repo, number, updates) {
|
|
97
|
+
return (await this.getAdapter()).updateIssue({
|
|
98
|
+
owner,
|
|
99
|
+
repo,
|
|
100
|
+
issueNumber: number,
|
|
101
|
+
...updates,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Close an issue by issue number.
|
|
106
|
+
*/
|
|
107
|
+
async closeIssue(owner, repo, number) {
|
|
108
|
+
return (await this.getAdapter()).closeIssue({ owner, repo, issueNumber: number });
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* List pull requests for a repository.
|
|
112
|
+
*/
|
|
113
|
+
async listPRs(owner, repo, options = {}) {
|
|
114
|
+
return (await this.getAdapter()).listPullRequests({ owner, repo, ...options });
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Fetch a pull request by pull request number.
|
|
118
|
+
*/
|
|
119
|
+
async getPR(owner, repo, number) {
|
|
120
|
+
return (await this.getAdapter()).getPullRequest({ owner, repo, pullNumber: number });
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a pull request.
|
|
124
|
+
*/
|
|
125
|
+
async createPR(owner, repo, title, body, base, head, options = {}) {
|
|
126
|
+
return (await this.getAdapter()).createPullRequest({
|
|
127
|
+
owner,
|
|
128
|
+
repo,
|
|
129
|
+
title,
|
|
130
|
+
body,
|
|
131
|
+
base,
|
|
132
|
+
head,
|
|
133
|
+
...options,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Update an existing pull request by pull request number.
|
|
138
|
+
*/
|
|
139
|
+
async updatePR(owner, repo, number, updates) {
|
|
140
|
+
return (await this.getAdapter()).updatePullRequest({
|
|
141
|
+
owner,
|
|
142
|
+
repo,
|
|
143
|
+
pullNumber: number,
|
|
144
|
+
...updates,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Merge a pull request and return the refreshed pull request.
|
|
149
|
+
*/
|
|
150
|
+
async mergePR(owner, repo, number, options = {}) {
|
|
151
|
+
return (await this.getAdapter()).mergePullRequest({
|
|
152
|
+
owner,
|
|
153
|
+
repo,
|
|
154
|
+
pullNumber: number,
|
|
155
|
+
...options,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* List files or directories at a repository path.
|
|
160
|
+
*/
|
|
161
|
+
async listFiles(owner, repo, path = '', options = {}) {
|
|
162
|
+
return (await this.getAdapter()).listFiles({ owner, repo, path, ...options });
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Read a repository file and return decoded UTF-8 content.
|
|
166
|
+
*/
|
|
167
|
+
async readFile(owner, repo, path, ref) {
|
|
168
|
+
return (await this.getAdapter()).readFile({ owner, repo, path, ref });
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Create a repository file with a commit message.
|
|
172
|
+
*/
|
|
173
|
+
async createFile(owner, repo, path, content, message, options = {}) {
|
|
174
|
+
await (await this.getAdapter()).createFile({
|
|
175
|
+
owner,
|
|
176
|
+
repo,
|
|
177
|
+
path,
|
|
178
|
+
content,
|
|
179
|
+
message,
|
|
180
|
+
...options,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Update a repository file with a commit message.
|
|
185
|
+
*/
|
|
186
|
+
async updateFile(owner, repo, path, content, message, sha, options = {}) {
|
|
187
|
+
return (await this.getAdapter()).updateFile({
|
|
188
|
+
owner,
|
|
189
|
+
repo,
|
|
190
|
+
path,
|
|
191
|
+
content,
|
|
192
|
+
message,
|
|
193
|
+
sha,
|
|
194
|
+
...options,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Delete a repository file with a commit message.
|
|
199
|
+
*/
|
|
200
|
+
async deleteFile(owner, repo, path, sha, message, options = {}) {
|
|
201
|
+
await (await this.getAdapter()).deleteFile({
|
|
202
|
+
owner,
|
|
203
|
+
repo,
|
|
204
|
+
path,
|
|
205
|
+
sha,
|
|
206
|
+
message,
|
|
207
|
+
...options,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* List repository branches.
|
|
212
|
+
*/
|
|
213
|
+
async listBranches(owner, repo) {
|
|
214
|
+
return (await this.getAdapter()).listBranches({ owner, repo });
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Create a branch from another branch, or from the repository default branch.
|
|
218
|
+
*/
|
|
219
|
+
async createBranch(owner, repo, branch, options = {}) {
|
|
220
|
+
await (await this.getAdapter()).createBranch({ owner, repo, branch, ...options });
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* List repository commits.
|
|
224
|
+
*/
|
|
225
|
+
async listCommits(owner, repo, options = {}) {
|
|
226
|
+
return (await this.getAdapter()).listCommits({ owner, repo, ...options });
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Create a Git commit object.
|
|
230
|
+
*/
|
|
231
|
+
async createCommit(owner, repo, message, tree, parents, options = {}) {
|
|
232
|
+
return (await this.getAdapter()).createCommit({
|
|
233
|
+
owner,
|
|
234
|
+
repo,
|
|
235
|
+
message,
|
|
236
|
+
tree,
|
|
237
|
+
parents,
|
|
238
|
+
...options,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Fetch the authenticated user, or a public user by username.
|
|
243
|
+
*/
|
|
244
|
+
async getUser(username) {
|
|
245
|
+
return (await this.getAdapter()).getUser(username ? { username } : undefined);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* List organizations for the authenticated user, or for a public user.
|
|
249
|
+
*/
|
|
250
|
+
async listOrganizations(username, options = {}) {
|
|
251
|
+
return (await this.getAdapter()).listOrganizations({ username, ...options });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAmEpD;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IACN,cAAc,CAAiC;IAEhE,YAAY,SAA8B,EAAE;QAC1C,IAAI,CAAC,cAAc,GAAG,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAA8B,EAAE;QAClD,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,SAA8B,EAAE;QAC5C,OAAO,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,SAA8B,EAAE;QACnD,OAAO,oBAAoB,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,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CAAC,UAAU,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACpF,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CACf,KAAa,EACb,IAAY,EACZ,UAAmC,EAAE;QAErC,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAChB,KAAa,EACb,IAAY,EACZ,OAAe,EACf,IAAY,EACZ,OAAiB,EACjB,UAAqC,EAAE;QAEvC,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,YAAY,CAAC;YAC5C,KAAK;YACL,IAAI;YACJ,OAAO;YACP,IAAI;YACJ,OAAO;YACP,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,QAAiB;QAC7B,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAChF,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAAiB,CACrB,QAAiB,EACjB,UAAyC,EAAE;QAE3C,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC/E,CAAC;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseGitHubAdapter } from './adapter.js';
|
|
2
|
+
import { type GitHubApiRequestMethod, type GitHubApiRequestOptions, type GitHubRuntime, type GitHubRuntimeConfig, type GitHubUserSummary } from './types.js';
|
|
3
|
+
export interface NangoProxyRequestPayload {
|
|
4
|
+
method: GitHubApiRequestMethod;
|
|
5
|
+
path: string;
|
|
6
|
+
query?: GitHubApiRequestOptions['query'];
|
|
7
|
+
body?: unknown;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
nango?: {
|
|
10
|
+
connectionId?: string;
|
|
11
|
+
providerConfigKey?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare class NangoClient extends BaseGitHubAdapter {
|
|
15
|
+
private lastNangoFallbackError;
|
|
16
|
+
constructor(config?: GitHubRuntimeConfig);
|
|
17
|
+
getRuntime(): GitHubRuntime;
|
|
18
|
+
isAuthenticated(): Promise<boolean>;
|
|
19
|
+
getCurrentUser(): Promise<GitHubUserSummary>;
|
|
20
|
+
request<TResponse = unknown>(method: GitHubApiRequestMethod, path: string, options?: GitHubApiRequestOptions): Promise<TResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the most recent Nango failure that triggered a relay-cloud fallback.
|
|
23
|
+
*/
|
|
24
|
+
getLastNangoFallbackError(): unknown;
|
|
25
|
+
private requestViaNango;
|
|
26
|
+
private requestViaRelayCloud;
|
|
27
|
+
private fetchWithTimeout;
|
|
28
|
+
private hasNangoCredentials;
|
|
29
|
+
private hasRelayCloudCredentials;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=cloud-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-runtime.d.ts","sourceRoot":"","sources":["../src/cloud-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD,OAAO,EAEL,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACvB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,sBAAsB,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE;QACN,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B,CAAC;CACH;AAED,qBAAa,WAAY,SAAQ,iBAAiB;IAChD,OAAO,CAAC,sBAAsB,CAAU;gBAE5B,MAAM,GAAE,mBAAwB;IAO5C,UAAU,IAAI,aAAa;IAIrB,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IASnC,cAAc,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAoB5C,OAAO,CAAC,SAAS,GAAG,OAAO,EAC/B,MAAM,EAAE,sBAAsB,EAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,SAAS,CAAC;IAoCrB;;OAEG;IACH,yBAAyB,IAAI,OAAO;YAItB,eAAe;YAiCf,oBAAoB;YAsDpB,gBAAgB;IAY9B,OAAO,CAAC,mBAAmB;IAM3B,OAAO,CAAC,wBAAwB;CAGjC"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { BaseGitHubAdapter } from './adapter.js';
|
|
2
|
+
import { appendQuery, trimTrailingSlash } from './actions/utils.js';
|
|
3
|
+
import { DEFAULT_NANGO_BASE_URL, DEFAULT_RELAY_CLOUD_GITHUB_PROXY_ENDPOINT } from './constants.js';
|
|
4
|
+
import { GitHubApiError, } from './types.js';
|
|
5
|
+
export class NangoClient extends BaseGitHubAdapter {
|
|
6
|
+
lastNangoFallbackError;
|
|
7
|
+
constructor(config = {}) {
|
|
8
|
+
super({
|
|
9
|
+
...config,
|
|
10
|
+
runtime: 'cloud',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
getRuntime() {
|
|
14
|
+
return 'cloud';
|
|
15
|
+
}
|
|
16
|
+
async isAuthenticated() {
|
|
17
|
+
try {
|
|
18
|
+
await this.getCurrentUser();
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async getCurrentUser() {
|
|
26
|
+
const user = await this.request('GET', '/user');
|
|
27
|
+
if (!user.login) {
|
|
28
|
+
throw new GitHubApiError('GitHub user response did not include a login.');
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
login: user.login,
|
|
32
|
+
name: user.name ?? undefined,
|
|
33
|
+
id: user.id,
|
|
34
|
+
type: user.type,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async request(method, path, options = {}) {
|
|
38
|
+
return this.executeWithRetries(async () => {
|
|
39
|
+
if (this.hasNangoCredentials()) {
|
|
40
|
+
try {
|
|
41
|
+
return await this.requestViaNango(method, path, options);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (!this.hasRelayCloudCredentials()) {
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
this.lastNangoFallbackError = error;
|
|
48
|
+
try {
|
|
49
|
+
return await this.requestViaRelayCloud(method, path, options);
|
|
50
|
+
}
|
|
51
|
+
catch (relayError) {
|
|
52
|
+
throw new GitHubApiError(`Nango GitHub proxy failed, then relay-cloud fallback failed: ${errorMessage(relayError)}`, {
|
|
53
|
+
cause: {
|
|
54
|
+
nango: error,
|
|
55
|
+
relayCloud: relayError,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (this.hasRelayCloudCredentials()) {
|
|
62
|
+
return this.requestViaRelayCloud(method, path, options);
|
|
63
|
+
}
|
|
64
|
+
throw new GitHubApiError('Cloud GitHub runtime requires Nango credentials or relay-cloud proxy configuration.');
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns the most recent Nango failure that triggered a relay-cloud fallback.
|
|
69
|
+
*/
|
|
70
|
+
getLastNangoFallbackError() {
|
|
71
|
+
return this.lastNangoFallbackError;
|
|
72
|
+
}
|
|
73
|
+
async requestViaNango(method, path, options) {
|
|
74
|
+
const secretKey = this.config.nango.secretKey;
|
|
75
|
+
const connectionId = this.config.nango.connectionId;
|
|
76
|
+
const providerConfigKey = this.config.nango.providerConfigKey;
|
|
77
|
+
if (!secretKey || !connectionId || !providerConfigKey) {
|
|
78
|
+
throw new GitHubApiError('Nango GitHub proxy requires secretKey, connectionId, and providerConfigKey.');
|
|
79
|
+
}
|
|
80
|
+
const url = buildNangoProxyUrl(this.config.nango.baseUrl, path, options.query);
|
|
81
|
+
const response = await this.fetchWithTimeout(url, {
|
|
82
|
+
method,
|
|
83
|
+
headers: {
|
|
84
|
+
Authorization: `Bearer ${secretKey}`,
|
|
85
|
+
'Connection-Id': connectionId,
|
|
86
|
+
'Provider-Config-Key': providerConfigKey,
|
|
87
|
+
Accept: 'application/json',
|
|
88
|
+
'Content-Type': 'application/json',
|
|
89
|
+
'User-Agent': this.config.userAgent,
|
|
90
|
+
...options.headers,
|
|
91
|
+
},
|
|
92
|
+
body: typeof options.body === 'undefined' ? undefined : JSON.stringify(options.body),
|
|
93
|
+
signal: options.signal,
|
|
94
|
+
timeout: options.timeout,
|
|
95
|
+
});
|
|
96
|
+
return parseJsonResponse(response);
|
|
97
|
+
}
|
|
98
|
+
async requestViaRelayCloud(method, path, options) {
|
|
99
|
+
const apiUrl = this.config.relayCloud.apiUrl;
|
|
100
|
+
const accessToken = this.config.relayCloud.accessToken;
|
|
101
|
+
const endpoint = this.config.relayCloud.endpoint ?? DEFAULT_RELAY_CLOUD_GITHUB_PROXY_ENDPOINT;
|
|
102
|
+
if (!apiUrl || !accessToken) {
|
|
103
|
+
throw new GitHubApiError('Relay cloud GitHub proxy requires apiUrl and accessToken configuration.');
|
|
104
|
+
}
|
|
105
|
+
const payload = {
|
|
106
|
+
method,
|
|
107
|
+
path,
|
|
108
|
+
query: options.query,
|
|
109
|
+
body: options.body,
|
|
110
|
+
headers: options.headers,
|
|
111
|
+
nango: {
|
|
112
|
+
connectionId: this.config.nango.connectionId,
|
|
113
|
+
providerConfigKey: this.config.nango.providerConfigKey,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
const response = await this.fetchWithTimeout(joinUrl(apiUrl, endpoint), {
|
|
117
|
+
method: 'POST',
|
|
118
|
+
headers: {
|
|
119
|
+
Authorization: `Bearer ${accessToken}`,
|
|
120
|
+
Accept: 'application/json',
|
|
121
|
+
'Content-Type': 'application/json',
|
|
122
|
+
'User-Agent': this.config.userAgent,
|
|
123
|
+
...(this.config.relayCloud.workspaceId
|
|
124
|
+
? { 'X-Relay-Workspace-Id': this.config.relayCloud.workspaceId }
|
|
125
|
+
: {}),
|
|
126
|
+
},
|
|
127
|
+
body: JSON.stringify(payload),
|
|
128
|
+
signal: options.signal,
|
|
129
|
+
timeout: options.timeout,
|
|
130
|
+
});
|
|
131
|
+
const result = await parseJsonResponse(response);
|
|
132
|
+
if (typeof result === 'object' &&
|
|
133
|
+
result !== null &&
|
|
134
|
+
'data' in result &&
|
|
135
|
+
Object.keys(result).some((key) => key === 'data')) {
|
|
136
|
+
return result.data;
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
async fetchWithTimeout(input, init) {
|
|
141
|
+
const fetchImpl = this.config.fetch ?? fetch;
|
|
142
|
+
const timeout = init.timeout ?? this.config.timeout;
|
|
143
|
+
const signal = init.signal ?? AbortSignal.timeout(timeout);
|
|
144
|
+
const { timeout: _timeout, ...requestInit } = init;
|
|
145
|
+
return fetchImpl(input, {
|
|
146
|
+
...requestInit,
|
|
147
|
+
signal,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
hasNangoCredentials() {
|
|
151
|
+
return Boolean(this.config.nango.secretKey && this.config.nango.connectionId && this.config.nango.providerConfigKey);
|
|
152
|
+
}
|
|
153
|
+
hasRelayCloudCredentials() {
|
|
154
|
+
return Boolean(this.config.relayCloud.apiUrl && this.config.relayCloud.accessToken);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async function parseJsonResponse(response) {
|
|
158
|
+
const text = await response.text();
|
|
159
|
+
if (!response.ok) {
|
|
160
|
+
throw new GitHubApiError(text || `GitHub API request failed with ${response.status} ${response.statusText}`, {
|
|
161
|
+
status: response.status,
|
|
162
|
+
responseBody: text,
|
|
163
|
+
responseHeaders: headersToRecord(response.headers),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (!text.trim()) {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
return JSON.parse(text);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
throw new GitHubApiError(`Failed to parse GitHub API JSON response: ${error instanceof Error ? error.message : String(error)}`, {
|
|
174
|
+
status: response.status,
|
|
175
|
+
responseBody: text,
|
|
176
|
+
responseHeaders: headersToRecord(response.headers),
|
|
177
|
+
cause: error,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function buildNangoProxyUrl(baseUrl, path, query) {
|
|
182
|
+
const base = trimTrailingSlash(baseUrl) ?? DEFAULT_NANGO_BASE_URL;
|
|
183
|
+
const endpoint = stripLeadingSlash(path);
|
|
184
|
+
return appendQuery(`${base}/proxy/${endpoint}`, query);
|
|
185
|
+
}
|
|
186
|
+
function joinUrl(baseUrl, path) {
|
|
187
|
+
return `${trimTrailingSlash(baseUrl) ?? baseUrl}/${stripLeadingSlash(path)}`;
|
|
188
|
+
}
|
|
189
|
+
function stripLeadingSlash(value) {
|
|
190
|
+
return value.replace(/^\/+/, '');
|
|
191
|
+
}
|
|
192
|
+
function headersToRecord(headers) {
|
|
193
|
+
const record = {};
|
|
194
|
+
headers.forEach((value, key) => {
|
|
195
|
+
record[key] = value;
|
|
196
|
+
});
|
|
197
|
+
return record;
|
|
198
|
+
}
|
|
199
|
+
function errorMessage(error) {
|
|
200
|
+
return error instanceof Error ? error.message : String(error);
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=cloud-runtime.js.map
|