Redirect issue if repo has configured external tracker. (#9247)

* Redirect issue if repo has configured external tracker.

* Handle error

* Add tests for redirect

* Fix test consistency
This commit is contained in:
David Svantesson 2019-12-07 05:21:18 +01:00 committed by techknowlogick
parent 82e0383d21
commit 9cb418e623
91 changed files with 2150 additions and 8 deletions

View file

@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/modules/git"
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting"
@ -606,6 +607,19 @@ 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))
return
}
} else if err != nil && !models.IsErrUnitTypeNotExist(err) {
ctx.ServerError("GetUnit", err)
return
}
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {