Skip to content

Commit f46176a

Browse files
David Svantessonsapk
David Svantesson
authored andcommitted
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.
1 parent 81a5244 commit f46176a

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

routers/repo/issue.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -607,17 +607,20 @@ func commentTag(repo *models.Repository, poster *models.User, issue *models.Issu
607607

608608
// ViewIssue render issue view page
609609
func ViewIssue(ctx *context.Context) {
610-
extIssueUnit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker)
611-
if err == nil && extIssueUnit != nil {
612-
if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" {
613-
metas := ctx.Repo.Repository.ComposeMetas()
614-
metas["index"] = ctx.Params(":index")
615-
ctx.Redirect(com.Expand(extIssueUnit.ExternalTrackerConfig().ExternalTrackerFormat, metas))
610+
if ctx.Params(":type") == "issues" {
611+
// If issue was requested we check if repo has external tracker and redirect
612+
extIssueUnit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker)
613+
if err == nil && extIssueUnit != nil {
614+
if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" {
615+
metas := ctx.Repo.Repository.ComposeMetas()
616+
metas["index"] = ctx.Params(":index")
617+
ctx.Redirect(com.Expand(extIssueUnit.ExternalTrackerConfig().ExternalTrackerFormat, metas))
618+
return
619+
}
620+
} else if err != nil && !models.IsErrUnitTypeNotExist(err) {
621+
ctx.ServerError("GetUnit", err)
616622
return
617623
}
618-
} else if err != nil && !models.IsErrUnitTypeNotExist(err) {
619-
ctx.ServerError("GetUnit", err)
620-
return
621624
}
622625

623626
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
@@ -1255,7 +1258,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
12551258

12561259
if ctx.HasError() {
12571260
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
1258-
ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
1261+
ctx.Redirect(issue.HTMLURL())
12591262
return
12601263
}
12611264

routers/repo/issue_dependency.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package repo
66

77
import (
8-
"fmt"
98
"net/http"
109

1110
"code.gitea.io/gitea/models"
@@ -31,7 +30,7 @@ func AddDependency(ctx *context.Context) {
3130
}
3231

3332
// Redirect
34-
defer ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issueIndex), http.StatusSeeOther)
33+
defer ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
3534

3635
// Dependency
3736
dep, err := models.GetIssueByID(depID)
@@ -85,7 +84,7 @@ func RemoveDependency(ctx *context.Context) {
8584
}
8685

8786
// Redirect
88-
ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issueIndex), http.StatusSeeOther)
87+
ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
8988

9089
// Dependency Type
9190
depTypeStr := ctx.Req.PostForm.Get("dependencyType")

routers/repo/issue_watch.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package repo
66

77
import (
8-
"fmt"
98
"net/http"
109
"strconv"
1110

@@ -54,6 +53,5 @@ func IssueWatch(ctx *context.Context) {
5453
return
5554
}
5655

57-
url := fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)
58-
ctx.Redirect(url, http.StatusSeeOther)
56+
ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
5957
}

0 commit comments

Comments
 (0)