-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Implement update branch API #32433
Implement update branch API #32433
Conversation
1beebeb
to
36829ec
Compare
Found while working on #32433. This branch will never be executed because we have would have already made the same check a couple lines above.
if repo.IsEmpty { | ||
ctx.Error(http.StatusNotFound, "", "Git Repository is empty.") | ||
return | ||
} | ||
|
||
if repo.IsMirror { | ||
ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.") | ||
return | ||
} |
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.
Maybe these checks can be done in RenameBranch
, and return different http status codes by catching errors?
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 this a blocked request?
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.
No.
In the web UI, user can not rename branch in mirror/empty repo. So maybe it is ok to skip these checks.
But you can create a special request to do it. So I think it is better to move these checks to the functions in service level. I have also mentioned this problem in some issues/PRs. But it seems that it is acceptable in this project, so this is not a blocked request.
e.g. I can pick up a public mirror repo in Gitea.com, then I create a fake request to change the branch name or do somethings which is not expected and no checks for the web UI side, I'm not sure what will happen, but it is not LGTM.
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.
Maybe we can put that for another PRs. This PR is focused on adding the API endpoint.
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.
I originally found those checks in the other branch API implementations and believed it made sense to include them in here.
I do agree that this logic should be moved to the service layer. To me, the presentation layer (i.e. the API and web routes handlers) should just be concerned with presenting the response given what the service layer provides. From my experience it does look like we have sprinkled application logic into our middleware and our web/API route handlers, so it does become confusing when considering where it should be added.
But I also agree with doing this in a separate PR just to keeps our changes atomic (since I would also wan't to add service layer tests for these checks). I would be more than happy to do this once this one is merged.
Please resolve the conflict. |
Co-authored-by: sillyguodong <33891828+sillyguodong@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
4445c70
to
83e3528
Compare
* giteaofficial/main: Fix bug of branch/tag selector in the issue sidebar (go-gitea#32744) Fix lfs migration (go-gitea#32812) Avoid MacOS keychain dialog in integration tests (go-gitea#32813) Update actionlint.yaml Detect whether action view branch was deleted (go-gitea#32764) Add "n commits" link to contributors in contributors graph page (go-gitea#32799) Fix "unicode escape" JS error (go-gitea#32806) use dedicated runners for release artifacts (go-gitea#32811) Make API "compare" accept commit IDs (go-gitea#32801) Implement update branch API (go-gitea#32433) Fix JS error when dropping a file to a editor without dropzone (go-gitea#32804) chore: use errors.New to replace fmt.Errorf with no parameters (go-gitea#32800)
Resolves #22526.
Builds upon #23061.