From 4f0329ff91ab5554f5abdc9c65853d41f5183622 Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Sat, 14 Dec 2019 01:53:32 +0100 Subject: [PATCH] Fix PR/issue redirects when having external tracker (#9339) * Make sure only issues are redirected to external tracker * Ensure correct redirects for pulls after dependency or watch. * NewIssuePost is always issues so no need to redirect with type. --- .drone.yml | 16 ++++++++-------- routers/repo/issue.go | 23 +++++++++++++---------- routers/repo/issue_dependency.go | 5 ++--- routers/repo/issue_watch.go | 4 +--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.drone.yml b/.drone.yml index b44bcb87256f2..a00b275ff1dbb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -165,8 +165,8 @@ steps: commands: - "curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash" - apt-get install -y git-lfs - - timeout -s ABRT 20m make test-sqlite-migration - - timeout -s ABRT 20m make test-sqlite + - timeout -s ABRT 30m make test-sqlite-migration + - timeout -s ABRT 30m make test-sqlite environment: GOPROXY: off TAGS: bindata @@ -200,8 +200,8 @@ steps: commands: - "curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash" - apt-get install -y git-lfs - - timeout -s ABRT 20m make test-mysql-migration - - timeout -s ABRT 20m make test-mysql + - timeout -s ABRT 30m make test-mysql-migration + - timeout -s ABRT 30m make test-mysql environment: GOPROXY: off TAGS: bindata @@ -218,8 +218,8 @@ steps: commands: - "curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash" - apt-get install -y git-lfs - - timeout -s ABRT 20m make test-mysql8-migration - - timeout -s ABRT 20m make test-mysql8 + - timeout -s ABRT 30m make test-mysql8-migration + - timeout -s ABRT 30m make test-mysql8 environment: GOPROXY: off TAGS: bindata @@ -233,8 +233,8 @@ steps: commands: - "curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash" - apt-get install -y git-lfs - - timeout -s ABRT 20m make test-pgsql-migration - - timeout -s ABRT 20m make test-pgsql + - timeout -s ABRT 30m make test-pgsql-migration + - timeout -s ABRT 30m make test-pgsql environment: GOPROXY: off TAGS: bindata diff --git a/routers/repo/issue.go b/routers/repo/issue.go index adafb64eb3e4f..7d11ed3537d58 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -607,17 +607,20 @@ func commentTag(repo *models.Repository, poster *models.User, issue *models.Issu // ViewIssue render issue view page func ViewIssue(ctx *context.Context) { - extIssueUnit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker) - if err == nil && extIssueUnit != nil { - if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" { - metas := ctx.Repo.Repository.ComposeMetas() - metas["index"] = ctx.Params(":index") - ctx.Redirect(com.Expand(extIssueUnit.ExternalTrackerConfig().ExternalTrackerFormat, metas)) + if ctx.Params(":type") == "issues" { + // If issue was requested we check if repo has external tracker and redirect + extIssueUnit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker) + if err == nil && extIssueUnit != nil { + if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" { + metas := ctx.Repo.Repository.ComposeMetas() + metas["index"] = ctx.Params(":index") + ctx.Redirect(com.Expand(extIssueUnit.ExternalTrackerConfig().ExternalTrackerFormat, metas)) + return + } + } else if err != nil && !models.IsErrUnitTypeNotExist(err) { + ctx.ServerError("GetUnit", err) return } - } else if err != nil && !models.IsErrUnitTypeNotExist(err) { - ctx.ServerError("GetUnit", err) - return } issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) @@ -1255,7 +1258,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) { if ctx.HasError() { ctx.Flash.Error(ctx.Data["ErrorMsg"].(string)) - ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) + ctx.Redirect(issue.HTMLURL()) return } diff --git a/routers/repo/issue_dependency.go b/routers/repo/issue_dependency.go index 6b11f0cdf1530..00d7d85ce9cf4 100644 --- a/routers/repo/issue_dependency.go +++ b/routers/repo/issue_dependency.go @@ -5,7 +5,6 @@ package repo import ( - "fmt" "net/http" "code.gitea.io/gitea/models" @@ -31,7 +30,7 @@ func AddDependency(ctx *context.Context) { } // Redirect - defer ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issueIndex), http.StatusSeeOther) + defer ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) // Dependency dep, err := models.GetIssueByID(depID) @@ -85,7 +84,7 @@ func RemoveDependency(ctx *context.Context) { } // Redirect - ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issueIndex), http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) // Dependency Type depTypeStr := ctx.Req.PostForm.Get("dependencyType") diff --git a/routers/repo/issue_watch.go b/routers/repo/issue_watch.go index eae663495ae6e..07671af13a145 100644 --- a/routers/repo/issue_watch.go +++ b/routers/repo/issue_watch.go @@ -5,7 +5,6 @@ package repo import ( - "fmt" "net/http" "strconv" @@ -54,6 +53,5 @@ func IssueWatch(ctx *context.Context) { return } - url := fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index) - ctx.Redirect(url, http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) }