Skip to content

refactor(tibuild-v2): refactor API paths and improve endpoint structure #247

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 3 commits into from
Mar 14, 2025

Conversation

wuhuizuo
Copy link
Contributor

No description provided.

Copy link

ti-chi-bot bot commented Mar 13, 2025

I Skip it since the diff size(822294 bytes > 80000 bytes) is too large

@ti-chi-bot ti-chi-bot bot requested a review from purelind March 13, 2025 11:54
@ti-chi-bot ti-chi-bot bot added the size/XXL label Mar 13, 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.

Hello @wuhuizuo, 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 refactoring the API paths and improving the endpoint structure for the tibuild-v2 service. The primary goal is to introduce a consistent /api/v2 prefix for all API endpoints and to streamline the structure of the artifact and devbuild services. This involves modifying the design file, client-side code, server-side code, and CLI configurations to reflect the new API structure.

Highlights

  • API Path Refactoring: Introduced the /api/v2 prefix for all API paths to maintain consistency across the API.
  • Service Endpoint Restructuring: Refactored the artifact and devbuild service endpoints to align with the new API path structure, including changes to request/response encoding/decoding and path definitions.
  • Payload Simplification: Simplified the SyncImage payload by removing the nested ImageSyncRequest and directly using ImageSyncRequest as the payload.
  • CLI Tool Updates: Updated the CLI tool to reflect the changes in API paths and payload structures, ensuring that the CLI commands are compatible with the refactored API.
  • List Devbuild Pagination: Refactor List devbuild to support pagination, including page number, page size, sort and direction.

Changelog

