Skip to content

Conversation

@lunny
Copy link
Member

@lunny lunny commented Dec 8, 2025

Fix #36116
Fix #35912
Fix #20906

@lunny lunny added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Dec 8, 2025
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 8, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Dec 8, 2025
Co-authored-by: techknowlogick <[email protected]>
Signed-off-by: Lunny Xiao <[email protected]>
@a1012112796
Copy link
Member

please have a look at #36116

@lunny lunny marked this pull request as ready for review December 10, 2025 23:25
@lunny lunny changed the title Refactor compare router param parse Refactor compare router param parse and fix bugs Dec 11, 2025
@lunny
Copy link
Member Author

lunny commented Dec 11, 2025

please have a look at #36116

This has been included and it's ready to review now.

@lunny lunny added the type/bug label Dec 11, 2025
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 11, 2025
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Dec 12, 2025

func GetUserOrOrgByName(ctx context.Context, name string) (*User, error) {
var u User
has, err := db.GetEngine(ctx).Where("name = ?", name).Get(&u)
Copy link
Contributor

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?

Copy link
Member Author

@lunny lunny Dec 12, 2025

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.

return nil, nil
}
if headRepo == nil {
ctx.HTTPError(http.StatusBadRequest, "The user "+headOwner.Name+" does not have a fork of the base repository")
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

} else {
ctx.ServerError("GetRepositoryByName", err)
}
return nil
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

} else {
headOwner, err = user_model.GetUserOrOrgByName(ctx, compareReq.HeadOwner)
if err != nil {
if user_model.IsErrUserNotExist(err) {
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@wxiaoguang wxiaoguang marked this pull request as draft December 12, 2025 02:54
@wxiaoguang
Copy link
Contributor

Is it safe to backport a refactoring PR with so many logic changes?

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Dec 12, 2025
@GiteaBot GiteaBot removed the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Dec 12, 2025
@lunny
Copy link
Member Author

lunny commented Dec 12, 2025

Is it safe to backport a refactoring PR with so many logic changes?

This will be partially backport. Only bugfixes will be backport.

@lunny lunny marked this pull request as ready for review December 12, 2025 17:36
@lunny lunny added this to the 1.26.0 milestone Dec 12, 2025
@lunny lunny added backport/done All backports for this PR have been created backport/v1.25 labels Dec 12, 2025
if traverseLevel == 0 {
return nil, nil
}
// test if we are lucky
Copy link
Member

Choose a reason for hiding this comment

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

describe what "lucky" means?

Copy link
Member Author

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.

Copy link
Member

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 :)

Copy link
Member Author

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.

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
Copy link
Member

@silverwind silverwind Dec 12, 2025

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.

Copy link
Member

@silverwind silverwind Dec 12, 2025

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.

Copy link
Member

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: true

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/done All backports for this PR have been created backport/v1.25 lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/translation type/bug type/refactoring Existing code has been cleaned up. There should be no new functionality.

Projects

None yet

8 participants