diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-02-05 09:35:03 -0500 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-05 22:35:03 +0800 |
commit | 027591a3a556477a26d6c849e1ed9b9a53c15110 (patch) | |
tree | a2530f9419e864fbb68e6b38dd7b28ce58f592b6 /routers | |
parent | e86d9351754f85b1508092b793dbd8a5cd1456f2 (diff) | |
download | gitea-027591a3a556477a26d6c849e1ed9b9a53c15110.tar.gz gitea-027591a3a556477a26d6c849e1ed9b9a53c15110.zip |
Redirects for renamed repos (#807)
* Redirects for renamed repos
* Remove unused phrase from locales
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/api.go | 9 | ||||
-rw-r--r-- | routers/repo/setting.go | 5 |
2 files changed, 13 insertions, 1 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index afdb2c0045..f89d6e3445 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -52,7 +52,14 @@ func repoAssignment() macaron.Handler { repo, err := models.GetRepositoryByName(owner.ID, repoName) if err != nil { if models.IsErrRepoNotExist(err) { - ctx.Status(404) + redirectRepoID, err := models.LookupRepoRedirect(owner.ID, repoName) + if err == nil { + context.RedirectToRepo(ctx.Context, redirectRepoID) + } else if models.IsErrRepoRedirectNotExist(err) { + ctx.Status(404) + } else { + ctx.Error(500, "LookupRepoRedirect", err) + } } else { ctx.Error(500, "GetRepositoryByName", err) } diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 9a426c1598..17a5b4aa02 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -68,6 +68,11 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { return } + err := models.NewRepoRedirect(ctx.Repo.Owner.ID, repo.ID, repo.Name, newRepoName) + if err != nil { + ctx.Handle(500, "NewRepoRedirect", err) + } + log.Trace("Repository name changed: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newRepoName) } // In case it's just a case change. |