Skip to content

Commit 0dfaea3

Browse files
author
Vladimir Smirnov
committed
Fix issue when regex could be empty in some cases (caused filter to stop working)
1 parent 6488b09 commit 0dfaea3

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ CHANGELOG
1919
- [Feature] Allow to request forceUpdate for the specific repo (for debug purposes). Currently can be done only by Admin Username that's specified in config
2020
- [Code] Refactor feed process a bit
2121
- [Code] Update all bundled libraries to newest versions
22+
- [Fix] Fix an error that made only one filter per repo working
2223

2324
**0.0.1**
2425
- [Improvement] Initial release

feeds/process.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func UpdateFeeds(feeds []*Feed) {
3636
defer configs.Config.Unlock()
3737

3838
for _, feed := range feeds {
39+
logger = logger.With(
40+
zap.Int("id", feed.Id),
41+
zap.String("repo", feed.Repo),
42+
)
43+
3944
logger.Debug("will initialize feeds",
4045
zap.Any("feed", feed),
4146
)
@@ -46,16 +51,18 @@ func UpdateFeeds(feeds []*Feed) {
4651
break
4752
}
4853
}
49-
if cfg == nil {
50-
re, err := regexp.Compile(feed.Filter)
51-
if err != nil {
52-
logger.Error("failed to compile regex",
53-
zap.String("filter", feed.Filter),
54-
zap.Error(err),
55-
)
56-
continue
57-
}
5854

55+
re, err := regexp.Compile(feed.Filter)
56+
if err != nil {
57+
logger.Error("failed to compile regex",
58+
zap.String("filter", feed.Filter),
59+
zap.Error(err),
60+
)
61+
continue
62+
}
63+
64+
// We were unable to find relevant configuration for this particular feed, we need to create it
65+
if cfg == nil {
5966
feed.cfg = configs.FeedsConfig{
6067
Repo: feed.Repo,
6168
PollingInterval: configs.Config.PollingInterval,
@@ -70,10 +77,13 @@ func UpdateFeeds(feeds []*Feed) {
7077
configs.Config.FeedsConfig = append(configs.Config.FeedsConfig, &feed.cfg)
7178
continue
7279
}
80+
81+
// Configuration was found, but this filter is new, we need to append it to existing repo
7382
cfg.Filters = append(cfg.Filters, configs.FiltersConfig{
7483
Name: feed.Name,
7584
Filter: feed.Filter,
7685
MessagePattern: feed.MessagePattern,
86+
FilterRegex: re,
7787
})
7888
}
7989

@@ -82,6 +92,7 @@ func UpdateFeeds(feeds []*Feed) {
8292
)
8393

8494
for _, feed := range feeds {
95+
// keep track of feeds that are currently running
8596
runningFeeds = append(runningFeeds, feed)
8697
go func(f *Feed) {
8798
f.ProcessFeed()
@@ -165,8 +176,6 @@ func (f *Feed) processSingleItem(cfg *configs.FeedsConfig, url string, item *gof
165176
continue
166177
}
167178

168-
169-
170179
if cfg.Filters[i].FilterRegex.MatchString(item.Title) {
171180
logger.Debug("filter matched")
172181
contentTruncated := false
@@ -208,7 +217,7 @@ func (f *Feed) processSingleItem(cfg *configs.FeedsConfig, url string, item *gof
208217
)
209218
continue
210219
}
211-
f.logger.Debug("notifications",
220+
logger.Debug("notifications",
212221
zap.Strings("methods", methods),
213222
)
214223
for _, m := range methods {

0 commit comments

Comments
 (0)