Skip to content

Commit e7906ed

Browse files
author
Codex
committed
Count fetched MR/PR items in /check missing logic
1 parent 8d5a318 commit e7906ed

2 files changed

Lines changed: 69 additions & 3 deletions

File tree

internal/integrations/slack/slack.go

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,14 @@ func handleListMissing(api *slack.Client, db *sql.DB, cfg Config, cmd slack.Slas
867867
}
868868

869869
monday, nextMonday := ReportWeekRange(cfg, time.Now().In(cfg.Location))
870+
weekItems, err := GetItemsByDateRange(db, monday, nextMonday)
871+
if err != nil {
872+
postEphemeral(api, cmd, fmt.Sprintf("Error loading items: %v", err))
873+
log.Printf("list-missing load error: %v", err)
874+
return
875+
}
876+
reportedAuthors := uniqueReportedAuthors(weekItems)
877+
870878
reportedAuthorIDs, err := GetSlackAuthorIDsByDateRange(db, monday, nextMonday)
871879
if err != nil {
872880
postEphemeral(api, cmd, fmt.Sprintf("Error loading items: %v", err))
@@ -881,11 +889,22 @@ func handleListMissing(api *slack.Client, db *sql.DB, cfg Config, cmd slack.Slas
881889
var missing []missingMember
882890
var missingIDs []string
883891
for _, uid := range memberIDs {
884-
if reportedAuthorIDs[uid] {
892+
user, err := api.GetUserInfo(uid)
893+
nameCandidates := []string{uid}
894+
if err == nil {
895+
if user.Profile.DisplayName != "" {
896+
nameCandidates = append(nameCandidates, user.Profile.DisplayName)
897+
}
898+
if user.RealName != "" {
899+
nameCandidates = append(nameCandidates, user.RealName)
900+
}
901+
if user.Name != "" {
902+
nameCandidates = append(nameCandidates, user.Name)
903+
}
904+
}
905+
if memberReportedThisWeek(uid, nameCandidates, reportedAuthorIDs, reportedAuthors) {
885906
continue
886907
}
887-
888-
user, err := api.GetUserInfo(uid)
889908
if err != nil {
890909
missing = append(missing, missingMember{display: uid, userID: uid})
891910
missingIDs = append(missingIDs, uid)
@@ -963,6 +982,38 @@ func handleListMissing(api *slack.Client, db *sql.DB, cfg Config, cmd slack.Slas
963982
log.Printf("list-missing count=%d", len(missing)+len(unresolved))
964983
}
965984

985+
func uniqueReportedAuthors(items []WorkItem) []string {
986+
seen := make(map[string]bool)
987+
var out []string
988+
for _, item := range items {
989+
author := strings.TrimSpace(item.Author)
990+
if author == "" || seen[author] {
991+
continue
992+
}
993+
seen[author] = true
994+
out = append(out, author)
995+
}
996+
return out
997+
}
998+
999+
func memberReportedThisWeek(userID string, nameCandidates []string, reportedAuthorIDs map[string]bool, reportedAuthors []string) bool {
1000+
if reportedAuthorIDs[userID] {
1001+
return true
1002+
}
1003+
for _, candidate := range nameCandidates {
1004+
candidate = strings.TrimSpace(candidate)
1005+
if candidate == "" {
1006+
continue
1007+
}
1008+
for _, author := range reportedAuthors {
1009+
if strings.EqualFold(candidate, author) || nameMatches(candidate, author) || nameMatches(author, candidate) {
1010+
return true
1011+
}
1012+
}
1013+
}
1014+
return false
1015+
}
1016+
9661017
func postEphemeral(api *slack.Client, cmd slack.SlashCommand, text string) {
9671018
postEphemeralTo(api, cmd.ChannelID, cmd.UserID, text)
9681019
}

internal/integrations/slack/slack_logic_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ func TestFormatItemDescriptionForList(t *testing.T) {
183183
}
184184
}
185185

186+
func TestMemberReportedThisWeek(t *testing.T) {
187+
reportedIDs := map[string]bool{"U123": true}
188+
reportedAuthors := []string{"Alex Rivera", "Jordan Patel"}
189+
190+
if !memberReportedThisWeek("U123", []string{"Alex Rivera"}, reportedIDs, reportedAuthors) {
191+
t.Fatal("expected member to be reported when author_id is present")
192+
}
193+
if !memberReportedThisWeek("U999", []string{"Alex"}, map[string]bool{}, reportedAuthors) {
194+
t.Fatal("expected fuzzy name match against fetched author to count as reported")
195+
}
196+
if memberReportedThisWeek("U999", []string{"Taylor"}, map[string]bool{}, reportedAuthors) {
197+
t.Fatal("expected unmatched member name to be considered missing")
198+
}
199+
}
200+
186201
func TestDeriveBossReportFromTeamReport_FileExists(t *testing.T) {
187202
dir := t.TempDir()
188203
teamName := "TestTeam"

0 commit comments

Comments
 (0)