Skip to content

Commit

Permalink
Search the commit's Subject and Body for related items
Browse files Browse the repository at this point in the history
  • Loading branch information
aesterline committed Oct 2, 2017
1 parent afbab68 commit db1f6d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
7 changes: 5 additions & 2 deletions git/related.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package git

import (
"github.com/HeySquirrel/tribe/config"
"fmt"
"regexp"
"sort"
"time"

"github.com/HeySquirrel/tribe/config"
)

type Contributor struct {
Expand Down Expand Up @@ -34,7 +36,8 @@ func (commits *Commits) RelatedItems() []string {

for _, commit := range *commits {
for _, re := range config.Matchers() {
found := re.FindAllString(commit.Subject, -1)
search := fmt.Sprintf("%s %s", commit.Subject, commit.Body)
found := re.FindAllString(search, -1)
if found != nil {
for _, item := range found {
_, ok := seen[item]
Expand Down
17 changes: 9 additions & 8 deletions git/related_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ import (
func TestRelatedItems(t *testing.T) {
cases := []struct {
Subject string
Body string
Expected []string
}{
{"HIL-123_team_coolness- scope coolness by user", []string{"HIL-123"}},
{"HIL-345: Make something cool", []string{"HIL-345"}},
{"HIL-987: user is uncool", []string{"HIL-987"}},
{"HIL-654: Remove HIL-872_uncool_users", []string{"HIL-654", "HIL-872"}},
{"No related work", []string{}},
{"HIL-123_team_coolness- scope coolness by user", "", []string{"HIL-123"}},
{"HIL-345: Make something cool", "", []string{"HIL-345"}},
{"HIL-987: user is uncool", "", []string{"HIL-987"}},
{"HIL-654: Remove HIL-872_uncool_users", "", []string{"HIL-654", "HIL-872"}},
{"No related work", "", []string{}},
{"No related work in the subject", "Issue: HIL-19200", []string{"HIL-19200"}},
}

for _, c := range cases {
commit := new(Commit)
commit.Subject = c.Subject

commit := &Commit{Subject: c.Subject, Body: c.Body}
entries := Commits{commit}

actual := entries.RelatedItems()

if len(actual) != len(c.Expected) {
Expand Down

0 comments on commit db1f6d7

Please sign in to comment.