-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
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 () => { |
There was a problem hiding this comment.
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.
This commit introduces a
--timeout
option to themd-to-notion-cli.ts
script.The timeout is applied when calling the Notion API. The default timeout is 10 seconds (10000ms).
Changes include:
--timeout
option to the commander program definition insrc/md-to-notion-cli.ts
.main
function to accept and parse thetimeout
option.timeoutMs
parameter of the NotionClient
constructor.test/md-to-notion-cli.test.ts
to verify: