Skip to content
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

Fix the protected branch panic issue #3567

Merged
merged 2 commits into from
Feb 23, 2018

Conversation

xwjdsh
Copy link
Contributor

@xwjdsh xwjdsh commented Feb 23, 2018

Fixes #3326

@codecov-io
Copy link

codecov-io commented Feb 23, 2018

Codecov Report

Merging #3567 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3567      +/-   ##
==========================================
+ Coverage   35.79%   35.79%   +<.01%     
==========================================
  Files         285      285              
  Lines       40863    40866       +3     
==========================================
+ Hits        14625    14630       +5     
+ Misses      24068    24066       -2     
  Partials     2170     2170
Impacted Files Coverage Δ
models/branches.go 53.1% <100%> (+0.8%) ⬆️
models/repo_list.go 67.18% <0%> (+1.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d1c5c3...c8c0b1b. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 23, 2018
if err != nil {
ctx.ServerError("IsProtectedBranch", err)
return nil
var isProtected bool
Copy link
Member

Choose a reason for hiding this comment

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

isProtected maybe default true?

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to add a check before

return !protectedBranch.CanUserPush(doer.ID), nil

If we are here and user is nil -> return true, nil

Copy link
Member

Choose a reason for hiding this comment

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

This will fix this for any use case of IsProtectedBranch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I thought so once, but the bad thing is the IsProtectedBranch function will be invoked multi-times redundantly.

Copy link
Member

Choose a reason for hiding this comment

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

So simply do at start of func as it would be the same.

if doer  == nil {
  return true, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I updated, thanks.

@lunny lunny added the type/bug label Feb 23, 2018
@lunny lunny added this to the 1.5.0 milestone Feb 23, 2018
@tboerger tboerger 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 Feb 23, 2018
@tboerger tboerger 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 Feb 23, 2018
@lunny lunny merged commit d2d0aea into go-gitea:master Feb 23, 2018
@lafriks
Copy link
Member

lafriks commented Feb 23, 2018

I think this should be backported to release/v1.4 branch

xwjdsh added a commit to xwjdsh/gitea that referenced this pull request Feb 23, 2018
Signed-off-by: Wendell Sun <iwendellsun@gmail.com>
lafriks pushed a commit that referenced this pull request Feb 23, 2018
Signed-off-by: Wendell Sun <iwendellsun@gmail.com>
@lafriks lafriks added the backport/done All backports for this PR have been created label Feb 23, 2018
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Protected branches causes 500 Internal Server Error
7 participants