Click here to see the changelog
  • experiments/tibuild-v2/design/design.go
    • Added /api/v2 prefix to all API paths.
    • Added /artifact path to the artifact service.
    • Added /devbuilds path to the devbuild service.
    • Modified the syncImage endpoint to use ImageSyncRequest directly as the payload.
    • Updated the devbuild service methods (list, create, get, update, rerun) to use relative paths within the /devbuilds path.
    • Added pageSize attribute to the List method payload.
  • experiments/tibuild-v2/gen/artifact/client.go
    • Modified the SyncImage function to accept ImageSyncRequest directly as the payload.
  • experiments/tibuild-v2/gen/artifact/endpoints.go
    • Updated the NewSyncImageEndpoint function to use ImageSyncRequest as the request type.
  • experiments/tibuild-v2/gen/artifact/service.go
    • Updated the SyncImage method signature to use ImageSyncRequest as the payload type.
    • Removed the SyncImagePayload type.
    • Moved ImageSyncRequest to be the payload type of the artifact service syncImage method.
  • experiments/tibuild-v2/gen/devbuild/service.go
    • Updated the List method description to include pagination support.
    • Added PerPage, Sort, Direction, PageSize attributes to the ListPayload type.
  • experiments/tibuild-v2/gen/http/artifact/client/cli.go
    • Modified the BuildSyncImagePayload function to construct ImageSyncRequest directly from the request body.
    • Updated the example JSON in the error message to reflect the new payload structure.
  • experiments/tibuild-v2/gen/http/artifact/client/encode_decode.go
    • Updated the EncodeSyncImageRequest function to use ImageSyncRequest as the payload type.
    • Removed the marshalArtifactImageSyncRequestToImageSyncRequestRequestBody and marshalImageSyncRequestRequestBodyToArtifactImageSyncRequest functions.
  • experiments/tibuild-v2/gen/http/artifact/client/paths.go
    • Updated the SyncImageArtifactPath function to include the /api/v2 prefix.
  • experiments/tibuild-v2/gen/http/artifact/client/types.go
    • Modified the SyncImageRequestBody type to include Source and Target directly.
    • Removed the ImageSyncRequestRequestBody type.
    • Updated the NewSyncImageRequestBody function to construct the request body directly from ImageSyncRequest.
  • experiments/tibuild-v2/gen/http/artifact/server/encode_decode.go
    • Updated the DecodeSyncImageRequest function to construct ImageSyncRequest directly from the request body.
    • Removed the unmarshalImageSyncRequestRequestBodyToArtifactImageSyncRequest function.
  • experiments/tibuild-v2/gen/http/artifact/server/paths.go
    • Updated the SyncImageArtifactPath function to include the /api/v2 prefix.
  • experiments/tibuild-v2/gen/http/artifact/server/server.go
    • Updated the mount paths for the SyncImage handler to include the /api/v2 prefix.
  • experiments/tibuild-v2/gen/http/artifact/server/types.go
    • Modified the SyncImageRequestBody type to include Source and Target directly.
    • Removed the ImageSyncRequestRequestBody type.
    • Updated the NewSyncImageResponseBody function to construct the response body directly from ImageSyncRequest.
    • Updated the NewSyncImageImageSyncRequest function to construct the payload directly from the request body.
    • Updated the ValidateSyncImageRequestBody function to validate Source and Target directly.
  • experiments/tibuild-v2/gen/http/cli/tibuild/cli.go
    • Updated the example JSON in the artifact sync-image command usage to reflect the new payload structure.
    • Updated the devbuild list command usage to include pagination parameters.
    • Updated the example JSON in the devbuild create command usage.
    • Updated the example JSON in the devbuild update command usage.
  • experiments/tibuild-v2/gen/http/devbuild/client/cli.go
    • Modified the BuildListPayload function to construct the payload from the request body and query parameters.
    • Updated the BuildCreatePayload function to construct the payload from the request body.
    • Updated the BuildUpdatePayload function to construct the payload from the request body.
  • experiments/tibuild-v2/gen/http/devbuild/client/encode_decode.go
    • Updated the EncodeListRequest function to include pagination parameters in the query string.
    • Updated the EncodeListRequest function to encode the request body.
  • experiments/tibuild-v2/gen/http/devbuild/client/paths.go
    • Updated the paths for all devbuild service endpoints to include the /api/v2 prefix.
  • experiments/tibuild-v2/gen/http/devbuild/client/types.go
    • Added ListRequestBody type.
    • Updated the NewListRequestBody function to construct the request body.
  • experiments/tibuild-v2/gen/http/devbuild/server/encode_decode.go
    • Updated the DecodeListRequest function to decode the request body and query parameters.
    • Updated the NewListPayload function to construct the payload from the request body and query parameters.
  • experiments/tibuild-v2/gen/http/devbuild/server/paths.go
    • Updated the paths for all devbuild service endpoints to include the /api/v2 prefix.
  • experiments/tibuild-v2/gen/http/devbuild/server/server.go
    • Updated the mount paths for all devbuild service handlers to include the /api/v2 prefix.
  • experiments/tibuild-v2/gen/http/devbuild/server/types.go
    • Added ListRequestBody type.
    • Updated the NewListPayload function to construct the payload from the request body and query parameters.
    • Added ValidateListRequestBody function.
  • experiments/tibuild-v2/gen/http/openapi.json
    • Updated the OpenAPI specification to reflect the changes in API paths and payload structures.
  • experiments/tibuild-v2/pkg/impl/artifact.go
    • Updated the SyncImage method signature to use ImageSyncRequest as the payload type.
  • experiments/tibuild-v2/pkg/impl/devbuild.go
    • Updated the List method description to include pagination support.
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.


In the realm of APIs, a path we tread,
Refactoring endpoints, a task ahead.
With prefixes and structures, we bring order and grace,
Ensuring consistency in every space.

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.

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

The pull request refactors the API paths and improves the endpoint structure, enhancing the overall organization and maintainability of the API. The changes are well-structured and address the intended improvements effectively.

Summary of Findings

  • API Path Structure: The API paths have been refactored to include a version prefix and improve endpoint structure. This change aims to provide better organization and maintainability for the API.
  • Payload Structure for syncImage: The payload structure for the syncImage method has been simplified by directly using ImageSyncRequest instead of wrapping it in SyncImagePayload. This reduces unnecessary nesting and improves code clarity.
  • List Payload Parameters: The parameters for the List method have been updated to support pagination and sorting, providing more flexibility in retrieving devbuilds.

Merge Readiness

The code changes are well-structured and address the intended improvements effectively. I would recommend addressing the high severity issue before merging. I am unable to directly approve the pull request, and users should have others review and approve this code before merging.

Comment on lines 25 to 26
return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "'{\n \"source\": \"Culpa possimus.\",\n \"target\": \"Perferendis nisi non quia debitis.\"\n }'")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The error message example still contains ImageSyncRequest which is no longer part of the request body. This should be updated to reflect the new structure.

Style Guide References

Suggested change
return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "'{\n \"source\": \"Culpa possimus.\",\n \"target\": \"Perferendis nisi non quia debitis.\"\n }'")
}
return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "'{\n \"source\": \"Culpa possimus.\",\n \"target\": \"Perferendis nisi non quia debitis.\"\n }'")

Comment on lines 40 to +41
Description("Sync hotfix image to dockerhub")
Payload(func() {
Attribute("ImageSyncRequest", ImageSyncRequest, "Image sync to public, only hotfix is accepted right now")
Required("ImageSyncRequest")
})
Payload(ImageSyncRequest)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a comment explaining why the payload is directly ImageSyncRequest instead of ImageSyncRequest within a payload attribute. This can improve readability and understanding for future developers.

Style Guide References

Suggested change
Description("Sync hotfix image to dockerhub")
Payload(func() {
Attribute("ImageSyncRequest", ImageSyncRequest, "Image sync to public, only hotfix is accepted right now")
Required("ImageSyncRequest")
})
Payload(ImageSyncRequest)
// Payload(ImageSyncRequest) - Image sync to public, only hotfix is accepted right now
Payload(ImageSyncRequest)

Comment on lines 33 to 37
return os.Args[0] + ` artifact sync-image --body '{
"ImageSyncRequest": {
"source": "Culpa possimus.",
"target": "Perferendis nisi non quia debitis."
}
"source": "Culpa possimus.",
"target": "Perferendis nisi non quia debitis."
}'` + "\n" +
os.Args[0] + ` devbuild list --size 9048917590767144830 --offset 2393528839850969203 --hotfix false --created-by "Fugiat voluptatibus quia."` + "\n" +
os.Args[0] + ` devbuild list --body '{
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The example should be updated to reflect the new payload structure for artifact sync-image.

Style Guide References

Suggested change
return os.Args[0] + ` artifact sync-image --body '{
"ImageSyncRequest": {
"source": "Culpa possimus.",
"target": "Perferendis nisi non quia debitis."
}
"source": "Culpa possimus.",
"target": "Perferendis nisi non quia debitis."
}'` + "\n" +
os.Args[0] + ` devbuild list --size 9048917590767144830 --offset 2393528839850969203 --hotfix false --created-by "Fugiat voluptatibus quia."` + "\n" +
os.Args[0] + ` devbuild list --body '{
return os.Args[0] + ` artifact sync-image --body '{
"source": "Culpa possimus.",
"target": "Perferendis nisi non quia debitis."
}'` + "\n" +

Comment on lines 231 to 233
%[1]s artifact sync-image --body '{
"ImageSyncRequest": {
"source": "Culpa possimus.",
"target": "Perferendis nisi non quia debitis."
}
"source": "Culpa possimus.",
"target": "Perferendis nisi non quia debitis."
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The example should be updated to reflect the new payload structure for artifact sync-image.

Style Guide References

Suggested change
%[1]s artifact sync-image --body '{
"ImageSyncRequest": {
"source": "Culpa possimus.",
"target": "Perferendis nisi non quia debitis."
}
"source": "Culpa possimus.",
"target": "Perferendis nisi non quia debitis."
%[1]s artifact sync-image --body '{
"source": "Culpa possimus.",
"target": "Perferendis nisi non quia debitis."
}'

