Skip to content

Commit 3fb1a2e

Browse files
committed
Remove hard code for min interval in installations
Signed-off-by: Maxim Sukharev <[email protected]>
1 parent 1f6ce46 commit 3fb1a2e

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

cmd/lookoutd/common.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func (c *lookoutdCommand) initProviderGithubApp(conf Config) error {
213213
if conf.Providers.Github.AppID == 0 {
214214
return fmt.Errorf("missing GitHub App ID in config")
215215
}
216+
216217
installationsSyncInterval := defaultInstallationsSyncInterval
217218
if conf.Providers.Github.InstallationSyncInterval != "" {
218219
var err error
@@ -225,7 +226,7 @@ func (c *lookoutdCommand) initProviderGithubApp(conf Config) error {
225226
cache := cache.NewValidableCache(diskcache.New("/tmp/github"))
226227
insts, err := github.NewInstallations(
227228
conf.Providers.Github.AppID, conf.Providers.Github.PrivateKey,
228-
cache, conf.Timeout.GithubRequest)
229+
cache, conf.Providers.Github.WatchMinInterval, conf.Timeout.GithubRequest)
229230
if err != nil {
230231
return err
231232
}

config.yml.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ providers:
1010
# app_id: 1234
1111
# private_key: ./key.pem
1212
# installation_sync_interval: 1h
13+
# watch_min_interval: 2s
1314

1415
repositories:
1516
- url: github.com/src-d/lookout

docs/configuration.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ providers:
2626
# app_id: 1234
2727
# private_key: ./key.pem
2828
# installation_sync_interval: 1h
29+
# watch_min_interval: 2s
2930
```
3031

3132
`comment_footer` key defines a format-string that will be used for custom messages for every message posted on GitHub; see how to [add a custom message to the posted comments](#custom-footer)
@@ -64,12 +65,14 @@ providers:
6465
app_id: 1234
6566
private_key: ./key.pem
6667
installation_sync_interval: 1h
68+
watch_min_interval: 10s
6769
```
6870
6971
When the GitHub App authentication method is used, the repositories to analyze are retrieved automatically from the GitHub installations, so `repositories` list from `config.yml` is ignored.
7072

71-
The update interval is defined by `installation_sync_interval`.
73+
The update interval to discover new installations and repositories is defined by `installation_sync_interval`.
7274

75+
The minimum watch interval to discover new pull requests and push events is defined by `watch_min_interval`.
7376

7477
## Repositories
7578

provider/github/installations.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import (
2020

2121
// Installations keeps github installations and allows to sync them
2222
type Installations struct {
23-
appID int
24-
privateKey string
25-
appClient *github.Client
23+
appID int
24+
privateKey string
25+
appClient *github.Client
26+
watchMinInterval string
2627

2728
cache *cache.ValidableCache
2829
clientTimeout time.Duration
@@ -37,6 +38,7 @@ type Installations struct {
3738
func NewInstallations(
3839
appID int, privateKey string,
3940
cache *cache.ValidableCache,
41+
watchMinInterval string,
4042
clientTimeout time.Duration,
4143
) (*Installations, error) {
4244
// Use App authorization to list installations
@@ -55,13 +57,14 @@ func NewInstallations(
5557
log.Infof("authorized as GitHub application %q, ID %v", app.GetName(), app.GetID())
5658

5759
i := &Installations{
58-
appID: appID,
59-
privateKey: privateKey,
60-
appClient: appClient,
61-
cache: cache,
62-
clientTimeout: clientTimeout,
63-
clients: make(map[int64]*Client),
64-
Pool: NewClientPool(),
60+
appID: appID,
61+
privateKey: privateKey,
62+
appClient: appClient,
63+
watchMinInterval: watchMinInterval,
64+
cache: cache,
65+
clientTimeout: clientTimeout,
66+
clients: make(map[int64]*Client),
67+
Pool: NewClientPool(),
6568
}
6669

6770
return i, nil
@@ -168,9 +171,7 @@ func (t *Installations) createClient(installationID int64) (*Client, error) {
168171
}
169172
}
170173

171-
// TODO (carlosms): hardcoded, take from config
172-
watchMinInterval := ""
173-
return NewClient(itr, t.cache, watchMinInterval, gitAuth, t.clientTimeout), nil
174+
return NewClient(itr, t.cache, t.watchMinInterval, gitAuth, t.clientTimeout), nil
174175
}
175176

176177
func (t *Installations) getRepos(iClient *Client) ([]*lookout.RepositoryInfo, error) {

provider/github/watcher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type ProviderConfig struct {
2222
PrivateKey string `yaml:"private_key"`
2323
AppID int `yaml:"app_id"`
2424
InstallationSyncInterval string `yaml:"installation_sync_interval"`
25+
WatchMinInterval string `yaml:"watch_min_interval"`
2526
}
2627

2728
// don't call github more often than

0 commit comments

Comments
 (0)