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

Fix PR/issue redirects when having external tracker #9339

Merged
merged 8 commits into from
Dec 14, 2019
23 changes: 13 additions & 10 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions routers/repo/issue_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package repo

import (
"fmt"
"net/http"

"code.gitea.io/gitea/models"
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions routers/repo/issue_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package repo

import (
"fmt"
"net/http"
"strconv"

Expand Down Expand Up @@ -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)
}