Skip to content

feat(chatops-lark): get bot name from api #245

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

Merged
merged 10 commits into from
Mar 5, 2025

Conversation

purelind
Copy link
Contributor

@purelind purelind commented Mar 5, 2025

Get botname directly from the API.

@ti-chi-bot ti-chi-bot bot requested a review from wuhuizuo March 5, 2025 05:55
Copy link

ti-chi-bot bot commented Mar 5, 2025

I have already done a preliminary review for you, and I hope to help you do a better job.

Key Changes:

  1. Added a new feature to retrieve the bot name directly from the API.
  2. Introduced a new package botinfo to handle fetching bot information from the Lark API.
  3. Modified the main.go file to include logic to get the bot name from the API at startup and store it in the config for later use.
  4. Created a new handler in the events/handler/root.go file to handle the retrieved bot name from the config.

Potential Problems:

  1. Error Handling:

    • Error handling in the GetBotName function in botinfo/client.go could be improved. It's recommended to provide more detailed error messages and handle HTTP request errors.
  2. Logging:

    • The logging statements should be consistent and provide clear and informative messages throughout the codebase.

Fixing Suggestions:

  1. Error Handling:

    • Add more descriptive error messages in the GetBotName function to provide better context on what went wrong.
    • Consider handling specific error cases such as network errors, API response errors, and parsing errors separately.
  2. Logging:

    • Ensure that logging messages are consistent and follow a standard format across the codebase.
    • Use structured logging to provide more context in log messages.
  3. Documentation:

    • Add comments to explain the purpose of new functions, structs, and important code blocks.
  4. Testing:

    • Write unit tests to cover the new functionality added in the botinfo package and ensure proper error handling.

Overall, the changes look good, but the mentioned improvements can enhance the code quality and maintainability.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @purelind, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request focuses on enhancing the chatops-lark application by retrieving the bot's name directly from the Lark API, rather than relying solely on the configuration file. This change improves the application's robustness and reduces the need for manual configuration. The primary changes involve adding a new botinfo package to handle API interactions, modifying the main application logic to fetch the bot name at startup, and updating the README to reflect the removal of the bot_name configuration parameter.

Highlights

  • Bot Name Retrieval from API: The application now fetches the bot name from the Lark API using the provided App ID and App Secret.
  • New botinfo Package: A new package pkg/botinfo has been added to encapsulate the logic for interacting with the Lark API to retrieve bot information.
  • Configuration Simplification: The bot_name parameter has been removed from the configuration file, simplifying the setup process.
  • Error Handling: The application now includes error handling for cases where the bot name cannot be retrieved from the API, falling back to the configuration file if available, and exiting if the bot name is not found in either location.

Changelog

Click here to see the changelog
  • chatops-lark/README.md
    • Removed the bot_name parameter from the configuration example in the README.
  • chatops-lark/cmd/server/main.go
    • Imported the new botinfo package.
    • Modified the main function to retrieve the bot name from the Lark API at startup.
    • Added logic to handle cases where the bot name cannot be retrieved from the API, falling back to the configuration file.
    • Ensured that the application exits if the bot name is not found in either the API or the configuration file.
    • Passed the configuration to the event handler.
  • chatops-lark/pkg/botinfo/client.go
    • Created a new package with functions to get the tenant access token and bot information from the Lark API.
    • Implemented the GetBotName function to fetch the bot name from the Lark API.
  • chatops-lark/pkg/events/handler/root.go
    • Modified the NewRootForMessage function to retrieve the bot name directly from the configuration.
    • Removed the initial empty string assignment to botName.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Trivia time!

What is the primary data format used for transmitting data between a web server and a web application, commonly used in APIs?

Click here for the answer
JSON (JavaScript Object Notation) is the primary data format used for transmitting data between a web server and a web application.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ti-chi-bot ti-chi-bot bot added the size/L label Mar 5, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a feature to retrieve the bot name directly from the Lark API, which enhances the application's robustness by reducing reliance on manual configuration. The implementation appears well-structured, with clear error handling and logging. However, there are a few areas that could be improved for better maintainability and clarity.

Summary of Findings

  • Error Handling: The error message "Bot name not found in config and couldn't be retrieved from API" could be more informative to assist in debugging.
  • Config Variable Usage: Consider using a dedicated struct for configuration instead of map[string]any to improve type safety and code clarity.

Merge Readiness

The pull request is almost ready for merging. Addressing the error handling and config variable usage would improve the code quality. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issues should be addressed before merging.

Copy link

ti-chi-bot bot commented Mar 5, 2025

@gemini-code-assist[bot]: changing LGTM is restricted to collaborators

In response to this:

Code Review

This pull request introduces a feature to retrieve the bot name directly from the Lark API, which enhances the application's robustness by reducing reliance on manual configuration. The implementation appears well-structured, with clear error handling and logging. However, there are a few areas that could be improved for better maintainability and clarity.

Summary of Findings

  • Error Handling: The error message "Bot name not found in config and couldn't be retrieved from API" could be more informative to assist in debugging.
  • Config Variable Usage: Consider using a dedicated struct for configuration instead of map[string]any to improve type safety and code clarity.

