From cd0c04e4d4168e5d13a26602e9c07f51e47a34b3 Mon Sep 17 00:00:00 2001 From: Jeff Neel <10672501+jeff350@users.noreply.github.com> Date: Mon, 19 Feb 2024 03:15:22 -0600 Subject: [PATCH] contributor: exclude specific authors (#47) There are times where some authors, such as bots, should not be included in the list of contributors. --- cmd/contributor.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/contributor.go b/cmd/contributor.go index ec18992..4b3cb1d 100644 --- a/cmd/contributor.go +++ b/cmd/contributor.go @@ -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 @@ -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. @@ -113,6 +115,8 @@ func contributorRun() error { i = i + 1 } + contributors = filterIgnoredContributors(contributors) + if err := composeByOrder(contributors); err != nil { return err } @@ -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 +}