mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 16:52:58 +01:00
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.
This commit is contained in:
parent
81a52442a1
commit
f46176a418
3 changed files with 16 additions and 16 deletions
|
@ -607,17 +607,20 @@ func commentTag(repo *models.Repository, poster *models.User, issue *models.Issu
|
||||||
|
|
||||||
// ViewIssue render issue view page
|
// ViewIssue render issue view page
|
||||||
func ViewIssue(ctx *context.Context) {
|
func ViewIssue(ctx *context.Context) {
|
||||||
extIssueUnit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker)
|
if ctx.Params(":type") == "issues" {
|
||||||
if err == nil && extIssueUnit != nil {
|
// If issue was requested we check if repo has external tracker and redirect
|
||||||
if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" {
|
extIssueUnit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker)
|
||||||
metas := ctx.Repo.Repository.ComposeMetas()
|
if err == nil && extIssueUnit != nil {
|
||||||
metas["index"] = ctx.Params(":index")
|
if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" {
|
||||||
ctx.Redirect(com.Expand(extIssueUnit.ExternalTrackerConfig().ExternalTrackerFormat, metas))
|
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
|
return
|
||||||
}
|
}
|
||||||
} else if err != nil && !models.IsErrUnitTypeNotExist(err) {
|
|
||||||
ctx.ServerError("GetUnit", err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
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() {
|
if ctx.HasError() {
|
||||||
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
|
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
|
||||||
ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
|
ctx.Redirect(issue.HTMLURL())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
@ -31,7 +30,7 @@ func AddDependency(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect
|
// Redirect
|
||||||
defer ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issueIndex), http.StatusSeeOther)
|
defer ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
|
||||||
|
|
||||||
// Dependency
|
// Dependency
|
||||||
dep, err := models.GetIssueByID(depID)
|
dep, err := models.GetIssueByID(depID)
|
||||||
|
@ -85,7 +84,7 @@ func RemoveDependency(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect
|
// Redirect
|
||||||
ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issueIndex), http.StatusSeeOther)
|
ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
|
||||||
|
|
||||||
// Dependency Type
|
// Dependency Type
|
||||||
depTypeStr := ctx.Req.PostForm.Get("dependencyType")
|
depTypeStr := ctx.Req.PostForm.Get("dependencyType")
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
@ -54,6 +53,5 @@ func IssueWatch(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)
|
ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
|
||||||
ctx.Redirect(url, http.StatusSeeOther)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue