Skip to content

Refactor on the SDK#21

Merged
kin0992 merged 2 commits intomainfrom
refactors/sdk
Sep 27, 2025
Merged

Refactor on the SDK#21
kin0992 merged 2 commits intomainfrom
refactors/sdk

Conversation

@kin0992
Copy link
Copy Markdown
Owner

@kin0992 kin0992 commented Sep 27, 2025

This pull request refactors the gitignoreio-sdk package to improve its API usability, error handling, and code organization. The SDK's generate method now returns a Promise and throws on errors, rather than using the neverthrow Result type. The domain types have been renamed and clarified, and the codebase has been reorganized to separate adapters and domain logic. Tests and documentation have been updated to reflect these changes.

Copilot AI review requested due to automatic review settings September 27, 2025 10:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the GitIgnoreSDK to change from a Result-based async pattern using neverthrow to a standard Promise-based approach with try/catch error handling. The main change converts the generate method from returning a ResultAsync to using async/await with thrown errors.

  • Converted the API from Result-based to Promise-based error handling
  • Reorganized domain interfaces by moving HttpClient to a separate file
  • Updated documentation and tests to reflect the new Promise-based API

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/gitignoreio-sdk/src/gitignore-sdk.ts Updated generate method to use async/await and throw errors instead of returning ResultAsync
packages/gitignoreio-sdk/src/domain/technology.ts Renamed GitIgnoreElement to Technology and added Technologies type definition
packages/gitignoreio-sdk/src/domain/index.ts Removed HttpClient interface and updated GitIgnoreIoSDK to use Promise return type
packages/gitignoreio-sdk/src/domain/http-client.ts New file containing the HttpClient interface moved from index.ts
packages/gitignoreio-sdk/src/adapters/fetch/client.ts Updated import path for HttpClient interface
packages/gitignoreio-sdk/src/tests/gitignore-sdk.test.ts Added test for error handling and updated existing test for Promise-based API
packages/gitignoreio-sdk/src/tests/data.ts Updated import path for HttpClient interface
packages/gitignoreio-sdk/package.json Moved neverthrow dependency and added bugs field
packages/gitignoreio-sdk/README.md Updated documentation to show Promise-based usage with try/catch

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +35 to +43
const result = await this.httpClient.get(url);
return result
.map((content) => ({ content }))
.match(
(value) => value,
(error) => {
throw error;
},
);
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code can be simplified using ResultAsync.unwrapOr() or similar neverthrow utilities instead of manually handling the match pattern. Consider: return { content: await this.httpClient.get(url).unwrapOrElse((error) => { throw error; }) };

Suggested change
const result = await this.httpClient.get(url);
return result
.map((content) => ({ content }))
.match(
(value) => value,
(error) => {
throw error;
},
);
return {
content: await this.httpClient.get(url).unwrapOrElse((error) => { throw error; }),
};

Copilot uses AI. Check for mistakes.
*/
export type Technologies = [Technology, ...Technology[]];

type Technology =
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Technology type should be exported to allow consumers to use it for type checking and validation. Change type Technology = to export type Technology =

Suggested change
type Technology =
export type Technology =

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings September 27, 2025 10:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +41 to +42
() => {
throw new Error('There was an error fetching data from gitignore.io');
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling discards the original error information. The match function receives an error parameter that should be used to provide more meaningful error messages or at least preserve the original error context.

Suggested change
() => {
throw new Error('There was an error fetching data from gitignore.io');
(error) => {
// Preserve original error information
if (error instanceof Error) {
throw new Error(`There was an error fetching data from gitignore.io: ${error.message}`, { cause: error });
} else {
throw new Error(`There was an error fetching data from gitignore.io: ${String(error)}`);
}

Copilot uses AI. Check for mistakes.
@kin0992 kin0992 merged commit 9e5e5b2 into main Sep 27, 2025
1 check passed
@kin0992 kin0992 deleted the refactors/sdk branch September 27, 2025 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants