Merge pull request #322 from zricethezav/exclude-forks

exclude-forks gitlab and github
This commit is contained in:
Zachary Rice authored and GitHub committed 2020-01-19 12:41:07 -05:00
commit 4024faceab
4 files changed
+22 -5

No files matched your search

+1
View File
@@ -86,6 +86,7 @@ Application Options:
--org= organization to audit
--user= user to audit
--pr= pull/merge request url
--exclude-forks audit excludes forks
Help Options:
-h, --help Show this help message
+9 -1
View File
@@ -72,7 +72,15 @@ func (g *Github) Audit() {
_githubRepos, resp, err = g.client.Repositories.ListByOrg(ctx, g.manager.Opts.Organization,
&github.RepositoryListByOrgOptions{ListOptions: listOptions})
}
githubRepos = append(githubRepos, _githubRepos...)
for _, r := range _githubRepos {
if g.manager.Opts.ExcludeForks && r.GetFork() {
log.Debugf("excluding forked repo: %s", *r.Name)
continue
}
githubRepos = append(githubRepos, r)
}
if resp == nil {
break
+10 -3
View File
@@ -57,19 +57,26 @@ func (g *Gitlab) Audit() {
glOpts := &gitlab.ListProjectsOptions{
ListOptions: listOpts,
}
projects, resp, err = g.client.Projects.ListUserProjects(g.manager.Opts.User, glOpts)
_projects, resp, err = g.client.Projects.ListUserProjects(g.manager.Opts.User, glOpts)
} else if g.manager.Opts.Organization != "" {
glOpts := &gitlab.ListGroupProjectsOptions{
ListOptions: listOpts,
}
projects, resp, err = g.client.Groups.ListGroupProjects(g.manager.Opts.Organization, glOpts)
_projects, resp, err = g.client.Groups.ListGroupProjects(g.manager.Opts.Organization, glOpts)
}
if err != nil {
log.Error(err)
}
projects = append(projects, _projects...)
for _, p := range _projects {
if g.manager.Opts.ExcludeForks && p.ForkedFromProject != nil {
log.Debugf("excluding forked repo: %s", p.Name)
continue
}
projects = append(projects, p)
}
if resp == nil {
break
}
+2 -1
View File
@@ -57,8 +57,9 @@ type Options struct {
Host string `long:"host" description:"git hosting service like gitlab or github. Supported hosts include: Github, Gitlab"`
BaseURL string `long:"baseurl" description:"Base URL for API requests. Defaults to the public GitLab or GitHub API, but can be set to a domain endpoint to use with a self hosted server."`
Organization string `long:"org" description:"organization to audit"`
User string `long:"user" description:"user to audit"` //work
User string `long:"user" description:"user to audit"`
PullRequest string `long:"pr" description:"pull/merge request url"`
ExcludeForks bool `long:"exclude-forks" description:"audit excludes forks"`
}
// ParseOptions is responsible for parsing options passed in by cli. An Options struct