Skip to content

fix: project view --id flag not working#639

Merged
bupd merged 4 commits into
goharbor:mainfrom
Sypher845:fix/project-view-by-id
Mar 3, 2026
Merged

fix: project view --id flag not working#639
bupd merged 4 commits into
goharbor:mainfrom
Sypher845:fix/project-view-by-id

Conversation

@Sypher845

@Sypher845 Sypher845 commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #638
t-rec

  1. In pkg/utils/error.go, the function ParseHarborErrorCode can now parse error code of type (status CODE), before it was only able to parse error of type [METHOD /path][CODE].

  2. Removed the CheckProject function in pkg/api/project_handler.go and replaced the logic where it is used with GetProject

  3. Before the --id flag for project view was not working , now it correctly passes isID to GetProject and works as expected.

@codecov

codecov Bot commented Jan 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 7.24%. Comparing base (60ad0bd) to head (61055d1).
⚠️ Report is 100 commits behind head on main.

Files with missing lines Patch % Lines
cmd/harbor/root/project/member/create.go 0.00% 5 Missing ⚠️
cmd/harbor/root/project/member/delete.go 0.00% 5 Missing ⚠️
pkg/utils/error.go 0.00% 5 Missing ⚠️
cmd/harbor/root/project/logs.go 0.00% 4 Missing ⚠️
cmd/harbor/root/project/view.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #639      +/-   ##
=========================================
- Coverage   10.99%   7.24%   -3.75%     
=========================================
  Files         173     260      +87     
  Lines        8671   12898    +4227     
=========================================
- Hits          953     935      -18     
- Misses       7612   11855    +4243     
- Partials      106     108       +2     

☔ 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.

@Sypher845

Copy link
Copy Markdown
Contributor Author

@bupd @NucleoFusion please review.

@qcserestipy qcserestipy self-requested a review February 6, 2026 18:37

@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.

Thank you for your contribution! I added a few comments. It would make the code simpler by removing the CheckProject function and replace the logic where it is used with GetProject.

Comment thread pkg/api/project_handler.go Outdated
Comment thread cmd/harbor/root/project/member/create.go Outdated
Comment thread cmd/harbor/root/project/member/delete.go Outdated
Comment thread cmd/harbor/root/project/logs.go Outdated
Comment thread cmd/harbor/root/project/view.go Outdated
@Sypher845 Sypher845 force-pushed the fix/project-view-by-id branch from bad54ba to 4428927 Compare February 7, 2026 11:31
@Sypher845

Copy link
Copy Markdown
Contributor Author

@qcserestipy
I found one thing , in pkg/utils/error.go the ParseHarborErroCode can only check for error of format [404].
But the project, err = api.GetProject(projectName, isID) in this the err has a format of (status 404), the current ParseHarborErrorCode cannot parse this format, so i added the format checking also.
please take a look

@Sypher845 Sypher845 requested a review from qcserestipy February 7, 2026 11:35
@Sypher845

Copy link
Copy Markdown
Contributor Author

@qcserestipy any update on this?

@qcserestipy

Copy link
Copy Markdown
Collaborator

LGTM, can you add a screenshot or screen record that documents the outcome?

Signed-off-by: Sypher845 <suyashpatil845@gmail.com>
Signed-off-by: Sypher845 <suyashpatil845@gmail.com>
@Sypher845

Copy link
Copy Markdown
Contributor Author

@qcserestipy done, added the GIF and also updated the PR description

@qcserestipy

Copy link
Copy Markdown
Collaborator

Nice, thank you! LGTM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes issue #638 where the --id flag for harbor project view was defined but not functional. The fix enhances error parsing to support additional error formats and refactors project existence checks to properly use the isID parameter.

Changes:

  • Enhanced ParseHarborErrorCode to parse errors in (status CODE) format in addition to the existing [METHOD /path][CODE] format
  • Removed the CheckProject function and replaced all usages with GetProject, which supports the isID parameter
  • Fixed project view command to properly pass the isID flag to GetProject, enabling project lookup by ID

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/utils/error.go Added regex-based parsing for (status CODE) error format
pkg/api/project_handler.go Removed unused CheckProject function
cmd/harbor/root/project/view.go Fixed to properly use isID flag when fetching projects
cmd/harbor/root/project/member/delete.go Replaced CheckProject with GetProject to support isID flag
cmd/harbor/root/project/member/create.go Replaced CheckProject with GetProject to support isID flag
cmd/harbor/root/project/logs.go Replaced CheckProject with GetProject for consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/utils/error.go
}

// Try format: (status CODE) - e.g., (status 404)
re := regexp.MustCompile(`\(status\s+(\d{3})\)`)

Copilot AI Feb 16, 2026

Copy link

Choose a reason for hiding this comment

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

The regex is compiled on every function call, which is inefficient. Consider compiling the regex once as a package-level variable to improve performance, especially if this function is called frequently.

Copilot uses AI. Check for mistakes.

@Sypher845 Sypher845 Feb 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The function is not called frequently. Also many other files are compiling the regex inside the function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SHould i implement this suggestion? @bupd @qcserestipy

Comment thread cmd/harbor/root/project/member/delete.go Outdated
Comment thread cmd/harbor/root/project/member/create.go Outdated
Signed-off-by: Sypher845 <suyashpatil845@gmail.com>
@Sypher845 Sypher845 force-pushed the fix/project-view-by-id branch from 4428927 to 1f6b16f Compare February 16, 2026 19:57
@bupd bupd merged commit 03ce614 into goharbor:main Mar 3, 2026
6 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 project view --id flag is defined but not implemented

4 participants