forked from NYANDEV/forgejo
Add support for commit cross references (#22645)
Fixes #22628 This PR adds cross references for commits by using the format `owner/repo@commit` . References are rendered like [go-gitea/lgtm@6fe88302](#dummy). --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
3ff5a6a365
commit
d0d257b243
3 changed files with 101 additions and 0 deletions
|
@ -303,6 +303,67 @@ func TestFindAllMentions(t *testing.T) {
|
|||
}, res)
|
||||
}
|
||||
|
||||
func TestFindRenderizableCommitCrossReference(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input string
|
||||
Expected *RenderizableReference
|
||||
}{
|
||||
{
|
||||
Input: "",
|
||||
Expected: nil,
|
||||
},
|
||||
{
|
||||
Input: "test",
|
||||
Expected: nil,
|
||||
},
|
||||
{
|
||||
Input: "go-gitea/gitea@test",
|
||||
Expected: nil,
|
||||
},
|
||||
{
|
||||
Input: "go-gitea/gitea@ab1234",
|
||||
Expected: nil,
|
||||
},
|
||||
{
|
||||
Input: "go-gitea/gitea@abcd1234",
|
||||
Expected: &RenderizableReference{
|
||||
Owner: "go-gitea",
|
||||
Name: "gitea",
|
||||
CommitSha: "abcd1234",
|
||||
RefLocation: &RefSpan{Start: 0, End: 23},
|
||||
},
|
||||
},
|
||||
{
|
||||
Input: "go-gitea/gitea@abcd1234abcd1234abcd1234abcd1234abcd1234",
|
||||
Expected: &RenderizableReference{
|
||||
Owner: "go-gitea",
|
||||
Name: "gitea",
|
||||
CommitSha: "abcd1234abcd1234abcd1234abcd1234abcd1234",
|
||||
RefLocation: &RefSpan{Start: 0, End: 55},
|
||||
},
|
||||
},
|
||||
{
|
||||
Input: "go-gitea/gitea@abcd1234abcd1234abcd1234abcd1234abcd12340", // longer than 40 characters
|
||||
Expected: nil,
|
||||
},
|
||||
{
|
||||
Input: "test go-gitea/gitea@abcd1234 test",
|
||||
Expected: &RenderizableReference{
|
||||
Owner: "go-gitea",
|
||||
Name: "gitea",
|
||||
CommitSha: "abcd1234",
|
||||
RefLocation: &RefSpan{Start: 4, End: 29},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
found, ref := FindRenderizableCommitCrossReference(c.Input)
|
||||
assert.Equal(t, ref != nil, found)
|
||||
assert.Equal(t, c.Expected, ref)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegExp_mentionPattern(t *testing.T) {
|
||||
trueTestCases := []struct {
|
||||
pat string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue