Skip to content

Commit

Permalink
feat: Add filtering for usernames on user-contributions
Browse files Browse the repository at this point in the history
Signed-off-by: John McBride <[email protected]>
  • Loading branch information
jpmcb committed Oct 26, 2023
1 parent f91ea5a commit d10c1ef
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions cmd/insights/user-contributions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ type userContributionsOptions struct {
// Repos is the array of git repository urls
Repos []string

// Users is the list of usernames to filter for
Users []string

// usersMap is a fast access set of usernames built from the Users string slice
usersMap map[string]struct{}

// FilePath is the path to yaml file containing an array of git repository urls
FilePath string

Expand Down Expand Up @@ -61,6 +67,7 @@ func NewUserContributionsCommand() *cobra.Command {

cmd.Flags().StringVarP(&opts.FilePath, constants.FlagNameFile, "f", "", "Path to yaml file containing an array of git repository urls")
cmd.Flags().Int32VarP(&opts.Period, constants.FlagNamePeriod, "p", 30, "Number of days, used for query filtering")
cmd.Flags().StringSliceVarP(&opts.Users, "users", "u", []string{}, "Inclusive comma separated list of GitHub usernames to filter for")

return cmd
}
Expand All @@ -71,6 +78,12 @@ func (opts *userContributionsOptions) run(ctx context.Context) error {
return err
}

opts.usersMap = make(map[string]struct{})
for _, username := range opts.Users {
// For fast access to list of users to filter out, uses an empty struct
opts.usersMap[username] = struct{}{}
}

var (
waitGroup = new(sync.WaitGroup)
errorChan = make(chan error, len(repositories))
Expand Down Expand Up @@ -257,12 +270,15 @@ func findAllUserContributionsInsights(ctx context.Context, opts *userContributio
}

for _, data := range dataPoints {
repoUserContributionsInsightGroup.Insights = append(repoUserContributionsInsightGroup.Insights, userContributionsInsights{
Login: *data.Login,
Commits: int(data.Commits),
PrsCreated: int(data.PrsCreated),
TotalContributions: int(data.Commits) + int(data.PrsCreated),
})
_, ok := opts.usersMap[*data.Login]
if len(opts.usersMap) == 0 || ok {
repoUserContributionsInsightGroup.Insights = append(repoUserContributionsInsightGroup.Insights, userContributionsInsights{
Login: *data.Login,
Commits: int(data.Commits),
PrsCreated: int(data.PrsCreated),
TotalContributions: int(data.Commits) + int(data.PrsCreated),
})
}
}

return repoUserContributionsInsightGroup, nil
Expand Down

0 comments on commit d10c1ef

Please sign in to comment.