From 9a3f521cc55f935dfdd1e996b80c3099a99b2718 Mon Sep 17 00:00:00 2001 From: dasv Date: Thu, 12 Dec 2019 21:37:56 +0100 Subject: [PATCH 1/3] Make sure only issues are redirected to external tracker --- routers/repo/issue.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 5d5aaca253f25..66b9c0eae7600 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -585,7 +585,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) { } log.Trace("Issue created: %d/%d", repo.ID, issue.ID) - ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index)) + ctx.Redirect(issue.HTMLURL()) } // commentTag returns the CommentTag for a comment in/with the given repo, poster and issue @@ -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 } From 92340fa6faf984b039341c71a7f9ab7fdff8807c Mon Sep 17 00:00:00 2001 From: dasv Date: Thu, 12 Dec 2019 21:38:36 +0100 Subject: [PATCH 2/3] Ensure correct redirects for pulls after dependency or watch. --- routers/repo/issue_dependency.go | 5 ++--- routers/repo/issue_watch.go | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) 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) } From acf5b5e15f7e5c58664660fea4a1272041d5ce4d Mon Sep 17 00:00:00 2001 From: dasv Date: Thu, 12 Dec 2019 23:13:21 +0100 Subject: [PATCH 3/3] NewIssuePost is always issues so no need to redirect with type. --- routers/repo/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 66b9c0eae7600..19e0b48bc1c4d 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -585,7 +585,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) { } log.Trace("Issue created: %d/%d", repo.ID, issue.ID) - ctx.Redirect(issue.HTMLURL()) + ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index)) } // commentTag returns the CommentTag for a comment in/with the given repo, poster and issue