Comment on lines 25 to 27
err = json.Unmarshal([]byte(devbuildListBody), &body)
if err != nil {
return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "'{\n \"direction\": \"desc\",\n \"per_page\": 9048917590767144830,\n \"sort\": \"updatedAt\"\n }'")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The error message example should be updated to reflect the new structure for the list payload.

Style Guide References

Suggested change
err = json.Unmarshal([]byte(devbuildListBody), &body)
if err != nil {
return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "'{\n \"direction\": \"desc\",\n \"per_page\": 9048917590767144830,\n \"sort\": \"updatedAt\"\n }'")
return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "'{\n \"direction\": \"desc\",\n \"per_page\": 9048917590767144830,\n \"sort\": \"updatedAt\"\n }'")

Comment on lines 713 to 722
if body.Sort != nil {
if !(*body.Sort == "createdAt" || *body.Sort == "updatedAt") {
err = goa.MergeErrors(err, goa.InvalidEnumValueError("body.sort", *body.Sort, []any{"createdAt", "updatedAt"}))
}
}
if body.Direction != nil {
if !(*body.Direction == "asc" || *body.Direction == "desc") {
err = goa.MergeErrors(err, goa.InvalidEnumValueError("body.direction", *body.Direction, []any{"asc", "desc"}))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding comments to explain the purpose and validation logic for the Sort and Direction fields.

// ValidateListRequestBody runs the validations defined on ListRequestBody
func ValidateListRequestBody(body *ListRequestBody) (err error) {
	// Validate Sort field
	if body.Sort != nil {
		if !(*body.Sort == "createdAt" || *body.Sort == "updatedAt") {
			err = goa.MergeErrors(err, goa.InvalidEnumValueError("body.sort", *body.Sort, []any{"createdAt", "updatedAt"}))
		}
	}
	// Validate Direction field
	if body.Direction != nil {
		if !(*body.Direction == "asc" || *body.Direction == "desc") {
			err = goa.MergeErrors(err, goa.InvalidEnumValueError("body.direction", *body.Direction, []any{"asc", "desc"}))
		}
	}
	return
}

Style Guide References

Copy link

ti-chi-bot bot commented Mar 13, 2025

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

In response to this:

Code Review

The pull request refactors the API paths and improves the endpoint structure, enhancing the overall organization and maintainability of the API. The changes are well-structured and address the intended improvements effectively.

Summary of Findings

  • API Path Structure: The API paths have been refactored to include a version prefix and improve endpoint structure. This change aims to provide better organization and maintainability for the API.
  • Payload Structure for syncImage: The payload structure for the syncImage method has been simplified by directly using ImageSyncRequest instead of wrapping it in SyncImagePayload. This reduces unnecessary nesting and improves code clarity.
  • List Payload Parameters: The parameters for the List method have been updated to support pagination and sorting, providing more flexibility in retrieving devbuilds.

Merge Readiness

The code changes are well-structured and address the intended improvements effectively. I would recommend addressing the high severity issue before merging. I am unable to directly approve the pull request, and users should have others review and approve this code 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 13, 2025

I Skip it since the diff size(834406 bytes > 80000 bytes) is too large

@wuhuizuo wuhuizuo force-pushed the feature/tibuild-v2 branch from 7ed6abe to 394059f Compare March 13, 2025 13:05
Copy link

ti-chi-bot bot commented Mar 13, 2025

I Skip it since the diff size(836825 bytes > 80000 bytes) is too large

@wuhuizuo
Copy link
Contributor Author

/wip

I want to make the sync-image api be a async mode.

Copy link

ti-chi-bot bot commented Mar 14, 2025

I Skip it since the diff size(1514241 bytes > 80000 bytes) is too large

@wuhuizuo
Copy link
Contributor Author

/approve

Copy link

ti-chi-bot bot commented Mar 14, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wuhuizuo

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 added the approved label Mar 14, 2025
@ti-chi-bot ti-chi-bot bot merged commit 711bf7b into main Mar 14, 2025
7 checks passed
@ti-chi-bot ti-chi-bot bot deleted the feature/tibuild-v2 branch March 14, 2025 18:15
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