Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options to speficy defaults for poll frequence and vcs #181

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config-example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"max-concurrent-indexers" : 2,
"dbpath" : "data",
"repo-defaults" : {
"ms-between-poll" : 30000,
"vcs" : "git"
},
"repos" : {
"SomeGitRepo" : {
"url" : "https://www.github.com/YourOrganization/RepoOne.git"
Expand Down
29 changes: 25 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ type Repo struct {
EnablePushUpdates *bool `json:"enable-push-updates"`
}

type RepoDefaults struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the struct should be singular. So, we can have RepoDefaultSetting or RepoDefault here.

MsBetweenPolls int `json:"ms-between-poll"`
Vcs string `json:"vcs"`
}

// Used for interpreting the config value for fields that use *bool. If a value
// is present, that value is returned. Otherwise, the default is returned.
func optionToBool(val *bool, def bool) bool {
Expand All @@ -56,6 +61,7 @@ type Config struct {
DbPath string `json:"dbpath"`
Repos map[string]*Repo `json:"repos"`
MaxConcurrentIndexers int `json:"max-concurrent-indexers"`
RepoDefault *RepoDefaults `json:"repo-defaults"`
}

// SecretMessage is just like json.RawMessage but it will not
Expand Down Expand Up @@ -87,13 +93,13 @@ func (r *Repo) VcsConfig() []byte {
}

// Populate missing config values with default values.
func initRepo(r *Repo) {
func initRepo(r *Repo, d *RepoDefaults) {
if r.MsBetweenPolls == 0 {
r.MsBetweenPolls = defaultMsBetweenPoll
r.MsBetweenPolls = d.MsBetweenPolls
}

if r.Vcs == "" {
r.Vcs = defaultVcs
r.Vcs = d.Vcs
}

if r.UrlPattern == nil {
Expand Down Expand Up @@ -139,8 +145,23 @@ func (c *Config) LoadFromFile(filename string) error {
c.DbPath = path
}

if c.RepoDefault == nil {
c.RepoDefault = &RepoDefaults{
MsBetweenPolls: defaultMsBetweenPoll,
Vcs: defaultVcs,
}
} else {
if c.RepoDefault.MsBetweenPolls == 0 {
c.RepoDefault.MsBetweenPolls = defaultMsBetweenPoll
}

if c.RepoDefault.Vcs == "" {
c.RepoDefault.Vcs = defaultVcs
}
}

for _, repo := range c.Repos {
initRepo(repo)
initRepo(repo, c.RepoDefault)
}

initConfig(c)
Expand Down