@sourceaxis/provider-github 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.
@@ -0,0 +1,18 @@
1
+ import type { Blob, Branch, Commit, FileInfo, Issue, PullRequest, Reference, Release, RepositoryIdentity, RepositoryInfo, SearchResult, Tag, Tree, TreeNode } from "@sourceaxis/contracts";
2
+ import type { GitHubBlobModel, GitHubBranchModel, GitHubCommitModel, GitHubContentModel, GitHubIssueModel, GitHubPullRequestModel, GitHubRefModel, GitHubReleaseModel, GitHubRepositoryModel, GitHubSearchItemModel, GitHubTreeModel, GitHubTreeNodeModel } from "./github-models.js";
3
+ export declare function mapGitHubRepository(model: GitHubRepositoryModel, fallback: RepositoryIdentity): RepositoryInfo;
4
+ export declare function mapGitHubBranch(model: GitHubBranchModel, repository: RepositoryIdentity): Branch;
5
+ export declare function mapGitHubTag(model: GitHubRefModel, repository: RepositoryIdentity): Tag;
6
+ export declare function mapGitHubRef(model: GitHubRefModel, repository: RepositoryIdentity): Reference;
7
+ export declare function mapGitHubCommit(model: GitHubCommitModel): Commit;
8
+ export declare function mapGitHubTree(model: GitHubTreeModel, path?: string): Tree;
9
+ export declare function mapGitHubTreeNode(model: GitHubTreeNodeModel): TreeNode;
10
+ export declare function mapGitHubContentToFileInfo(model: GitHubContentModel): FileInfo;
11
+ export declare function mapGitHubContentToBlob(model: GitHubContentModel): Blob;
12
+ export declare function mapGitHubBlob(model: GitHubBlobModel, path: string): Blob;
13
+ export declare function mapGitHubContentToTreeNode(model: GitHubContentModel): TreeNode;
14
+ export declare function mapGitHubIssue(model: GitHubIssueModel): Issue;
15
+ export declare function mapGitHubPullRequest(model: GitHubPullRequestModel, repository: RepositoryIdentity): PullRequest;
16
+ export declare function mapGitHubRelease(model: GitHubReleaseModel): Release;
17
+ export declare function mapGitHubSearchItem(model: GitHubSearchItemModel): SearchResult;
18
+ //# sourceMappingURL=mappers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../../src/mappers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,MAAM,EACN,MAAM,EACN,QAAQ,EACR,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,EACP,kBAAkB,EAClB,cAAc,EAEd,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,QAAQ,EACT,MAAM,uBAAuB,CAAC;AAK/B,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAElB,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EAEpB,MAAM,oBAAoB,CAAC;AAE5B,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,qBAAqB,EAC5B,QAAQ,EAAE,kBAAkB,GAC3B,cAAc,CAoChB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,kBAAkB,GAAG,MAAM,CAYhG;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,kBAAkB,GAAG,GAAG,CAUvF;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,kBAAkB,GAAG,SAAS,CAiB7F;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CA0BhE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,SAAK,GAAG,IAAI,CAQrE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,mBAAmB,GAAG,QAAQ,CAYtE;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,kBAAkB,GAAG,QAAQ,CAc9E;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAStE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CASxE;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,kBAAkB,GAAG,QAAQ,CAW9E;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,gBAAgB,GAAG,KAAK,CA6B7D;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,sBAAsB,EAC7B,UAAU,EAAE,kBAAkB,GAC7B,WAAW,CA+Bb;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CA0BnE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,qBAAqB,GAAG,YAAY,CAe9E"}
@@ -0,0 +1,380 @@
1
+ import { ValidationError } from "@sourceaxis/errors";
2
+ import { deepFreeze } from "@sourceaxis/shared";
3
+ import { GitHubProviderId } from "./constants.js";
4
+ export function mapGitHubRepository(model, fallback) {
5
+ const identity = deepFreeze({
6
+ name: requiredString(model.name ?? fallback.name, "GitHub repository name is missing"),
7
+ owner: requiredString(model.owner?.login ?? fallback.owner, "GitHub repository owner is missing"),
8
+ provider: GitHubProviderId
9
+ });
10
+ const info = deepFreeze({
11
+ createdAt: model.created_at ?? undefined,
12
+ defaultBranch: model.default_branch ?? undefined,
13
+ description: model.description ?? undefined,
14
+ fullName: model.full_name ?? `${identity.owner}/${identity.name}`,
15
+ identity,
16
+ isArchived: model.archived,
17
+ isFork: model.fork,
18
+ license: model.license === null || model.license === undefined
19
+ ? undefined
20
+ : {
21
+ key: requiredString(model.license.key ?? undefined, "GitHub license key is missing"),
22
+ name: requiredString(model.license.name ?? undefined, "GitHub license name is missing"),
23
+ spdxId: model.license.spdx_id ?? undefined,
24
+ url: model.license.url ?? undefined
25
+ },
26
+ metadata: { provider: GitHubProviderId },
27
+ name: identity.name,
28
+ owner: mapGitHubOwner(model.owner, identity.owner),
29
+ updatedAt: model.updated_at ?? undefined,
30
+ url: model.html_url ?? `https://github.com/${identity.owner}/${identity.name}`,
31
+ visibility: mapRepositoryVisibility(model)
32
+ });
33
+ return info;
34
+ }
35
+ export function mapGitHubBranch(model, repository) {
36
+ const name = requiredString(model.name, "GitHub branch name is missing");
37
+ return deepFreeze({
38
+ default: false,
39
+ metadata: { provider: GitHubProviderId },
40
+ name,
41
+ protected: model.protected,
42
+ repository,
43
+ target: requiredString(model.commit?.sha, "GitHub branch commit sha is missing"),
44
+ type: "branch"
45
+ });
46
+ }
47
+ export function mapGitHubTag(model, repository) {
48
+ const name = refName(model.ref, "tags");
49
+ return deepFreeze({
50
+ metadata: { provider: GitHubProviderId },
51
+ name,
52
+ repository,
53
+ target: requiredString(model.object?.sha, "GitHub tag target sha is missing"),
54
+ type: "tag"
55
+ });
56
+ }
57
+ export function mapGitHubRef(model, repository) {
58
+ const ref = requiredString(model.ref, "GitHub ref name is missing");
59
+ const type = ref.startsWith("refs/tags/")
60
+ ? "tag"
61
+ : ref.startsWith("refs/pull/")
62
+ ? "pull-request"
63
+ : ref.startsWith("refs/heads/")
64
+ ? "branch"
65
+ : "detached";
66
+ return deepFreeze({
67
+ metadata: { provider: GitHubProviderId },
68
+ name: ref.replace(/^refs\/(?:heads|tags)\//u, ""),
69
+ repository,
70
+ target: requiredString(model.object?.sha, "GitHub ref target sha is missing"),
71
+ type
72
+ });
73
+ }
74
+ export function mapGitHubCommit(model) {
75
+ const sha = requiredString(model.sha, "GitHub commit sha is missing");
76
+ return deepFreeze({
77
+ author: mapGitActor(model.commit?.author, model.author),
78
+ committer: model.commit?.committer === undefined || model.commit.committer === null
79
+ ? undefined
80
+ : mapGitActor(model.commit.committer),
81
+ message: model.commit?.message ?? "",
82
+ metadata: { provider: GitHubProviderId },
83
+ parents: (model.parents ?? []).flatMap((parent) => parent.sha === undefined ? [] : [{ sha: parent.sha, url: parent.url }]),
84
+ sha,
85
+ tree: requiredString(model.commit?.tree?.sha, "GitHub commit tree sha is missing"),
86
+ url: model.html_url,
87
+ verification: model.commit?.verification === undefined || model.commit.verification === null
88
+ ? undefined
89
+ : {
90
+ reason: model.commit.verification.reason ?? undefined,
91
+ signature: model.commit.verification.signature ?? undefined,
92
+ status: model.commit.verification.verified === true ? "verified" : "unverified"
93
+ }
94
+ });
95
+ }
96
+ export function mapGitHubTree(model, path = "") {
97
+ return deepFreeze({
98
+ metadata: { provider: GitHubProviderId },
99
+ nodes: (model.tree ?? []).map(mapGitHubTreeNode),
100
+ path,
101
+ sha: requiredString(model.sha, "GitHub tree sha is missing"),
102
+ truncated: model.truncated
103
+ });
104
+ }
105
+ export function mapGitHubTreeNode(model) {
106
+ const path = requiredString(model.path, "GitHub tree node path is missing");
107
+ return deepFreeze({
108
+ metadata: { provider: GitHubProviderId },
109
+ mode: model.mode,
110
+ name: path.split("/").pop() ?? path,
111
+ path,
112
+ sha: model.sha,
113
+ size: model.size,
114
+ type: mapTreeNodeType(model.type)
115
+ });
116
+ }
117
+ export function mapGitHubContentToFileInfo(model) {
118
+ const path = requiredString(model.path, "GitHub content path is missing");
119
+ return deepFreeze({
120
+ downloadUrl: model.download_url ?? undefined,
121
+ metadata: {
122
+ links: model.html_url === undefined ? undefined : [{ href: model.html_url, rel: "html" }],
123
+ provider: GitHubProviderId
124
+ },
125
+ name: model.name ?? path.split("/").pop() ?? path,
126
+ path,
127
+ sha: model.sha,
128
+ size: model.size
129
+ });
130
+ }
131
+ export function mapGitHubContentToBlob(model) {
132
+ return deepFreeze({
133
+ content: model.content === null || model.content === undefined ? undefined : model.content,
134
+ encoding: model.encoding === "base64" ? "base64" : "utf-8",
135
+ metadata: { provider: GitHubProviderId },
136
+ path: requiredString(model.path, "GitHub content path is missing"),
137
+ sha: requiredString(model.sha, "GitHub content sha is missing"),
138
+ size: model.size ?? 0
139
+ });
140
+ }
141
+ export function mapGitHubBlob(model, path) {
142
+ return deepFreeze({
143
+ content: model.content === null || model.content === undefined ? undefined : model.content,
144
+ encoding: model.encoding === "base64" ? "base64" : "utf-8",
145
+ metadata: { provider: GitHubProviderId },
146
+ path,
147
+ sha: requiredString(model.sha, "GitHub blob sha is missing"),
148
+ size: model.size ?? 0
149
+ });
150
+ }
151
+ export function mapGitHubContentToTreeNode(model) {
152
+ const path = requiredString(model.path, "GitHub content path is missing");
153
+ return deepFreeze({
154
+ metadata: { provider: GitHubProviderId },
155
+ name: model.name ?? path.split("/").pop() ?? path,
156
+ path,
157
+ sha: model.sha,
158
+ size: model.size,
159
+ type: mapContentType(model.type)
160
+ });
161
+ }
162
+ export function mapGitHubIssue(model) {
163
+ return deepFreeze({
164
+ assignees: (model.assignees ?? undefined)?.map((assignee) => mapGitHubUser(assignee, assignee.login ?? "unknown")),
165
+ author: model.user === null || model.user === undefined
166
+ ? undefined
167
+ : mapGitHubUser(model.user, model.user.login ?? "unknown"),
168
+ body: model.body ?? undefined,
169
+ closedAt: model.closed_at ?? undefined,
170
+ createdAt: model.created_at ?? undefined,
171
+ id: model.id === undefined ? undefined : String(model.id),
172
+ labels: (model.labels ?? []).flatMap((label) => {
173
+ if (typeof label === "string") {
174
+ return [label];
175
+ }
176
+ return label.name === undefined || label.name === null ? [] : [label.name];
177
+ }),
178
+ metadata: {
179
+ links: model.html_url === undefined ? undefined : [{ href: model.html_url, rel: "html" }],
180
+ provider: GitHubProviderId
181
+ },
182
+ number: requiredNumber(model.number, "GitHub issue number is missing"),
183
+ state: model.state === "closed" ? "closed" : "open",
184
+ title: requiredString(model.title, "GitHub issue title is missing"),
185
+ updatedAt: model.updated_at ?? undefined
186
+ });
187
+ }
188
+ export function mapGitHubPullRequest(model, repository) {
189
+ return deepFreeze({
190
+ author: model.user === null || model.user === undefined
191
+ ? undefined
192
+ : mapGitHubUser(model.user, model.user.login ?? "unknown"),
193
+ body: model.body ?? undefined,
194
+ closedAt: model.closed_at ?? undefined,
195
+ createdAt: model.created_at ?? undefined,
196
+ id: model.id === undefined ? undefined : String(model.id),
197
+ mergeStatus: model.merged === true ? "clean" : "unknown",
198
+ mergedAt: model.merged_at ?? undefined,
199
+ metadata: {
200
+ links: model.html_url === undefined ? undefined : [{ href: model.html_url, rel: "html" }],
201
+ provider: GitHubProviderId
202
+ },
203
+ number: requiredNumber(model.number, "GitHub pull request number is missing"),
204
+ source: {
205
+ branch: requiredString(model.head?.ref, "GitHub pull request source branch is missing"),
206
+ repository: mapPullRequestRepository(model.head?.repo, repository),
207
+ sha: model.head?.sha
208
+ },
209
+ state: model.merged === true ? "merged" : model.state === "closed" ? "closed" : "open",
210
+ target: {
211
+ branch: requiredString(model.base?.ref, "GitHub pull request target branch is missing"),
212
+ repository: mapPullRequestRepository(model.base?.repo, repository),
213
+ sha: model.base?.sha
214
+ },
215
+ title: requiredString(model.title, "GitHub pull request title is missing"),
216
+ updatedAt: model.updated_at ?? undefined
217
+ });
218
+ }
219
+ export function mapGitHubRelease(model) {
220
+ return deepFreeze({
221
+ assets: (model.assets ?? []).map((asset) => ({
222
+ contentType: asset.content_type,
223
+ createdAt: asset.created_at ?? undefined,
224
+ downloadUrl: asset.browser_download_url,
225
+ metadata: { provider: GitHubProviderId },
226
+ name: requiredString(asset.name, "GitHub release asset name is missing"),
227
+ size: asset.size
228
+ })),
229
+ author: model.author === null || model.author === undefined
230
+ ? undefined
231
+ : mapGitHubUser(model.author, model.author.login ?? "unknown"),
232
+ body: model.body ?? undefined,
233
+ createdAt: model.created_at ?? undefined,
234
+ id: model.id === undefined ? undefined : String(model.id),
235
+ metadata: {
236
+ links: model.html_url === undefined ? undefined : [{ href: model.html_url, rel: "html" }],
237
+ provider: GitHubProviderId
238
+ },
239
+ name: model.name ?? undefined,
240
+ publishedAt: model.published_at ?? undefined,
241
+ state: model.draft === true ? "draft" : model.prerelease === true ? "prerelease" : "published",
242
+ tagName: requiredString(model.tag_name, "GitHub release tag name is missing")
243
+ });
244
+ }
245
+ export function mapGitHubSearchItem(model) {
246
+ const kind = mapSearchKind(model);
247
+ const path = model.path ?? model.name ?? model.title ?? model.sha ?? "result";
248
+ return deepFreeze({
249
+ item: {
250
+ downloadUrl: model.html_url,
251
+ metadata: { provider: GitHubProviderId },
252
+ name: path.split("/").pop() ?? path,
253
+ path,
254
+ sha: model.sha
255
+ },
256
+ kind,
257
+ score: model.score
258
+ });
259
+ }
260
+ function mapGitHubOwner(model, fallback) {
261
+ if (model?.type === "Organization") {
262
+ return deepFreeze({
263
+ avatarUrl: model.avatar_url ?? undefined,
264
+ displayName: model.name ?? model.login ?? fallback,
265
+ id: model.id === undefined ? undefined : String(model.id),
266
+ name: model.login ?? fallback,
267
+ url: model.html_url ?? undefined
268
+ });
269
+ }
270
+ return deepFreeze({
271
+ avatarUrl: model?.avatar_url ?? undefined,
272
+ displayName: model?.name ?? model?.login ?? fallback,
273
+ id: model?.id === undefined ? undefined : String(model.id),
274
+ url: model?.html_url ?? undefined,
275
+ username: model?.login ?? fallback
276
+ });
277
+ }
278
+ function mapGitHubUser(model, fallback) {
279
+ return deepFreeze({
280
+ avatarUrl: model.avatar_url ?? undefined,
281
+ displayName: model.name ?? model.login ?? fallback,
282
+ id: model.id === undefined ? undefined : String(model.id),
283
+ url: model.html_url ?? undefined,
284
+ username: model.login ?? fallback
285
+ });
286
+ }
287
+ function mapRepositoryVisibility(model) {
288
+ if (model.visibility === "internal") {
289
+ return "internal";
290
+ }
291
+ if (model.private === true || model.visibility === "private") {
292
+ return "private";
293
+ }
294
+ if (model.private === false || model.visibility === "public") {
295
+ return "public";
296
+ }
297
+ return "unknown";
298
+ }
299
+ function mapGitActor(model, user) {
300
+ return deepFreeze({
301
+ date: model?.date ?? undefined,
302
+ email: model?.email ?? undefined,
303
+ name: model?.name ?? user?.login ?? "unknown",
304
+ user: user === null || user === undefined
305
+ ? undefined
306
+ : mapGitHubOwner(user, user.login ?? "unknown")
307
+ });
308
+ }
309
+ function mapPullRequestRepository(model, fallback) {
310
+ if (model === null || model === undefined) {
311
+ return fallback;
312
+ }
313
+ return {
314
+ name: model.name ?? fallback.name,
315
+ owner: model.owner?.login ?? fallback.owner,
316
+ provider: GitHubProviderId
317
+ };
318
+ }
319
+ function mapSearchKind(model) {
320
+ if (model.type === "commit") {
321
+ return "commit";
322
+ }
323
+ if (model.type === "issue") {
324
+ return "issue";
325
+ }
326
+ if (model.type === "pull-request" || model.number !== undefined) {
327
+ return "pull-request";
328
+ }
329
+ if (model.type === "release") {
330
+ return "release";
331
+ }
332
+ return "file";
333
+ }
334
+ function mapTreeNodeType(type) {
335
+ if (type === "tree") {
336
+ return "directory";
337
+ }
338
+ if (type === "commit") {
339
+ return "submodule";
340
+ }
341
+ return "file";
342
+ }
343
+ function mapContentType(type) {
344
+ if (type === "dir") {
345
+ return "directory";
346
+ }
347
+ if (type === "symlink") {
348
+ return "symlink";
349
+ }
350
+ if (type === "submodule") {
351
+ return "submodule";
352
+ }
353
+ return "file";
354
+ }
355
+ function refName(ref, namespace) {
356
+ const full = requiredString(ref, "GitHub ref name is missing");
357
+ return full.replace(new RegExp(`^refs/${namespace}/`, "u"), "");
358
+ }
359
+ function requiredString(value, message) {
360
+ if (value === undefined || value === null || value.trim() === "") {
361
+ throw new ValidationError(message, {
362
+ diagnostics: {
363
+ operation: { operation: "github.map" },
364
+ provider: { provider: GitHubProviderId }
365
+ }
366
+ });
367
+ }
368
+ return value;
369
+ }
370
+ function requiredNumber(value, message) {
371
+ if (value === undefined) {
372
+ throw new ValidationError(message, {
373
+ diagnostics: {
374
+ operation: { operation: "github.map" },
375
+ provider: { provider: GitHubProviderId }
376
+ }
377
+ });
378
+ }
379
+ return value;
380
+ }
@@ -0,0 +1,15 @@
1
+ import type { GitHubOctokitAdapter, GitHubOctokitAdapterContext } from "./index.js";
2
+ type OctokitRequestFunction = <TBody = unknown>(route: string, parameters?: Readonly<Record<string, unknown>>) => Promise<Readonly<{
3
+ data?: TBody;
4
+ headers?: Readonly<Record<string, string>>;
5
+ status: number;
6
+ }>>;
7
+ export type InternalOctokitClient = Readonly<{
8
+ request: OctokitRequestFunction;
9
+ }>;
10
+ export type InternalOctokitAdapterOptions = Readonly<{
11
+ client?: InternalOctokitClient;
12
+ }>;
13
+ export declare function createOctokitAdapter(context: GitHubOctokitAdapterContext, options?: InternalOctokitAdapterOptions): GitHubOctokitAdapter;
14
+ export {};
15
+ //# sourceMappingURL=octokit-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"octokit-adapter.d.ts","sourceRoot":"","sources":["../../src/octokit-adapter.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,oBAAoB,EACpB,2BAA2B,EAG5B,MAAM,YAAY,CAAC;AAEpB,KAAK,sBAAsB,GAAG,CAAC,KAAK,GAAG,OAAO,EAC5C,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAC3C,OAAO,CACV,QAAQ,CAAC;IAAE,IAAI,CAAC,EAAE,KAAK,CAAC;IAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CACvF,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC;IAC3C,OAAO,EAAE,sBAAsB,CAAC;CACjC,CAAC,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,QAAQ,CAAC;IACnD,MAAM,CAAC,EAAE,qBAAqB,CAAC;CAChC,CAAC,CAAC;AAEH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,2BAA2B,EACpC,OAAO,GAAE,6BAAkC,GAC1C,oBAAoB,CAmBtB"}
@@ -0,0 +1,51 @@
1
+ import { Octokit } from "@octokit/rest";
2
+ import { deepFreeze } from "@repoferry/shared";
3
+ export function createOctokitAdapter(context, options = {}) {
4
+ const client = options.client ?? createOctokitClient(context.authentication);
5
+ return deepFreeze({
6
+ async request(request) {
7
+ const response = await client.request(`${request.method ?? "GET"} ${request.url}`, createOctokitParameters(request));
8
+ return deepFreeze({
9
+ data: response.data,
10
+ headers: response.headers,
11
+ status: response.status
12
+ });
13
+ }
14
+ });
15
+ }
16
+ function createOctokitClient(authentication) {
17
+ const token = getAuthenticationToken(authentication);
18
+ const options = {};
19
+ if (token !== undefined) {
20
+ options.auth = token;
21
+ }
22
+ return new Octokit(options);
23
+ }
24
+ function createOctokitParameters(request) {
25
+ const parameters = {};
26
+ if (request.body !== undefined) {
27
+ parameters.data = request.body;
28
+ }
29
+ if (request.headers !== undefined) {
30
+ parameters.headers = request.headers;
31
+ }
32
+ if (request.signal !== undefined) {
33
+ parameters.request = { signal: request.signal };
34
+ }
35
+ if (request.timeoutMs !== undefined) {
36
+ parameters.request = {
37
+ ...(typeof parameters.request === "object" && parameters.request !== null
38
+ ? parameters.request
39
+ : {}),
40
+ timeout: request.timeoutMs
41
+ };
42
+ }
43
+ return deepFreeze(parameters);
44
+ }
45
+ function getAuthenticationToken(authentication) {
46
+ const credentials = authentication?.credentials;
47
+ if (credentials === undefined || credentials.kind === "anonymous" || !("token" in credentials)) {
48
+ return undefined;
49
+ }
50
+ return typeof credentials.token === "string" ? credentials.token : undefined;
51
+ }
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@sourceaxis/provider-github",
3
+ "version": "0.1.0",
4
+ "description": "GitHub provider foundation for SourceAxis.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/esm/index.d.ts",
15
+ "import": "./dist/esm/index.js",
16
+ "require": "./dist/cjs/index.js",
17
+ "default": "./dist/esm/index.js"
18
+ }
19
+ },
20
+ "types": "./dist/esm/index.d.ts",
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.esm.json && node ../../scripts/build/build-cjs.mjs .",
23
+ "test": "vitest run --config vitest.config.mjs",
24
+ "typecheck": "tsc -p tsconfig.json --noEmit"
25
+ },
26
+ "dependencies": {
27
+ "@sourceaxis/auth": "workspace:*",
28
+ "@sourceaxis/cache": "workspace:*",
29
+ "@sourceaxis/contracts": "workspace:*",
30
+ "@sourceaxis/core": "workspace:*",
31
+ "@sourceaxis/errors": "workspace:*",
32
+ "@sourceaxis/observability": "workspace:*",
33
+ "@sourceaxis/shared": "workspace:*",
34
+ "@sourceaxis/transport": "workspace:*"
35
+ },
36
+ "main": "./dist/cjs/index.js",
37
+ "module": "./dist/esm/index.js",
38
+ "engines": {
39
+ "node": ">=20.19.0"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/mriduldey/source-axis.git",
44
+ "directory": "packages/provider-github"
45
+ },
46
+ "bugs": {
47
+ "url": "https://github.com/mriduldey/source-axis/issues"
48
+ },
49
+ "homepage": "https://github.com/mriduldey/source-axis#readme",
50
+ "keywords": [
51
+ "git",
52
+ "github",
53
+ "sdk",
54
+ "typescript",
55
+ "provider-neutral"
56
+ ],
57
+ "publishConfig": {
58
+ "access": "public",
59
+ "provenance": true
60
+ }
61
+ }