Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@chlins
Copy link
Member

@chlins chlins commented May 15, 2025

This pull request introduces several changes aimed at improving code readability, simplifying logic, and leveraging Go's standard library for better performance and maintainability. The most significant updates include replacing manual loops with range syntax or utility functions like slices.Contains and maps.Copy, as well as removing unused code. Below is a categorized summary of the most important changes:

Refactoring Loops for Simplification

  • Replaced traditional for loops with range syntax in multiple functions to simplify iteration logic. Examples include TestMaxOpenConns in pgsql_test.go, ArrayEqual in testutils.go, and GenerateRandomStringWithLen in utils.go. [1] [2] [3]

Leveraging Standard Library Functions

  • Replaced custom logic for checking membership in slices with slices.Contains in functions like skippedUnusedJobType in monitor.go and hasCapability in checker.go. [1] [2]
  • Used maps.Copy to simplify map copying in functions like Decode in codec.go and Build in context.go. [1] [2]

Code Cleanup

  • Removed unused function StringInSlice from utils.go to reduce clutter and improve maintainability.

Bug Fixes and Logic Adjustments

  • Adjusted loop logic in copyBlobByChunk in transfer.go to use a single expression for calculating the end range, improving clarity and reducing potential off-by-one errors.

Dependency Updates

  • Added imports for slices and maps packages in various files to enable the use of utility functions for slices and maps. [1] [2] [3]

These changes collectively enhance the codebase by improving readability, reducing redundancy, and leveraging modern Go practices.Thank you for contributing to Harbor!

Comprehensive Summary of your change

Issue being fixed

Fixes #(issue)

Please indicate you've done the following:

  • Well Written Title and Summary of the PR
  • Label the PR as needed. "release-note/ignore-for-release, release-note/new-feature, release-note/update, release-note/enhancement, release-note/community, release-note/breaking-change, release-note/docs, release-note/infra, release-note/deprecation"
  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Made sure tests are passing and test coverage is added if needed.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed in website repository.

@chlins chlins requested a review from a team as a code owner May 15, 2025 08:25
@chlins chlins added the release-note/update Update or Fix label May 15, 2025
@codecov
Copy link

codecov bot commented May 15, 2025

Codecov Report

Attention: Patch coverage is 79.78723% with 19 lines in your changes missing coverage. Please review.

Project coverage is 65.87%. Comparing base (c8c11b4) to head (f7c929b).
Report is 493 commits behind head on main.

Files with missing lines Patch % Lines
src/pkg/scan/rest/v1/models.go 50.00% 5 Missing ⚠️
src/pkg/reg/adapter/googlegcr/adapter.go 0.00% 2 Missing ⚠️
src/pkg/scan/dao/scanner/model.go 71.42% 2 Missing ⚠️
src/server/v2.0/handler/project.go 0.00% 2 Missing ⚠️
src/common/dao/testutils.go 0.00% 1 Missing ⚠️
.../controller/replication/transfer/image/transfer.go 0.00% 1 Missing ⚠️
src/core/auth/ldap/ldap.go 0.00% 1 Missing ⚠️
src/core/session/codec.go 50.00% 1 Missing ⚠️
src/jobservice/job/impl/context.go 66.66% 1 Missing ⚠️
src/jobservice/job/impl/default_context.go 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main   #21998       +/-   ##
===========================================
+ Coverage   45.36%   65.87%   +20.50%     
===========================================
  Files         244     1071      +827     
  Lines       13333   115703   +102370     
  Branches     2719     2925      +206     
===========================================
+ Hits         6049    76215    +70166     
- Misses       6983    35264    +28281     
- Partials      301     4224     +3923     
Flag Coverage Δ
unittests 65.87% <79.78%> (+20.50%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/common/utils/utils.go 81.81% <100.00%> (ø)
src/controller/artifact/annotation/v1alpha1.go 65.45% <100.00%> (ø)
src/controller/config/controller.go 30.40% <100.00%> (ø)
src/controller/event/handler/webhook/scan/scan.go 51.00% <100.00%> (ø)
src/controller/health/controller.go 83.72% <100.00%> (ø)
src/controller/jobmonitor/monitor.go 25.54% <100.00%> (ø)
src/controller/proxy/manifestcache.go 38.81% <100.00%> (ø)
src/controller/scan/checker.go 54.41% <100.00%> (ø)
src/controller/scanner/base_controller.go 37.06% <100.00%> (ø)
src/jobservice/job/impl/gc/garbage_collection.go 45.59% <100.00%> (ø)
... and 40 more

... and 935 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@wy65701436 wy65701436 left a comment

Choose a reason for hiding this comment

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

lgtm

@chlins
Copy link
Member Author

chlins commented May 29, 2025

@stonezdj Please help to review this change, thanks.

@chlins chlins force-pushed the refactor/modern branch from 6505285 to f7c929b Compare June 18, 2025 09:45
@chlins chlins enabled auto-merge (squash) June 18, 2025 09:54
@chlins chlins merged commit 59c3de1 into goharbor:main Jun 18, 2025
12 checks passed
OrlinVasilev pushed a commit to OrlinVasilev/harbor that referenced this pull request Oct 29, 2025
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.

6 participants