generated from NatoBoram/gigachad.ts
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
77 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { test } from "vitest" | ||
import { fromBase64, toBase64 } from "./base64.js" | ||
|
||
test("toBase64", ({ expect }) => { | ||
const based = toBase64("Copyright © 2024 CodeRabbit") | ||
expect(based).toBe("Q29weXJpZ2h0IMKpIDIwMjQgQ29kZVJhYmJpdA==") | ||
}) | ||
|
||
test("fromBase64", ({ expect }) => { | ||
const debased = fromBase64("Q29weXJpZ2h0IMKpIDIwMjQgQ29kZVJhYmJpdA==") | ||
expect(debased).toBe("Copyright © 2024 CodeRabbit") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function toBase64(input: string): string { | ||
const bytes = new TextEncoder().encode(input) | ||
const string = String.fromCodePoint(...bytes) | ||
return btoa(string) | ||
} | ||
|
||
export function fromBase64(base64: string): Buffer | Uint8Array | string { | ||
const string = atob(base64) | ||
const bytes = Uint8Array.from(string, v => v.codePointAt(0) ?? 0) | ||
return new TextDecoder().decode(bytes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
import createClient, { type Client, type ClientOptions } from "openapi-fetch" | ||
import type { Client, ClientOptions } from "openapi-fetch" | ||
import createClient from "openapi-fetch" | ||
import type { paths } from "./openapi/index.js" | ||
|
||
/** | ||
* Creates an `openapi-fetch` client using {@link createClient}. | ||
* | ||
* @example | ||
* export client = createBitbucketCloudClient({ | ||
* baseUrl: "https://api.bitbucket.org/2.0", | ||
* headers: { Accept: "application/json", Authorization: `Basic ${basic}` }, | ||
* }) | ||
*/ | ||
export const createBitbucketCloudClient: ( | ||
clientOptions?: ClientOptions, | ||
) => Client<paths, "application/json"> = createClient<paths, "application/json"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./base64.js" | ||
export * from "./cloud/index.js" | ||
export * from "./server/index.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import type { Client } from "openapi-fetch" | ||
import type { paths } from "../../src/cloud/openapi/openapi-typescript.js" | ||
import { createBitbucketCloudClient } from "../../src/index.js" | ||
import { createBitbucketCloudClient, toBase64 } from "../../src/index.js" | ||
import { | ||
BITBUCKET_CLOUD_APP_PASSWORD, | ||
BITBUCKET_CLOUD_URL, | ||
BITBUCKET_CLOUD_USERNAME, | ||
} from "../env.js" | ||
|
||
const basic = Buffer.from( | ||
const basic = toBase64( | ||
BITBUCKET_CLOUD_USERNAME + ":" + BITBUCKET_CLOUD_APP_PASSWORD, | ||
).toString("base64") | ||
) | ||
|
||
export const cloud: Client<paths, "application/json"> = | ||
createBitbucketCloudClient({ | ||
baseUrl: BITBUCKET_CLOUD_URL, | ||
headers: { Accept: "application/json", Authorization: `Basic ${basic}` }, | ||
}) | ||
export const cloud = createBitbucketCloudClient({ | ||
baseUrl: BITBUCKET_CLOUD_URL.toString(), | ||
headers: { Accept: "application/json", Authorization: `Basic ${basic}` }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
import type { Client } from "openapi-fetch" | ||
import { createBitbucketServerClient } from "../../src/index.js" | ||
import type { paths } from "../../src/server/openapi/openapi-typescript.js" | ||
import { BITBUCKET_SERVER_TOKEN, BITBUCKET_SERVER_URL } from "../env.js" | ||
|
||
export const server: Client<paths, "application/json"> = | ||
createBitbucketServerClient({ | ||
baseUrl: BITBUCKET_SERVER_URL, | ||
headers: { | ||
Accept: "application/json", | ||
Authorization: `Bearer ${BITBUCKET_SERVER_TOKEN}`, | ||
}, | ||
}) | ||
export const server = createBitbucketServerClient({ | ||
baseUrl: BITBUCKET_SERVER_URL.toString(), | ||
headers: { | ||
Accept: "application/json", | ||
Authorization: `Bearer ${BITBUCKET_SERVER_TOKEN}`, | ||
}, | ||
}) |