@@ -31,21 +31,30 @@ import (
3131 "github.com/kubernetes-sigs/maintainers/pkg/utils"
3232)
3333
34- var dryRun , skipGH , skipDS bool
35- var repositoryDS , repositoryGH , periodDS string
36- var includes , excludes []string
37- var excludeFiles []string
34+ type options struct {
35+ dryRun bool
36+ skipDS bool
37+ skipGH bool
38+ repositoryDS string
39+ repositoryGH string
40+ periodDS string
41+ includes []string
42+ excludes []string
43+ excludeFiles []string
44+ }
45+
46+ var o options
3847
3948func init () {
40- pruneCmd .Flags ().StringSliceVar (& includes , "include" , []string {}, "add these comma-separated list of users to prune from OWNERS" )
41- pruneCmd .Flags ().StringSliceVar (& excludes , "exclude" , []string {}, "do not prune these comma-separated list of users from OWNERS" )
42- pruneCmd .Flags ().BoolVar (& dryRun , "dryrun" , true , "do not modify any files" )
43- pruneCmd .Flags ().BoolVar (& skipGH , "skip-github" , false , "skip github PR count check" )
44- pruneCmd .Flags ().BoolVar (& skipDS , "skip-devstats" , false , "skip devstat contributions count check" )
45- pruneCmd .Flags ().StringVar (& repositoryDS , "repository-devstats" , "kubernetes/kubernetes" , "defaults to \" kubernetes/kubernetes\" repository" )
46- pruneCmd .Flags ().StringVar (& repositoryGH , "repository-github" , "kubernetes/kubernetes" , "defaults to \" kubernetes/kubernetes\" repository" )
47- pruneCmd .Flags ().StringVar (& periodDS , "period-devstats" , "y" , "one of \" y\" (year) \" q\" (quarter) \" m\" (month) " )
48- pruneCmd .Flags ().StringSliceVar (& excludeFiles , "exclude-files" , []string {}, "do not update these OWNERS files" )
49+ pruneCmd .Flags ().StringSliceVar (& o . includes , "include" , []string {}, "add these comma-separated list of users to prune from OWNERS" )
50+ pruneCmd .Flags ().StringSliceVar (& o . excludes , "exclude" , []string {}, "do not prune these comma-separated list of users from OWNERS" )
51+ pruneCmd .Flags ().BoolVar (& o . dryRun , "dryrun" , true , "do not modify any files" )
52+ pruneCmd .Flags ().BoolVar (& o . skipGH , "skip-github" , false , "skip github PR count check" )
53+ pruneCmd .Flags ().BoolVar (& o . skipDS , "skip-devstats" , false , "skip devstat contributions count check" )
54+ pruneCmd .Flags ().StringVar (& o . repositoryDS , "repository-devstats" , "kubernetes/kubernetes" , "defaults to \" kubernetes/kubernetes\" repository" )
55+ pruneCmd .Flags ().StringVar (& o . repositoryGH , "repository-github" , "kubernetes/kubernetes" , "defaults to \" kubernetes/kubernetes\" repository" )
56+ pruneCmd .Flags ().StringVar (& o . periodDS , "period-devstats" , "y" , "one of \" y\" (year) \" q\" (quarter) \" m\" (month) " )
57+ pruneCmd .Flags ().StringSliceVar (& o . excludeFiles , "exclude-files" , []string {}, "do not update these OWNERS files" )
4958 rootCmd .CompletionOptions .DisableDefaultCmd = true
5059 pruneCmd .SilenceErrors = true
5160 rootCmd .AddCommand (pruneCmd )
@@ -76,13 +85,13 @@ var pruneCmd = &cobra.Command{
7685
7786 var ownerContribs []utils.Contribution
7887
79- if ! skipDS {
80- contribs , err := utils .GetContributionsForAYear (repositoryDS , periodDS )
88+ if ! o . skipDS {
89+ contribs , err := utils .GetContributionsForAYear (o . repositoryDS , o . periodDS )
8190 if err != nil {
8291 return err
8392 }
8493 if len (contribs ) == 0 {
85- panic ("unable to find any contributions in repository : " + repositoryDS )
94+ panic ("unable to find any contributions in repository : " + o . repositoryDS )
8695 }
8796 for _ , id := range uniqueUsers {
8897 for _ , item := range contribs {
@@ -115,7 +124,7 @@ var pruneCmd = &cobra.Command{
115124 }
116125
117126 var lowPRComments []string
118- if ! skipGH {
127+ if ! o . skipGH {
119128 lowPRComments = fetchGithubPRCommentCounts (ownerContribs )
120129 }
121130
@@ -125,7 +134,7 @@ var pruneCmd = &cobra.Command{
125134 ownerContribs [i ].CommentCount > ownerContribs [j ].CommentCount
126135 })
127136
128- fmt .Printf ("\n \n >>>>> Contributions from %s devstats repo and %s github repo : %d\n " , repositoryDS , repositoryGH , len (ownerContribs ))
137+ fmt .Printf ("\n \n >>>>> Contributions from %s devstats repo and %s github repo : %d\n " , o . repositoryDS , o . repositoryGH , len (ownerContribs ))
129138 fmt .Printf (">>>>> GitHub ID : Devstats contrib count : GitHub PR comment count\n " )
130139 for _ , item := range ownerContribs {
131140 if item .ID != item .Alias {
@@ -137,22 +146,22 @@ var pruneCmd = &cobra.Command{
137146
138147 missingIDs := userIDs .List ()
139148 sort .Strings (missingIDs )
140- if ! skipDS {
141- fmt .Printf ("\n \n >>>>> Missing Contributions in %s (devstats == 0): %d\n " , repositoryDS , len (missingIDs ))
149+ if ! o . skipDS {
150+ fmt .Printf ("\n \n >>>>> Missing Contributions in %s (devstats == 0): %d\n " , o . repositoryDS , len (missingIDs ))
142151 for _ , id := range missingIDs {
143152 fmt .Printf ("%s\n " , id )
144153 }
145154 }
146155
147- if ! skipGH {
156+ if ! o . skipGH {
148157 fmt .Printf ("\n \n >>>>> Low reviews/approvals in %s (GH pr comments <= 10 && devstats <=20): %d\n " ,
149- repositoryGH , len (lowPRComments ))
158+ o . repositoryGH , len (lowPRComments ))
150159 for _ , id := range lowPRComments {
151160 fmt .Printf ("%s\n " , id )
152161 }
153162 }
154163
155- if ! dryRun {
164+ if ! o . dryRun {
156165 err = fixupOwnersFiles (files , missingIDs , lowPRComments )
157166 if err != nil {
158167 return err
@@ -170,11 +179,11 @@ func fetchGithubPRCommentCounts(ownerContribs []utils.Contribution) []string {
170179 for count , item := range ownerContribs {
171180 commentCount = - 1
172181 var err error
173- commentCount , err = utils .FetchPRCommentCount (item .ID , repositoryGH )
182+ commentCount , err = utils .FetchPRCommentCount (item .ID , o . repositoryGH )
174183 for commentCount == - 1 && err == nil {
175184 fmt .Printf ("." )
176185 time .Sleep (5 * time .Second )
177- commentCount , err = utils .FetchPRCommentCount (item .ID , repositoryGH )
186+ commentCount , err = utils .FetchPRCommentCount (item .ID , o . repositoryGH )
178187 }
179188 if item .ContribCount <= 20 && commentCount <= 10 {
180189 lowPRComments = append (lowPRComments , item .ID )
@@ -192,12 +201,12 @@ func fixupOwnersFiles(files []string, missingIDs []string, lowPRComments []strin
192201
193202 userIDs .Insert (missingIDs ... )
194203 userIDs .Insert (lowPRComments ... )
195- userIDs .Insert (includes ... )
196- userIDs .Delete (excludes ... )
204+ userIDs .Insert (o . includes ... )
205+ userIDs .Delete (o . excludes ... )
197206
198207 list := userIDs .List ()
199208 for _ , path := range files {
200- if isExcludedPath (path , excludeFiles ) {
209+ if isExcludedPath (path , o . excludeFiles ) {
201210 continue
202211 }
203212 err := utils .RemoveUserFromOWNERS (path , list )
0 commit comments