Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.

Commit ca8c5e3

Browse files
Ajinkya Naharajinkyan83
authored andcommitted
DA-3256: Update logic for checking included repos
1 parent 3654879 commit ca8c5e3

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

fixtures/models.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ type Fixture struct {
1717
Type string `yaml:"type"`
1818
} `yaml:"flags"`
1919
Skip []string `yaml:"skip"`
20+
Only []string `yaml:"only"`
2021
SkipREs []*regexp.Regexp `yaml:"-"`
22+
OnlyREs []*regexp.Regexp `yaml:"-"`
2123
} `yaml:"endpoints"`
2224
Flags interface{} `yaml:"flags"`
2325
} `yaml:"projects,omitempty"`

fixtures/util.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func GetYamlFiles() []string {
6868
if err != nil {
6969
log.Printf("Error listing yaml files: %+v", err)
7070
}
71+
7172
return result
7273
}
7374

@@ -119,7 +120,7 @@ func ParseOrg(endPointName string) string {
119120
}
120121

121122
// GetGithubRepoList returns the list of repositories for a given endpoint
122-
func GetGithubRepoList(endPointName string, skipREs []*regexp.Regexp) ([]string, error) {
123+
func GetGithubRepoList(endPointName string, skipREs []*regexp.Regexp, onlyREs []*regexp.Regexp) ([]string, error) {
123124
token := os.Getenv("GITHUB_OAUTH_TOKEN")
124125
ctx := context.Background()
125126
ts := oauth2.StaticTokenSource(
@@ -147,10 +148,13 @@ func GetGithubRepoList(endPointName string, skipREs []*regexp.Regexp) ([]string,
147148
org := ParseOrg(endPointName)
148149
for _, repo := range repoList {
149150
if repo.Name != nil {
150-
name := org + "/" + *(repo.Name)
151-
if CheckSkipped(endPointName, skipREs, name) {
152-
repos = append(repos, *(repo.HTMLURL))
151+
name := "/" + org + "/" + *(repo.Name)
152+
included := CheckIncluded(endPointName, name, skipREs, onlyREs)
153+
if !included {
154+
continue
153155
}
156+
repos = append(repos, *(repo.HTMLURL))
157+
154158
}
155159
}
156160
}
@@ -162,15 +166,25 @@ func GetGithubRepoList(endPointName string, skipREs []*regexp.Regexp) ([]string,
162166
return repos, nil
163167
}
164168

165-
// CheckSkipped verifies whether a particular repo is in the skipped list or not.
166-
func CheckSkipped(endPointName string, skipREs []*regexp.Regexp, repo string) bool {
167-
included := true
169+
// CheckIncluded verifies whether a particular repo is in the skipped list or not.
170+
func CheckIncluded(endPointName string, repo string, skipREs []*regexp.Regexp, onlyREs []*regexp.Regexp) bool {
168171
for _, skipRE := range skipREs {
169172
if skipRE.MatchString(repo) {
170-
included = false
171173
log.Printf("%s: skipped %s (%v)\n", endPointName, repo, skipRE)
174+
return false
175+
}
176+
}
177+
if len(onlyREs) == 0 {
178+
return true
179+
}
180+
included := false
181+
for _, onlyRE := range onlyREs {
182+
if onlyRE.MatchString(repo) {
183+
log.Printf("%s: included %s (%v)\n", endPointName, repo, onlyRE)
184+
included = true
172185
break
173186
}
174187
}
188+
175189
return included
176190
}

0 commit comments

Comments
 (0)