Skip to content

feat: Add --timeout option to CLI #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sh1nj1
Copy link
Member

@sh1nj1 sh1nj1 commented May 20, 2025

This commit introduces a --timeout option to the md-to-notion-cli.ts script.

The timeout is applied when calling the Notion API. The default timeout is 10 seconds (10000ms).

Changes include:

  • Added a --timeout option to the commander program definition in src/md-to-notion-cli.ts.
  • Updated the main function to accept and parse the timeout option.
  • Passed the parsed timeout value to the timeoutMs parameter of the Notion Client constructor.
  • Added unit tests in test/md-to-notion-cli.test.ts to verify:
    • Default timeout is applied.
    • Custom timeout values are correctly passed.
    • Timeout value is parsed as an integer.
  • Manually tested the CLI with various timeout values to confirm expected behavior, including successful calls (with invalid token) and timeout errors with very short timeout values.

This commit introduces a `--timeout` option to the `md-to-notion-cli.ts` script.

The timeout is applied when calling the Notion API.
The default timeout is 10 seconds (10000ms).

Changes include:
- Added a `--timeout` option to the commander program definition in `src/md-to-notion-cli.ts`.
- Updated the `main` function to accept and parse the `timeout` option.
- Passed the parsed timeout value to the `timeoutMs` parameter of the Notion `Client` constructor.
- Added unit tests in `test/md-to-notion-cli.test.ts` to verify:
    - Default timeout is applied.
    - Custom timeout values are correctly passed.
    - Timeout value is parsed as an integer.
- Manually tested the CLI with various timeout values to confirm expected behavior, including successful calls (with invalid token) and timeout errors with very short timeout values.
@sh1nj1 sh1nj1 requested a review from Copilot May 20, 2025 03:18
Copy link

@Copilot 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 pull request adds a new --timeout option to the CLI tool for controlling the API call timeout behavior. Key changes include updating the CLI's options and main function in src/md-to-notion-cli.ts, comprehensive unit tests in test/md-to-notion-cli.test.ts to ensure proper behavior, and a manual test markdown file for additional verification.

Reviewed Changes

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

File Description
test/md-to-notion-cli.test.ts Added tests to verify default, custom, and integer parsing behavior for the timeout.
temp_md_files_manual_test/test.md Added a simple markdown file to facilitate manual testing of the timeout functionality.
src/md-to-notion-cli.ts Updated the CLI option and main function to support the new --timeout parameter.

@@ -57,7 +58,8 @@ async function main(
}

if (dir) {
const notion = new Client({ auth: options.token })
const timeoutMs = parseInt(String(options.timeout), 10)
Copy link
Preview

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

Consider adding validation to check if the result of parseInt is NaN and handle it appropriately, such as reverting to the default timeout or throwing a clear error.

Suggested change
const timeoutMs = parseInt(String(options.timeout), 10)
let timeoutMs = parseInt(String(options.timeout), 10)
if (isNaN(timeoutMs)) {
timeoutMs = 30000 // Default timeout value in milliseconds
}

Copilot uses AI. Check for mistakes.

})
})

it("should parse timeout as an integer", async () => {
Copy link
Preview

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

Consider documenting that the timeout value is truncated to an integer when a non-integer input is provided, to clarify the behavior for future maintainers and users.

Copilot uses AI. Check for mistakes.

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.

1 participant