-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Refactor compare router param parse and fix bugs #36105
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: techknowlogick <[email protected]> Signed-off-by: Lunny Xiao <[email protected]>
|
please have a look at #36116 |
This has been included and it's ready to review now. |
models/user/user.go
Outdated
|
|
||
| func GetUserOrOrgByName(ctx context.Context, name string) (*User, error) { | ||
| var u User | ||
| has, err := db.GetEngine(ctx).Where("name = ?", name).Get(&u) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why not
lower_name - There is no existing similar function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6453e4a There is no existing function that can retrieve a user or an organization.
routers/api/v1/repo/pull.go
Outdated
| return nil, nil | ||
| } | ||
| if headRepo == nil { | ||
| ctx.HTTPError(http.StatusBadRequest, "The user "+headOwner.Name+" does not have a fork of the base repository") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why sometimes APIError sometimes HTTPError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
routers/web/repo/compare.go
Outdated
| } else { | ||
| ctx.ServerError("GetRepositoryByName", err) | ||
| } | ||
| return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why duplicate the code with API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
routers/api/v1/repo/pull.go
Outdated
| } else { | ||
| headOwner, err = user_model.GetUserOrOrgByName(ctx, compareReq.HeadOwner) | ||
| if err != nil { | ||
| if user_model.IsErrUserNotExist(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetUserOrOrgByName doesn't return errors for IsErrUserNotExist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Is it safe to backport a refactoring PR with so many logic changes? |
This will be partially backport. Only bugfixes will be backport. |
routers/common/compare.go
Outdated
| if traverseLevel == 0 { | ||
| return nil, nil | ||
| } | ||
| // test if we are lucky |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe what "lucky" means?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment could be removed. It seems meaningless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I wonder why you added it in first place :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9868b2f I honestly can’t remember why I did that.
routers/common/compare.go
Outdated
| func GetHeadOwnerAndRepo(ctx context.Context, baseRepo *repo_model.Repository, compareReq *CompareRouterReq) (headOwner *user_model.User, headRepo *repo_model.Repository, err error) { | ||
| if compareReq.HeadOwner == "" { | ||
| if compareReq.HeadRepoName != "" { // unsupported syntax | ||
| return nil, nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you avoid returning no result and no error at the same time? I thought we had the nilnil linter to detect such scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems nilnil it is currently not enabled and I guess there may be many violations in the code base. We should still strive to enable it because such returns are ambiguous and very unclear to readers.
A function should either be successful or failure, not something in between the two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I did a test run of nilnil with below settings, there are currently 287 violations in the code base but I feel I'm not qualified to fix them. What we could do is add // nolint to them all and gradually fix them, forbiding any new errors to be introduced.
nilnil:
only-two: false
detect-opposite: trueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…lunny/refactor_compare
Fix #36116
Fix #35912
Fix #20906