Skip to content

fix: require valid project ID for project labels creation#641

Merged
bupd merged 3 commits into
goharbor:mainfrom
Sypher845:fix/validate-project-id-for-scope-p
Mar 3, 2026
Merged

fix: require valid project ID for project labels creation#641
bupd merged 3 commits into
goharbor:mainfrom
Sypher845:fix/validate-project-id-for-scope-p

Conversation

@Sypher845

Copy link
Copy Markdown
Contributor

Fixes #640

This pull request improves the label creation command in the Harbor CLI by enhancing error handling and adding validation for project-specific labels. The main changes focus on making the command more robust and user-friendly.

Validation for project-specific labels:

  • Added a check to ensure that when the label scope is set to project ('p'), a valid ProjectID must be provided. If not, a clear error message is returned.

Result
Screenshot from 2026-01-24 03-00-43

  • Added a check to verify that the specified project exists before creating a project-specific label, returning an error if the project does not exist.

Result
Screenshot from 2026-01-24 03-01-49

@codecov

codecov Bot commented Jan 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.44444% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 7.45%. Comparing base (60ad0bd) to head (abf70f6).
⚠️ Report is 105 commits behind head on main.

Files with missing lines Patch % Lines
cmd/harbor/root/labels/create.go 44.44% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #641      +/-   ##
=========================================
- Coverage   10.99%   7.45%   -3.54%     
=========================================
  Files         173     261      +88     
  Lines        8671   12930    +4259     
=========================================
+ Hits          953     964      +11     
- Misses       7612   11857    +4245     
- Partials      106     109       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bupd bupd left a comment

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.

/lgtm @Sypher845 please add a test for the changes made. Thanks

@Sypher845

Copy link
Copy Markdown
Contributor Author

So sorry, I missed the notification for this! Working on it!!

Signed-off-by: Sypher845 <suyashpatil845@gmail.com>
Signed-off-by: Sypher845 <suyashpatil845@gmail.com>
@Sypher845 Sypher845 force-pushed the fix/validate-project-id-for-scope-p branch from 432a4c3 to 7d08f42 Compare February 1, 2026 20:14
@Sypher845

Copy link
Copy Markdown
Contributor Author

@bupd i have added the tests, please take a look.

@Sypher845 Sypher845 requested a review from bupd February 1, 2026 20:27
@qcserestipy qcserestipy self-requested a review February 7, 2026 08:59

@qcserestipy qcserestipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thank you for your contribution!

@bupd bupd left a comment

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.

/lgtm

@bupd bupd merged commit 11822d1 into goharbor:main Mar 3, 2026
7 of 8 checks passed
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.

harbor label create allows invalid project-scoped labels

3 participants