Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add filtering for usernames on user-contributions #60

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading