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

Implement update branch API #32433

Merged
merged 11 commits into from
Dec 12, 2024
Merged

Conversation

kemzeb
Copy link
Contributor

@kemzeb kemzeb commented Nov 6, 2024

Resolves #22526.

Builds upon #23061.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 6, 2024
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 6, 2024
@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 Nov 6, 2024
routers/api/v1/repo/branch.go Outdated Show resolved Hide resolved
routers/api/v1/repo/branch.go Outdated Show resolved Hide resolved
@silverwind silverwind added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Nov 6, 2024
routers/api/v1/api.go Outdated Show resolved Hide resolved
@kemzeb kemzeb force-pushed the feat-api-add-rename-branch branch from 1beebeb to 36829ec Compare November 17, 2024 02:12
routers/api/v1/api.go Outdated Show resolved Hide resolved
@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 Nov 19, 2024
@lunny lunny added this to the 1.23.0 milestone Nov 19, 2024
lunny pushed a commit that referenced this pull request Nov 20, 2024
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.
Comment on lines +443 to +441
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
}
Copy link
Contributor

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?

Copy link
Member

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?

Copy link
Contributor

@yp05327 yp05327 Dec 6, 2024

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.

Copy link
Member

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.

Copy link
Contributor Author

@kemzeb kemzeb Dec 7, 2024

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.

@lunny
Copy link
Member

lunny commented Dec 6, 2024

Please resolve the conflict.

@kemzeb kemzeb changed the title Implement rename branch API Implement update branch API Dec 7, 2024
@kemzeb kemzeb force-pushed the feat-api-add-rename-branch branch from 4445c70 to 83e3528 Compare December 7, 2024 01:20
@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 7, 2024
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Dec 12, 2024
@lunny lunny enabled auto-merge (squash) December 12, 2024 04:11
@lunny lunny merged commit 01b1896 into go-gitea:main Dec 12, 2024
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Dec 12, 2024
zjjhot added a commit to zjjhot/gitea that referenced this pull request Dec 13, 2024
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Api for branch rename
7 participants