diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9f090cc70f..e4e776154c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: CI +name: ๐Ÿ› ๏ธ CI on: push: @@ -14,77 +14,77 @@ env: jobs: build: - name: Build + name: ๐Ÿ—๏ธ Build runs-on: ubuntu-latest strategy: matrix: node-version: [20.x, 22.x] steps: - - name: Checkout sources + - name: ๐Ÿ”„ Checkout sources uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} + - name: โš™๏ธ Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - - name: Install pnpm + - name: ๐Ÿ“ฆ Install pnpm uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - - name: Installing dependencies + - name: ๐Ÿ“Œ Installing dependencies run: pnpm install --frozen-lockfile - - name: Building sources + - name: ๐Ÿ› ๏ธ Building sources run: pnpm run build lint: - name: Lint Code + name: ๐Ÿ” Lint Code needs: build runs-on: ubuntu-latest strategy: matrix: node-version: [20.x, 22.x] steps: - - name: Checkout sources + - name: ๐Ÿ”„ Checkout sources uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} + - name: โš™๏ธ Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - - name: Install pnpm + - name: ๐Ÿ“ฆ Install pnpm uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - - name: Installing dependencies + - name: ๐Ÿ“Œ Installing dependencies run: pnpm install --frozen-lockfile - - name: Linting + - name: โœจ Linting run: pnpm run lint env: CI: true test_unit: - name: Unit Tests + name: ๐Ÿงช Unit Tests needs: build runs-on: ubuntu-latest strategy: matrix: node-version: [20.x, 22.x] steps: - - name: Checkout sources + - name: ๐Ÿ”„ Checkout sources uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} + - name: โš™๏ธ Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - - name: Install pnpm + - name: ๐Ÿ“ฆ Install pnpm uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - - name: Installing dependencies + - name: ๐Ÿ“Œ Installing dependencies run: pnpm install --frozen-lockfile - - name: Running unit tests + - name: ๐Ÿš€ Running unit tests run: pnpm run test:unit test_integration: - name: Integration Tests + name: ๐Ÿงฉ Integration Tests needs: - lint - test_unit @@ -94,23 +94,23 @@ jobs: matrix: node-version: [20.x, 22.x] steps: - - name: Checkout sources + - name: ๐Ÿ”„ Checkout sources uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} + - name: โš™๏ธ Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - - name: Install pnpm + - name: ๐Ÿ“ฆ Install pnpm uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - - name: Installing dependencies + - name: ๐Ÿ“Œ Installing dependencies run: pnpm install --frozen-lockfile - - name: Creating `.env` file + - name: ๐Ÿ“ Creating `.env` file run: | touch .env echo HOST=${{ secrets.HOST }} >> .env echo EMAIL=${{ secrets.EMAIL }} >> .env echo API_TOKEN=${{ secrets.API_TOKEN }} >> .env - - name: Running integration tests + - name: ๐Ÿš€ Running integration tests run: pnpm run test:integration diff --git a/.github/workflows/publish-dev.yml b/.github/workflows/publish-dev.yml index 6888bea535..cb0803ce7b 100644 --- a/.github/workflows/publish-dev.yml +++ b/.github/workflows/publish-dev.yml @@ -1,4 +1,4 @@ -name: Publish to NPM Dev Channel +name: ๐Ÿš€ Publish to NPM Dev Channel on: workflow_dispatch @@ -6,28 +6,27 @@ on: permissions: contents: read - jobs: build-and-publish: runs-on: ubuntu-latest steps: - - name: Checkout code + - name: ๐Ÿ”„ Checkout code uses: actions/checkout@v4 - - name: Set up Node.js + - name: โš™๏ธ Set up Node.js uses: actions/setup-node@v4 with: node-version: 20 registry-url: https://registry.npmjs.org/ - - name: Install dependencies + - name: ๐Ÿ“ฆ Install dependencies run: npm install - - name: Build project + - name: ๐Ÿ› ๏ธ Build project run: npm run build - - name: Update package version + - name: ๐Ÿ”– Update package version id: update-version run: | CURRENT_VERSION=$(node -p "require('./package.json').version") @@ -37,10 +36,10 @@ jobs: echo "New version: $NEW_VERSION" echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - - name: Update package-lock.json + - name: ๐Ÿ”„ Update package-lock.json run: npm install - - name: Publish to NPM Dev Channel + - name: ๐Ÿ“ค Publish to NPM Dev Channel run: npm publish --tag dev env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index acdc872493..dd571ceeab 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,39 +13,39 @@ permissions: jobs: build-and-test: - name: Build and Test + name: ๐Ÿ—๏ธ Build and Test runs-on: ubuntu-latest steps: - - name: Checkout repository + - name: ๐Ÿ”„ Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Setup Node.js ${{ env.NODE_VERSION }} + - name: โš™๏ธ Setup Node.js ${{ env.NODE_VERSION }} uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} - - name: Install pnpm + - name: ๐Ÿ“ฆ Install pnpm uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - - name: Install dependencies + - name: ๐Ÿ“Œ Install dependencies run: pnpm install --frozen-lockfile - - name: Run build + - name: ๐Ÿ› ๏ธ Run build run: pnpm run build - - name: Run lint + - name: ๐Ÿ” Run lint run: pnpm run lint env: CI: true - - name: Run unit tests + - name: ๐Ÿงช Run unit tests run: pnpm run test:unit - - name: Run integration tests + - name: ๐Ÿงฉ Run integration tests run: pnpm run test:integration env: HOST: ${{ secrets.HOST }} @@ -53,29 +53,29 @@ jobs: API_TOKEN: ${{ secrets.API_TOKEN }} publish-package: - name: Publish Package + name: ๐Ÿš€ Publish Package needs: build-and-test runs-on: ubuntu-latest permissions: contents: write steps: - - name: Checkout repository + - name: ๐Ÿ”„ Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Setup Node.js ${{ env.NODE_VERSION }} + - name: โš™๏ธ Setup Node.js ${{ env.NODE_VERSION }} uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} registry-url: 'https://registry.npmjs.org' - - name: Install pnpm + - name: ๐Ÿ“ฆ Install pnpm uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - - name: Get and validate version + - name: ๐Ÿ”– Get and validate version id: version run: | if [[ $GITHUB_REF == refs/tags/v* ]]; then @@ -103,47 +103,48 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.PAT }} - - name: Install dependencies + - name: ๐Ÿ“Œ Install dependencies run: pnpm install --frozen-lockfile - - name: Build package + - name: ๐Ÿ› ๏ธ Build package run: pnpm run build - - name: Publish to NPM + - name: ๐Ÿ“ค Publish to NPM run: pnpm publish --no-git-checks env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} deploy-documentation: - name: Deploy Documentation + name: ๐Ÿ“š Deploy Documentation needs: publish-package runs-on: ubuntu-latest steps: - - name: Checkout repository + - name: ๐Ÿ”„ Checkout repository uses: actions/checkout@v4 with: ref: master - - name: Setup Node.js ${{ env.NODE_VERSION }} + - name: โš™๏ธ Setup Node.js ${{ env.NODE_VERSION }} uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} - - name: Install pnpm + - name: ๐Ÿ“ฆ Install pnpm uses: pnpm/action-setup@v4 with: version: ${{ env.PNPM_VERSION }} - - name: Install dependencies + - name: ๐Ÿ“Œ Install dependencies run: pnpm install --frozen-lockfile - - name: Generate documentation + - name: ๐Ÿ“ Generate documentation run: pnpm run doc - - name: Deploy to docs branch + - name: ๐Ÿš€ Deploy to docs branch uses: JamesIves/github-pages-deploy-action@v4 with: branch: docs folder: docs clean: true + token: '${{ secrets.PAT }}' commit-message: "docs: Update documentation for v${{ needs.publish-package.outputs.version }} [skip ci]" diff --git a/package.json b/package.json index 21bb0ab101..a36afa6261 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "rollup": "^4.40.1", "sinon": "^20.0.0", "tslib": "^2.8.1", - "typedoc": "^0.28.3", + "typedoc": "^0.28.4", "typescript": "^5.8.3", "typescript-eslint": "^8.31.1", "vitest": "^3.1.2" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7d7dee9709..ad6fcafdd8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -70,8 +70,8 @@ importers: specifier: ^2.8.1 version: 2.8.1 typedoc: - specifier: ^0.28.3 - version: 0.28.3(typescript@5.8.3) + specifier: ^0.28.4 + version: 0.28.4(typescript@5.8.3) typescript: specifier: ^5.8.3 version: 5.8.3 @@ -1572,8 +1572,8 @@ packages: resolution: {integrity: sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==} engines: {node: '>= 0.6'} - typedoc@0.28.3: - resolution: {integrity: sha512-5svOCTfXvVSh6zbZKSQluZhR8yN2tKpTeHZxlmWpE6N5vc3R8k/jhg9nnD6n5tN9/ObuQTojkONrOxFdUFUG9w==} + typedoc@0.28.4: + resolution: {integrity: sha512-xKvKpIywE1rnqqLgjkoq0F3wOqYaKO9nV6YkkSat6IxOWacUCc/7Es0hR3OPmkIqkPoEn7U3x+sYdG72rstZQA==} engines: {node: '>= 18', pnpm: '>= 10'} hasBin: true peerDependencies: @@ -3270,7 +3270,7 @@ snapshots: media-typer: 1.1.0 mime-types: 3.0.1 - typedoc@0.28.3(typescript@5.8.3): + typedoc@0.28.4(typescript@5.8.3): dependencies: '@gerrit0/mini-shiki': 3.3.0 lunr: 2.3.9 diff --git a/src/version2/issueAttachments.ts b/src/version2/issueAttachments.ts index db15b276cd..2f1aecc23d 100644 --- a/src/version2/issueAttachments.ts +++ b/src/version2/issueAttachments.ts @@ -1,5 +1,3 @@ -import type { Mime } from 'mime'; -import mime from 'mime'; import type * as Models from './models'; import type * as Parameters from './parameters'; import type { Client } from '../clients'; @@ -424,23 +422,9 @@ export class IssueAttachments { const formData = new FormData(); const attachments = Array.isArray(parameters.attachment) ? parameters.attachment : [parameters.attachment]; - // eslint-disable-next-line @typescript-eslint/consistent-type-imports - let Readable: typeof import('stream').Readable | undefined; - - if (typeof window === 'undefined') { - const { Readable: NodeReadable } = await import('stream'); - - Readable = NodeReadable; - } - - for await (const attachment of attachments) { - const file = await this._convertToFile(attachment, mime, Readable); - - if (!(file instanceof File || file instanceof Blob)) { - throw new Error(`Unsupported file type for attachment: ${typeof file}`); - } - - formData.append('file', file, attachment.filename); + for (const attachment of attachments) { + // @ts-expect-error Wrong typings + formData.append('file', attachment.file, attachment.filename); } const config: RequestConfig = { @@ -457,76 +441,4 @@ export class IssueAttachments { return this.client.sendRequest(config, callback); } - - private async _convertToFile( - attachment: Parameters.Attachment, - mime: Mime, - // eslint-disable-next-line @typescript-eslint/consistent-type-imports - Readable?: typeof import('stream').Readable, - ): Promise { - const mimeType = attachment.mimeType ?? (mime.getType(attachment.filename) || undefined); - - if (attachment.file instanceof Blob || attachment.file instanceof File) { - return attachment.file; - } - - if (typeof attachment.file === 'string') { - return new File([attachment.file], attachment.filename, { type: mimeType }); - } - - if (Readable && attachment.file instanceof Readable) { - return this._streamToBlob(attachment.file, attachment.filename, mimeType); - } - - if (attachment.file instanceof ReadableStream) { - return this._streamToBlob(attachment.file, attachment.filename, mimeType); - } - - if (ArrayBuffer.isView(attachment.file) || attachment.file instanceof ArrayBuffer) { - return new File([attachment.file], attachment.filename, { type: mimeType }); - } - - throw new Error('Unsupported attachment file type.'); - } - - private async _streamToBlob( - // eslint-disable-next-line @typescript-eslint/consistent-type-imports - stream: import('stream').Readable | ReadableStream, - filename: string, - mimeType?: string, - ): Promise { - if (typeof window === 'undefined' && stream instanceof (await import('stream')).Readable) { - return new Promise((resolve, reject) => { - const chunks: Uint8Array[] = []; - - stream.on('data', chunk => chunks.push(chunk)); - stream.on('end', () => { - const blob = new Blob(chunks, { type: mimeType }); - - resolve(new File([blob], filename, { type: mimeType })); - }); - stream.on('error', reject); - }); - } - - if (stream instanceof ReadableStream) { - const reader = stream.getReader(); - const chunks: Uint8Array[] = []; - - let done = false; - - while (!done) { - const { value, done: streamDone } = await reader.read(); - - if (value) chunks.push(value); - done = streamDone; - } - - const blob = new Blob(chunks, { type: mimeType }); - - return new File([blob], filename, { type: mimeType }); - } - - throw new Error('Unsupported stream type.'); - } } diff --git a/src/version2/parameters/addAttachment.ts b/src/version2/parameters/addAttachment.ts index 7a0682f58b..415c10df7c 100644 --- a/src/version2/parameters/addAttachment.ts +++ b/src/version2/parameters/addAttachment.ts @@ -39,6 +39,7 @@ export interface Attachment { */ file: Buffer | ReadableStream | Readable | string | Blob | File; + // todo not using? /** * Optional MIME type of the attachment. Example values include: * diff --git a/src/version3/issueAttachments.ts b/src/version3/issueAttachments.ts index 309dcf3061..8f99e18e0d 100644 --- a/src/version3/issueAttachments.ts +++ b/src/version3/issueAttachments.ts @@ -1,5 +1,3 @@ -import type { Mime } from 'mime'; -import mime from 'mime'; import type * as Models from './models'; import type * as Parameters from './parameters'; import type { Client } from '../clients'; @@ -436,23 +434,9 @@ export class IssueAttachments { const formData = new FormData(); const attachments = Array.isArray(parameters.attachment) ? parameters.attachment : [parameters.attachment]; - // eslint-disable-next-line @typescript-eslint/consistent-type-imports - let Readable: typeof import('stream').Readable | undefined; - - if (typeof window === 'undefined') { - const { Readable: NodeReadable } = await import('stream'); - - Readable = NodeReadable; - } - for (const attachment of attachments) { - const file = await this._convertToFile(attachment, mime, Readable); - - if (!(file instanceof File || file instanceof Blob)) { - throw new Error(`Unsupported file type for attachment: ${typeof file}`); - } - - formData.append('file', file, attachment.filename); + // @ts-expect-error Wrong typings + formData.append('file', attachment.file, attachment.filename); } const config: RequestConfig = { @@ -469,76 +453,4 @@ export class IssueAttachments { return this.client.sendRequest(config, callback); } - - private async _convertToFile( - attachment: Parameters.Attachment, - mime: Mime, - // eslint-disable-next-line @typescript-eslint/consistent-type-imports - Readable?: typeof import('stream').Readable, - ): Promise { - const mimeType = attachment.mimeType ?? (mime.getType(attachment.filename) || undefined); - - if (attachment.file instanceof Blob || attachment.file instanceof File) { - return attachment.file; - } - - if (typeof attachment.file === 'string') { - return new File([attachment.file], attachment.filename, { type: mimeType }); - } - - if (Readable && attachment.file instanceof Readable) { - return this._streamToBlob(attachment.file, attachment.filename, mimeType); - } - - if (attachment.file instanceof ReadableStream) { - return this._streamToBlob(attachment.file, attachment.filename, mimeType); - } - - if (ArrayBuffer.isView(attachment.file) || attachment.file instanceof ArrayBuffer) { - return new File([attachment.file], attachment.filename, { type: mimeType }); - } - - throw new Error('Unsupported attachment file type.'); - } - - private async _streamToBlob( - // eslint-disable-next-line @typescript-eslint/consistent-type-imports - stream: import('stream').Readable | ReadableStream, - filename: string, - mimeType?: string, - ): Promise { - if (typeof window === 'undefined' && stream instanceof (await import('stream')).Readable) { - return new Promise((resolve, reject) => { - const chunks: Uint8Array[] = []; - - stream.on('data', chunk => chunks.push(chunk)); - stream.on('end', () => { - const blob = new Blob(chunks, { type: mimeType }); - - resolve(new File([blob], filename, { type: mimeType })); - }); - stream.on('error', reject); - }); - } - - if (stream instanceof ReadableStream) { - const reader = stream.getReader(); - const chunks: Uint8Array[] = []; - - let done = false; - - while (!done) { - const { value, done: streamDone } = await reader.read(); - - if (value) chunks.push(value); - done = streamDone; - } - - const blob = new Blob(chunks, { type: mimeType }); - - return new File([blob], filename, { type: mimeType }); - } - - throw new Error('Unsupported stream type.'); - } } diff --git a/src/version3/parameters/addAttachment.ts b/src/version3/parameters/addAttachment.ts index d30367c879..a82d31ef1f 100644 --- a/src/version3/parameters/addAttachment.ts +++ b/src/version3/parameters/addAttachment.ts @@ -39,6 +39,7 @@ export interface Attachment { */ file: Buffer | ReadableStream | Readable | string | Blob | File; + // todo not using? /** * Optional MIME type of the attachment. Example values include: *