Skip to content
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

refactor: use handlers for oras blob push command #1618

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

wangxiaoxuan273
Copy link
Contributor

@wangxiaoxuan273 wangxiaoxuan273 commented Feb 10, 2025

What this PR does / why we need it:

The oras blob push on the main branch has several problems.

  1. It uses Printer.Println for status and metadata output, instead of handlers.
  2. When pushing a blob that already exists, tty tracking is not used.
  3. When --descriptor is used, status output is still shown but nothing should be printed except the descriptor.

This PR fixes all the above issues and refactors the code to use status, metadata and content handlers.

Current display:
image

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Part of #1542

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

Xiaoxuan Wang added 4 commits December 5, 2024 13:44
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Copy link

codecov bot commented Feb 10, 2025

Codecov Report

Attention: Patch coverage is 83.00000% with 17 lines in your changes missing coverage. Please review.

Project coverage is 84.36%. Comparing base (724f56b) to head (6e06bd4).

Files with missing lines Patch % Lines
cmd/oras/root/blob/push.go 73.91% 3 Missing and 3 partials ⚠️
cmd/oras/internal/display/status/tty.go 75.00% 4 Missing and 1 partial ⚠️
cmd/oras/internal/display/content/blob_push.go 72.72% 2 Missing and 1 partial ⚠️
cmd/oras/internal/display/handler.go 62.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1618      +/-   ##
==========================================
+ Coverage   84.33%   84.36%   +0.02%     
==========================================
  Files         120      122       +2     
  Lines        5464     5532      +68     
==========================================
+ Hits         4608     4667      +59     
- Misses        608      614       +6     
- Partials      248      251       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Xiaoxuan Wang and others added 9 commits February 10, 2025 16:04
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
@wangxiaoxuan273 wangxiaoxuan273 marked this pull request as ready for review February 17, 2025 06:47
@wangxiaoxuan273 wangxiaoxuan273 changed the title [WIP] refactor: use handlers for oras blob push command refactor: use handlers for oras blob push command Feb 17, 2025
cmd/oras/root/blob/push.go Show resolved Hide resolved
cmd/oras/internal/display/status/text.go Outdated Show resolved Hide resolved
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Copy link
Member

@Wwwsylvia Wwwsylvia left a comment

Choose a reason for hiding this comment

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

LGTM

// BlobPushHandler handles descriptor output for blob push events.
type BlobPushHandler interface {
// OnBlobPushed is called after a blob is pushed.
OnBlobPushed() error
Copy link
Contributor

Choose a reason for hiding this comment

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

by logic, it should be

Suggested change
OnBlobPushed() error
OnBlobPushed(desc ocispec.Descriptor) error

return err
}

if err := metadataHandler.OnBlobPushed(opts.AnnotatedReference()); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

AnnotatedReference() itself is text output.

@@ -31,5 +31,11 @@ type ManifestIndexCreateHandler interface {
OnContentCreated(content []byte) error
}

// BlobPushHandler handles descriptor output for blob push events.
type BlobPushHandler interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is --descriptor considered as metadata output?

@shizhMSFT
Copy link
Contributor

Since #1524 does major refactoring on the status output, let's wait #1524 to be merged first.

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.

3 participants