From 52c2e82813c2519cd08c9ecd66ef7b0815682770 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 10 Jun 2022 07:39:53 +0200 Subject: Custom regexp external issues (#17624) * Implement custom regular expression for external issue tracking. Signed-off-by: Alexander Beyn * Fix syntax/style * Update repo.go * Set metas['regexp'] * gofmt * fix some tests * fix more tests * refactor frontend * use LRU cache for regexp * Update modules/markup/html_internal_test.go Co-authored-by: Alexander Beyn Co-authored-by: techknowlogick Co-authored-by: Lauris BH Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang --- models/repo/repo.go | 3 +++ models/repo/repo_unit.go | 7 ++++--- models/repo_test.go | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'models') diff --git a/models/repo/repo.go b/models/repo/repo.go index 3fd6b94eb1..57d85435eb 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -414,6 +414,9 @@ func (repo *Repository) ComposeMetas() map[string]string { switch unit.ExternalTrackerConfig().ExternalTrackerStyle { case markup.IssueNameStyleAlphanumeric: metas["style"] = markup.IssueNameStyleAlphanumeric + case markup.IssueNameStyleRegexp: + metas["style"] = markup.IssueNameStyleRegexp + metas["regexp"] = unit.ExternalTrackerConfig().ExternalTrackerRegexpPattern default: metas["style"] = markup.IssueNameStyleNumeric } diff --git a/models/repo/repo_unit.go b/models/repo/repo_unit.go index 8c17d6138c..da3e19dece 100644 --- a/models/repo/repo_unit.go +++ b/models/repo/repo_unit.go @@ -76,9 +76,10 @@ func (cfg *ExternalWikiConfig) ToDB() ([]byte, error) { // ExternalTrackerConfig describes external tracker config type ExternalTrackerConfig struct { - ExternalTrackerURL string - ExternalTrackerFormat string - ExternalTrackerStyle string + ExternalTrackerURL string + ExternalTrackerFormat string + ExternalTrackerStyle string + ExternalTrackerRegexpPattern string } // FromDB fills up a ExternalTrackerConfig from serialized format. diff --git a/models/repo_test.go b/models/repo_test.go index c9e66398d1..f554ff16a6 100644 --- a/models/repo_test.go +++ b/models/repo_test.go @@ -74,6 +74,9 @@ func TestMetas(t *testing.T) { externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleNumeric testSuccess(markup.IssueNameStyleNumeric) + externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleRegexp + testSuccess(markup.IssueNameStyleRegexp) + repo, err := repo_model.GetRepositoryByID(3) assert.NoError(t, err) -- cgit v1.2.3