-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Custom regexp external issues #17624
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6808b57
Implement custom regular expression for external issue tracking.
AlexanderBeyn fc1401a
Fix syntax/style
strk ce82e7c
Update repo.go
techknowlogick 7ac7a0e
Set metas['regexp']
strk 777dc41
gofmt
strk 9a40b16
Merge branch 'main' into custom-regexp-external-issues
lafriks b8703c8
Merge branch 'master' into custom-regexp-external-issues
6543 94361df
Merge pull request #2 from 6543-forks/custom-regexp-external-issues
strk 898169e
Merge branch 'main' into custom-regexp-external-issues
6543 a1795f9
Merge branch 'main' into custom-regexp-external-issues
6543 68b718b
fix some tests
wxiaoguang 0b88fbc
fix more tests
wxiaoguang 60217b4
refactor frontend
wxiaoguang 2639ced
use LRU cache for regexp
wxiaoguang 94c4953
Merge branch 'main' into custom-regexp-external-issues
wxiaoguang 20eb0d1
Update modules/markup/html_internal_test.go
6543 79461d1
Merge branch 'main' into custom-regexp-external-issues
6543 ee53226
Merge branch 'main' into custom-regexp-external-issues
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package regexplru | ||
|
||
import ( | ||
"regexp" | ||
|
||
"code.gitea.io/gitea/modules/log" | ||
|
||
lru "github.com/hashicorp/golang-lru" | ||
) | ||
|
||
var lruCache *lru.Cache | ||
|
||
func init() { | ||
var err error | ||
lruCache, err = lru.New(1000) | ||
if err != nil { | ||
log.Fatal("failed to new LRU cache, err: %v", err) | ||
} | ||
} | ||
|
||
// GetCompiled works like regexp.Compile, the compiled expr or error is stored in LRU cache | ||
func GetCompiled(expr string) (r *regexp.Regexp, err error) { | ||
v, ok := lruCache.Get(expr) | ||
if !ok { | ||
r, err = regexp.Compile(expr) | ||
if err != nil { | ||
lruCache.Add(expr, err) | ||
return nil, err | ||
} | ||
lruCache.Add(expr, r) | ||
} else { | ||
r, ok = v.(*regexp.Regexp) | ||
if !ok { | ||
if err, ok = v.(error); ok { | ||
return nil, err | ||
} | ||
panic("impossible") | ||
} | ||
} | ||
return r, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package regexplru | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRegexpLru(t *testing.T) { | ||
r, err := GetCompiled("a") | ||
assert.NoError(t, err) | ||
assert.True(t, r.MatchString("a")) | ||
|
||
r, err = GetCompiled("a") | ||
assert.NoError(t, err) | ||
assert.True(t, r.MatchString("a")) | ||
|
||
assert.EqualValues(t, 1, lruCache.Len()) | ||
|
||
_, err = GetCompiled("(") | ||
assert.Error(t, err) | ||
assert.EqualValues(t, 2, lruCache.Len()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.