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

Reorder the process of repo rename. #17990

Closed
FlyingOnion opened this issue Dec 15, 2021 · 3 comments · Fixed by #18008
Closed

Reorder the process of repo rename. #17990

FlyingOnion opened this issue Dec 15, 2021 · 3 comments · Fixed by #18008
Labels
Milestone

Comments

@FlyingOnion
Copy link

Feature Description

I'm facing a small problem when I implement my own notifier. When I implement NotifyRenameRepository function, I could not find the new repo name (the name in arg repo *models.Repository is the old name). After I check the code I found that repo.Name = newRepoName is called after function repo_service.ChangeRepositoryName.

There are two places:

if err := repo_service.ChangeRepositoryName(ctx.User, repo, newRepoName); err != nil {

if err := repo_service.ChangeRepositoryName(ctx.User, repo, newRepoName); err != nil {

Wait for your opinion.

Screenshots

No response

@lunny lunny added the type/proposal The new feature has not been accepted yet but needs to be discussed first. label Dec 15, 2021
@lunny
Copy link
Member

lunny commented Dec 15, 2021

I think you can find the old and new name. NotifyRenameRepository(doer *user_model.User, repo *repo_model.Repository, oldRepoName string).

@lunny lunny added reviewed/invalid and removed type/proposal The new feature has not been accepted yet but needs to be discussed first. labels Dec 15, 2021
@FlyingOnion
Copy link
Author

FlyingOnion commented Dec 16, 2021

In NotifyRenameRepository(doer *user_model.User, repo *repo_model.Repository, oldRepoName string), repo.Name returns old name. repo.Name is updated after func repo_service.ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoName string) error function returns.

This is a brief order in routers/api/v1/repo/repo.go function updateBasicProperties, so as in routers/web/repo/setting.go function SettingsPost.

func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) error {
  repo := ctx.Repo.Repository
  newRepoName := repo.Name
  if opts.Name != nil {
    newRepoName = *opts.Name
  }
  repo_service.ChangeRepositoryName(ctx.User, repo, newRepoName) {
    models.ChangeRepositoryName(doer, repo, newRepoName) // does not update repo.Name in this function call
    notification.NotifyRenameRepository(doer, repo, oldRepoName) // repo.Name remains unchanged
  }
  repo.Name = newName // repo.Name is updated here
}

@lunny
Copy link
Member

lunny commented Dec 16, 2021

Ah, then I think it's a bug rather a feature.

@lunny lunny added this to the 1.15.8 milestone Dec 16, 2021
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants