Skip to content

style: update style for mcp server#8338

Merged
f2c-ci-robot[bot] merged 1 commit intodevfrom
pr@dev@mcp
Apr 7, 2025
Merged

style: update style for mcp server#8338
f2c-ci-robot[bot] merged 1 commit intodevfrom
pr@dev@mcp

Conversation

@zhengkunwang223
Copy link
Copy Markdown
Member

No description provided.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 7, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

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/test-infra repository.

mcpServer.value.baseUrl = mcpServer.value.protocol + mcpServer.value.url;
if (mode.value == 'create') {
await createMcpServer(mcpServer.value);
MsgSuccess(i18n.global.t('commons.msg.createSuccess'));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are two main changes:

  1. Protocol Prepend: In the previous version, there was no protocol being prepended to baseUrl. Now, it is mandatory by adding protocol and url fields in state object.

  2. Connection URL Handling: After fetching connection URL from API (getMcpDomain()), the old approach of setting baseUrl directly with res.data.connUrl has changed. New URLs will now also have their protocols extracted (either "http//" or "https//") and assigned separately to protocol and url, before assigning them back to baseUrl.

Additionally, this might be affecting form validation rules as well, so you'd need review those too to ensure they account for these new properties.

return res, nil
}
res.WebsiteID = website.ID
res.Domain = website.PrimaryDomain
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The changes made in this code snippet seem appropriate since returning nil instead of an error indicates that there was no issue fetching the website record with the provided ID. However, for better readability and maintainability, it's good practice to log errors if they occur. Here's an optimized version:

func (m McpServerService) GetBindDomain() (response.McpBindDomainRes, error) {
	var res response.McpBindDomainRes

	websiteRepo := &WebsiteRepository{}
	err := websiteRepo.GetFirst(commonRepo.WithByID(websiteID), &res)
	if err != nil {
		log.Errorf("Failed to fetch website with ID %d: %v", websiteID, err)
		return res, err // Keeping original return pattern for clarity
	}

	res.WebsiteID = website.ID
	res.Domain = website.PrimaryDomain

	return res, nil
}

This code includes logging when an error occurs using a package like log. Additionally, I've used type assertions in the repository call (&res) for explicitness, which might not be necessary in simpler contexts but can enhance clarity.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 7, 2025

_ = settingRepo.Update("MCP_WEBSITE_ID", "0")
}
tx.Commit()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code has an issue where the parameter req.ID is compared to variable websiteID, which seems incorrect. Typically, you should compare them if they refer to different objects or IDs. However, given the context of the function name and usage, it might be intended to delete the website identified by req.ID. If so, ensure that websiteID is correctly set to match the value of req.ID.

Additionally, there's unnecessary use of _ before settingRepo.UpdateOrCreate("MCP_WEBSITE_ID", "0"). Removing this underscore would make the code cleaner.

Here’s a revised version with these adjustments:

@@ -498,7 +498,11 @@ func (w WebsiteService) DeleteWebsite(req request.WebsiteDelete) error {
 	}
 	websiteID := GetWebsiteID()
 	if req.ID == websiteID {
-		_ = settingRepo.UpdateOrCreate("MCP_WEBSITE_ID", "0")
+		err := settingRepo.Update("MCP_WEBSITE_ID", "0")
+		if err != nil {
+			return err // Handle the error appropriately
+		}
 	}
 	tx.Commit()
 

Make sure to handle any potential errors from the Update method appropriately based on your application's requirements.

Copy link
Copy Markdown
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

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

/lgtm

@wanghe-fit2cloud
Copy link
Copy Markdown
Member

/approve

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 7, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wanghe-fit2cloud

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

The pull request process is described here

Details 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

@f2c-ci-robot f2c-ci-robot Bot added the approved label Apr 7, 2025
@f2c-ci-robot f2c-ci-robot Bot merged commit 097a33c into dev Apr 7, 2025
6 checks passed
@f2c-ci-robot f2c-ci-robot Bot deleted the pr@dev@mcp branch April 7, 2025 11:09
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.

3 participants