Skip to content

Commit

Permalink
Allow the "@" character when parse jira usernames (#925)
Browse files Browse the repository at this point in the history
* Allow the "@" character when parse jira usernames

* Added unit tests for `parseJIRAUsernamesFromText`
  • Loading branch information
korkoshko authored Apr 11, 2023
1 parent fcc1205 commit 55bc972
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func parseJIRAUsernamesFromText(text string) []string {
usernameMap := map[string]bool{}
usernames := []string{}

var re = regexp.MustCompile(`(?m)\[~([a-zA-Z0-9-_.:\+]+)\]`)
var re = regexp.MustCompile(`(?m)\[~([a-zA-Z0-9-_@.:\+]+)\]`)
for _, match := range re.FindAllString(text, -1) {
name := match[:len(match)-1]
name = name[2:]
Expand Down
36 changes: 36 additions & 0 deletions server/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestParseJIRAUsernamesFromText(t *testing.T) {
tcs := []struct {
Text string
Expected []string
}{
{Text: "[~]", Expected: []string{}},
{Text: "[~j]", Expected: []string{"j"}},
{Text: "[~jira]", Expected: []string{"jira"}},
{Text: "[~jira.user]", Expected: []string{"jira.user"}},
{Text: "[~jira_user]", Expected: []string{"jira_user"}},
{Text: "[~jira-user]", Expected: []string{"jira-user"}},
{Text: "[~jira:user]", Expected: []string{"jira:user"}},
{Text: "[~jira_user_3]", Expected: []string{"jira_user_3"}},
{Text: "[~jira-user-4]", Expected: []string{"jira-user-4"}},
{Text: "[~JiraUser5]", Expected: []string{"JiraUser5"}},
{Text: "[~jira-user+6]", Expected: []string{"jira-user+6"}},
{Text: "[~2023]", Expected: []string{"2023"}},
{Text: "[[email protected]]", Expected: []string{"[email protected]"}},
{Text: "[[email protected]]", Expected: []string{"[email protected]"}},
{Text: "[[email protected]] [[email protected]] [[email protected]]", Expected: []string{"[email protected]"}},
{Text: "[jira_incorrect_user]", Expected: []string{}},
{Text: "[~jira_user_reviewer], Hi! Can you review the PR from [~jira_user_contributor]? Thanks!", Expected: []string{"jira_user_reviewer", "jira_user_contributor"}},
}

for _, tc := range tcs {
assert.Equal(t, tc.Expected, parseJIRAUsernamesFromText(tc.Text))
}
}

0 comments on commit 55bc972

Please sign in to comment.