Skip to content

Commit

Permalink
Merge pull request #6 from opensourceways/hrz-930
Browse files Browse the repository at this point in the history
note bugfix
  • Loading branch information
shishupei authored Oct 18, 2024
2 parents e28ac5a + d3312d7 commit ba0c76c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions models/dto/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"encoding/json"
"reflect"
"regexp"
"strings"
"text/template"
"time"
Expand Down Expand Up @@ -128,6 +129,19 @@ func (raw *Raw) GetRelateUsers(event *CloudEvents) {
}
}

func extractMentions(note string) []string {
re := regexp.MustCompile(`@([a-zA-Z0-9_-]+)`)
matches := re.FindAllStringSubmatch(note, -1)

var mentions []string
for _, match := range matches {
if len(match) > 1 {
mentions = append(mentions, match[1]) // match[1] 是捕获组
}
}
return mentions
}

func (raw *Raw) getGiteeRelatedUsers(event *CloudEvents, sourceGroup string) []string {
lSourceGroup := strings.Split(sourceGroup, "/")
owner, repo := lSourceGroup[0], lSourceGroup[1]
Expand All @@ -142,6 +156,18 @@ func (raw *Raw) getGiteeRelatedUsers(event *CloudEvents, sourceGroup string) []s
switch giteeType {
case "pr", "push", "issue":
return allAdmins
case "note":
if noteEvent, ok := (*raw)["NoteEvent"].(map[string]interface{}); ok {
if note, ok := noteEvent["Note"].(string); ok {
return extractMentions(note)
} else {
logrus.Error("Note does not exist or is not a string")
return []string{}
}
} else {
logrus.Error("NoteEvent does not exist or is not a map")
return []string{}
}
default:
return []string{}
}
Expand Down

0 comments on commit ba0c76c

Please sign in to comment.