-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding support for json output for orgs and repo
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
- Loading branch information
Showing
9 changed files
with
340 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
all: | ||
gofmt -s -w . | ||
go build -o org-stats | ||
go build -o codestats | ||
run: | ||
go run main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/DataDrake/cli-ng/v2/cmd" | ||
"github.com/vsoch/codestats/github" | ||
) | ||
|
||
// Args and flags | ||
type OrgArgs struct { | ||
Orgs []string `desc:"One or more GitHub organization names to parse."` | ||
} | ||
type OrgFlags struct { | ||
Pretty bool `long:"pretty" desc:"If printing to the terminal, print it pretty."` | ||
Pattern string `long:"pattern" desc:"Only include repos that match this regular expression."` | ||
} | ||
|
||
var Org = cmd.Sub{ | ||
Name: "org", | ||
Alias: "o", | ||
Short: "Generate stats (json) for org projects.", | ||
Flags: &OrgFlags{}, | ||
Args: &OrgArgs{}, | ||
Run: RunOrg, | ||
} | ||
|
||
func init() { | ||
cmd.Register(&Org) | ||
} | ||
|
||
func RunOrg(r *cmd.Root, c *cmd.Sub) { | ||
args := c.Args.(*OrgArgs) | ||
flags := c.Flags.(*OrgFlags) | ||
|
||
// a lookup of repo results by org | ||
results := map[string][]github.RepoResult{} | ||
for _, org := range args.Orgs { | ||
results[org] = github.GetOrgStats(org, flags.Pattern) | ||
} | ||
|
||
// Parse into json | ||
var outJson []byte | ||
if flags.Pretty { | ||
outJson, _ = json.MarshalIndent(results, "", " ") | ||
} else { | ||
outJson, _ = json.Marshal(results) | ||
} | ||
output := string(outJson) | ||
fmt.Printf(output) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/DataDrake/cli-ng/v2/cmd" | ||
"github.com/vsoch/codestats/github" | ||
) | ||
|
||
// Args and flags | ||
type RepoArgs struct { | ||
Repos []string `desc:"One or more GitHub repository names to parse."` | ||
} | ||
type RepoFlags struct { | ||
Pretty bool `long:"pretty" desc:"If printing to the terminal, print it pretty."` | ||
} | ||
|
||
var Repo = cmd.Sub{ | ||
Name: "repo", | ||
Alias: "r", | ||
Short: "Generate stats (json) for repositories.", | ||
Flags: &RepoFlags{}, | ||
Args: &RepoArgs{}, | ||
Run: RunRepo, | ||
} | ||
|
||
func init() { | ||
cmd.Register(&Repo) | ||
} | ||
|
||
func RunRepo(r *cmd.Root, c *cmd.Sub) { | ||
args := c.Args.(*RepoArgs) | ||
flags := c.Flags.(*RepoFlags) | ||
|
||
// a lookup of repo results by org | ||
results := map[string]github.RepoResult{} | ||
for _, repo := range args.Repos { | ||
results[repo] = github.GetRepoStats(repo) | ||
} | ||
|
||
// Parse into json | ||
var outJson []byte | ||
if flags.Pretty { | ||
outJson, _ = json.MarshalIndent(results, "", " ") | ||
} else { | ||
outJson, _ = json.Marshal(results) | ||
} | ||
output := string(outJson) | ||
fmt.Printf(output) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.