From 6d09db7032305a994f43df331ca9f24f20a614df Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 7 Feb 2018 23:45:35 +0100 Subject: [PATCH] Add option to expand repo to contain all infos Signed-off-by: Knut Ahlers --- main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main.go b/main.go index 6844435..90fb10c 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( var ( cfg = struct { + ExpandMatches bool `flag:"expand-matches" default:"false" description:"Replace matched repos with their full version"` Filters []string `flag:"filter,f" default:"" description:"Filters to match the repos against"` GithubToken string `flag:"token" default:"" env:"GITHUB_TOKEN" description:"Token to access Github API"` LogLevel string `flag:"log-level" default:"info" description:"Log level for output (debug, info, warn, error, fatal)"` @@ -100,6 +101,12 @@ func main() { continue } + if cfg.ExpandMatches { + if err := expandRepo(repo); err != nil { + log.WithError(err).Error("Unable to expand repo") + } + } + log.WithFields(log.Fields{ "repo": *repo.FullName, "private": *repo.Private, @@ -113,6 +120,17 @@ func main() { } } +func expandRepo(repo *github.Repository) error { + ctx := context.Background() + r, _, err := client.Repositories.Get(ctx, *repo.Owner.Login, *repo.Name) + if err != nil { + return err + } + + repo = r + return nil +} + func fetchRepos() ([]*github.Repository, error) { var ( ctx = context.Background()