Redirects for renamed repos (#807)
* Redirects for renamed repos * Remove unused phrase from locales
This commit is contained in:
parent
e86d935175
commit
027591a3a5
29 changed files with 127 additions and 27 deletions
|
@ -133,6 +133,26 @@ func earlyResponseForGoGetMeta(ctx *Context) {
|
|||
})))
|
||||
}
|
||||
|
||||
// RedirectToRepo redirect to a differently-named repository
|
||||
func RedirectToRepo(ctx *Context, redirectRepoID int64) {
|
||||
ownerName := ctx.Params(":username")
|
||||
previousRepoName := ctx.Params(":reponame")
|
||||
|
||||
repo, err := models.GetRepositoryByID(redirectRepoID)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetRepositoryByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
redirectPath := strings.Replace(
|
||||
ctx.Req.URL.Path,
|
||||
fmt.Sprintf("%s/%s", ownerName, previousRepoName),
|
||||
fmt.Sprintf("%s/%s", ownerName, repo.Name),
|
||||
1,
|
||||
)
|
||||
ctx.Redirect(redirectPath)
|
||||
}
|
||||
|
||||
// RepoAssignment returns a macaron to handle repository assignment
|
||||
func RepoAssignment(args ...bool) macaron.Handler {
|
||||
return func(ctx *Context) {
|
||||
|
@ -176,11 +196,18 @@ func RepoAssignment(args ...bool) macaron.Handler {
|
|||
repo, err := models.GetRepositoryByName(owner.ID, repoName)
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
if ctx.Query("go-get") == "1" {
|
||||
earlyResponseForGoGetMeta(ctx)
|
||||
return
|
||||
redirectRepoID, err := models.LookupRepoRedirect(owner.ID, repoName)
|
||||
if err == nil {
|
||||
RedirectToRepo(ctx, redirectRepoID)
|
||||
} else if models.IsErrRepoRedirectNotExist(err) {
|
||||
if ctx.Query("go-get") == "1" {
|
||||
earlyResponseForGoGetMeta(ctx)
|
||||
return
|
||||
}
|
||||
ctx.Handle(404, "GetRepositoryByName", err)
|
||||
} else {
|
||||
ctx.Handle(500, "LookupRepoRedirect", err)
|
||||
}
|
||||
ctx.Handle(404, "GetRepositoryByName", err)
|
||||
} else {
|
||||
ctx.Handle(500, "GetRepositoryByName", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue