Skip to content

Commit

Permalink
contributor: exclude specific authors (#47)
Browse files Browse the repository at this point in the history
There are times where some authors, such as bots, should not be included in the list of contributors.
  • Loading branch information
jeff350 committed Feb 19, 2024
1 parent ad3d458 commit cd0c04e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/contributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
errNameOrEmailNotExists = errors.New("Couldn't get the name or email of one contributor")

order *string
ignoreContributors []string
)

// contributorCmd represents the contributor command
Expand All @@ -69,6 +70,7 @@ func init() {

order = contributorCmd.PersistentFlags().String(config.Order, orderCommit, "The order to compose Authors.md."+
"(commit)")
contributorCmd.PersistentFlags().StringSliceVar(&ignoreContributors, "ignore-contributors", nil, "List of contributors to ignore")
}

// contributorRun runs the real logic to generate AUTHORS.md.
Expand Down Expand Up @@ -113,6 +115,8 @@ func contributorRun() error {
i = i + 1
}

contributors = filterIgnoredContributors(contributors)

if err := composeByOrder(contributors); err != nil {
return err
}
Expand Down Expand Up @@ -166,3 +170,23 @@ func writeToFile(contributors []*github.Contributor) error {
}
return nil
}

// filterIgnoredContributors filters out contributors specified to be ignored.
func filterIgnoredContributors(contributors []*github.Contributor) []*github.Contributor {
var filteredContributors []*github.Contributor
ignoredMap := make(map[string]bool)

// Create a map for quick lookup
for _, contributor := range ignoreContributors {
ignoredMap[contributor] = true
}

// Filter contributors
for _, contributor := range contributors {
if !ignoredMap[*contributor.Login] {
filteredContributors = append(filteredContributors, contributor)
}
}

return filteredContributors
}

0 comments on commit cd0c04e

Please sign in to comment.