Merge Readiness

The pull request is almost ready for merging. Addressing the error handling and config variable usage would improve the code quality. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issues should be addressed before merging.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

ti-chi-bot bot commented Mar 5, 2025

I have already done a preliminary review for you, and I hope to help you do a better job.

Summary of Changes:

  1. Removed the bot name from config in the README.md file.
  2. In the main.go file, the bot name is now retrieved from an API at startup.
  3. A new package botinfo has been added which contains the client.go file. This file includes functions that interact with the Lark API and retrieve bot information.
  4. Test cases for the botinfo package have been added in client_test.go.
  5. In the root.go file, the bot name is now retrieved from the config.

Potential Problems:

  1. If the API used to fetch the bot name fails, the application will stop running. This can be a problem if the API is unreliable or slow.
  2. There is no error handling for the case when the bot name is empty in the API response.
  3. There is no fallback mechanism to use a bot name from configuration if the API fails.
  4. Test coverage for errors and edge cases might not be sufficient. For instance, checking if the HTTP request is correct is missing.

Suggestions:

  1. Consider adding a fallback mechanism to use a bot name from the configuration if the API call fails.
  2. Add error handling for the case when the bot name is empty in the API response.
  3. Improve test coverage by adding more edge cases and error scenarios.
  4. Check the correctness of the HTTP request in the test cases.

@ti-chi-bot ti-chi-bot bot added size/XXL and removed size/L labels Mar 5, 2025
Copy link

ti-chi-bot bot commented Mar 5, 2025

I have already done a preliminary review for you, and I hope to help you do a better job.

This pull request introduces a feature to retrieve the bot name directly from the API, instead of hardcoding it in the configuration file. The bot name is used for mentions in group chats.

Key changes made:

  1. Removed the bot_name from the configuration file (README.md).
  2. Updated the main.go file to fetch the bot name using the new GetBotName function at startup, and store it in the configuration for later use.
  3. Added a new botinfo package with a client.go file, which contains functions to interact with the Lark API to get bot info and tenant access token.
  4. Added tests for the new botinfo package (client_test.go).
  5. Updated the root.go file in the events/handler package to use the bot name from the configuration.

Potential problems and suggestions:

  1. Error Handling: There are several places in the code where errors are logged but not returned. This could lead to unexpected behavior. It would be better to return these errors to the caller for proper error handling.
  2. Testing: The tests added cover only the botinfo package. It would be good to add tests for the changes in main.go and root.go.
  3. Dependency Injection: The botinfo package has a dependency on an HTTP client. This client is created inside the package. It would be better to pass this as a dependency to the functions that need it. This would make testing easier and the code more flexible.
  4. Documentation: The PR lacks adequate documentation for the new feature. The description of the PR and the code comments should explain what changes were made, why they were made, and how they affect the existing functionality.
  5. Configuration Change: The PR involves a change to the configuration file. This should be clearly mentioned in the PR description and documentation to alert users to update their configuration files. Also, a migration strategy for existing users should be considered.
  6. Error Messages: The error messages in main.go and root.go could be more descriptive.

Copy link

ti-chi-bot bot commented Mar 5, 2025

I have already done a preliminary review for you, and I hope to help you do a better job.

This pull request introduces the feature of fetching the bot name directly from the API for the chatops-lark project. Here are the key changes:

  1. The bot name is no longer required in the configuration file. The corresponding line in the README has been removed.

  2. In chatops-lark/cmd/server/main.go, the bot name is fetched from the API during startup if it's not already in the config.

  3. A new package botinfo is introduced, containing the logic to fetch the bot name from the Lark API.

  4. A new file client_test.go is added for testing the botinfo package.

  5. In rootHandler of chatops-lark/pkg/events/handler/root.go, a check is added to make sure that the bot name is provided in the config.

Potential problems:

  1. Error handling: In the new code, if fetching the bot name from the API fails, the application will exit with a fatal log message. This means that, in case of a temporary API issue, the application would crash instead of continuing with the existing configuration.

    Suggestion: Consider falling back to the existing configuration (if it exists) when fetching the bot name from the API fails.

  2. Test coverage: While the new botinfo package is covered by tests, the changes in main.go and root.go are not. Specifically, the logic to fetch the bot name from the API in main.go and the check for the bot name in the configuration in root.go are not covered.

    Suggestion: Add tests for these scenarios to ensure that they work as expected and prevent regressions in the future.

  3. Documentation: The README file is updated to remove the bot name from the configuration, but it doesn't mention that the bot name is now fetched from the API.

    Suggestion: Update the README to include this information, so that users understand where the bot name is coming from.

@purelind
Copy link
Contributor Author

purelind commented Mar 5, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new feature to fetch the bot name from the Lark API, which enhances the bot's configuration process. The code is well-structured and includes error handling and logging. However, there are a few areas that could be improved for clarity and robustness.

Summary of Findings

  • Error Handling in main.go: The error handling in main.go could be more informative, especially when failing to retrieve the bot name. Consider providing more context or alternative solutions to the user.
  • Redundant Validation in root.go: The validation of bot_name in root.go seems redundant since main.go already handles this. Consider removing the validation in root.go or providing a more specific error message.
  • Context Timeout: Consider making the context timeout configurable.

Merge Readiness

The pull request is almost ready for merging. Addressing the error handling in main.go and the redundant validation in root.go would improve the code's robustness and clarity. I am unable to approve this pull request, and recommend that others review and approve this code before merging. Given the high severity comment, I recommend that the pull request not be merged until it is addressed.

Copy link

ti-chi-bot bot commented Mar 5, 2025

@gemini-code-assist[bot]: changing LGTM is restricted to collaborators

In response to this:

Code Review

This pull request introduces a new feature to fetch the bot name from the Lark API, which enhances the bot's configuration process. The code is well-structured and includes error handling and logging. However, there are a few areas that could be improved for clarity and robustness.

Summary of Findings

  • Error Handling in main.go: The error handling in main.go could be more informative, especially when failing to retrieve the bot name. Consider providing more context or alternative solutions to the user.
  • Redundant Validation in root.go: The validation of bot_name in root.go seems redundant since main.go already handles this. Consider removing the validation in root.go or providing a more specific error message.
  • Context Timeout: Consider making the context timeout configurable.

Merge Readiness

The pull request is almost ready for merging. Addressing the error handling in main.go and the redundant validation in root.go would improve the code's robustness and clarity. I am unable to approve this pull request, and recommend that others review and approve this code before merging. Given the high severity comment, I recommend that the pull request not be merged until it is addressed.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link

ti-chi-bot bot commented Mar 5, 2025

I have already done a preliminary review for you, and I hope to help you do a better job.

The key changes in this pull request are:

  1. Removal of bot name from Readme file as it is now fetched from API.
  2. Introduced a new function to fetch the bot name from API during startup if it's not already in the config.
  3. If the bot name is not available in the config and also couldn't be fetched from the API, the program will terminate with a fatal log.
  4. A new pkg botinfo is created which contains functions to make API requests to fetch bot info.
  5. Unit tests have been added for the new functions in the botinfo package.

Potential problems:

  1. The main check of the bot name being in the config or being able to be fetched from the API happens at startup. If not, a fatal log and the program is terminated. This could be a problem if for some reason, the API is temporarily down or there's a network issue. The whole system would be down in such a case.
  2. There's no retry logic in case the bot name is not fetched from the API. It tries once and if it fails, the program will terminate.

Fixing suggestions:

  1. Instead of terminating the whole program if the bot name can't be fetched, you could add a retry mechanism to reattempt fetching the bot name. This would be helpful in case of temporary network issues.
  2. Also, add proper error handling and logs to identify issues faster.

Copy link

ti-chi-bot bot commented Mar 5, 2025

I have already done a preliminary review for you, and I hope to help you do a better job.

Key Changes:

  1. The bot name is no longer hardcoded and is now retrieved directly from the API. This is done by calling the botinfo.GetBotName function in main.go.
  2. A new botinfo package has been introduced that contains functionality to interact with the bot API and retrieve information.
  3. Tests have been added for the new botinfo package.
  4. The bot name is no longer required in the config file, and an error message will be logged if it is not found.

Potential Problems:

  1. There is no checking for the existence of the appID and appSecret variables before calling the botinfo.GetBotName function in main.go. If these variables are not provided, the function call will fail.
  2. There are no tests for the changes in main.go.
  3. There are no checks to ensure that the bot name retrieved from the API is valid.
  4. There's no handling for API rate limiting or connection problems in the botinfo package.

Suggestions:

  1. Add checks in main.go to ensure that appID and appSecret exist before calling botinfo.GetBotName.
  2. Add tests for the changes in main.go.
  3. Add checks in the botinfo package to ensure that the bot name retrieved from the API is valid.
  4. Add error handling and retry logic for API rate limiting or connection problems in the botinfo package.

Copy link

ti-chi-bot bot commented Mar 5, 2025

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot merged commit f4cea34 into main Mar 5, 2025
6 checks passed
@ti-chi-bot ti-chi-bot bot deleted the purelind/get-botname-from-api branch March 5, 2025 06:52
ti-chi-bot bot pushed a commit to PingCAP-QE/ee-ops that referenced this pull request Mar 5, 2025
…g to v2025.1.30-19-gf4cea34 (#1431)

This PR contains the following updates:

REF   PingCAP-QE/ee-apps#245 

| Package | Update | Change |
|---|---|---|
|
[ghcr.io/pingcap-qe/ee-apps/chatops-lark](https://redirect.github.com/PingCAP-QE/ee-apps)
| patch | `v2025.1.30-11-g3b74562` -> `v2025.1.30-19-gf4cea34` |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/PingCAP-QE/ee-ops).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xNzYuMiIsInVwZGF0ZWRJblZlciI6IjM5LjE3Ni4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Purelind <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant