@@ -21,7 +21,7 @@ class Contributions < AbstractCommand
2121 MAX_PR_SEARCH = T . let ( 100 , Integer )
2222
2323 cmd_args do
24- usage_banner "`contributions` [`--user=`] [`--repositories=`] [`--from=`] [`--to=`] [`--csv`]"
24+ usage_banner "`contributions` [`--user=`] [`--repositories=`] [`--quarter=`] [`-- from=`] [`--to=`] [`--csv`]"
2525 description <<~EOS
2626 Summarise contributions to Homebrew repositories.
2727 EOS
@@ -40,6 +40,10 @@ class Contributions < AbstractCommand
4040 flag "--team=" ,
4141 description : "Specify the team to populate users from. " \
4242 "The first part of the team name will be used as the organisation."
43+ flag "--quarter=" ,
44+ description : "Quarter to search (1-4). " \
45+ "Omitting this flag searches the past year." \
46+ "If `--from` or `--to` are set, they take precedence."
4347 flag "--from=" ,
4448 description : "Date (ISO 8601 format) to start searching contributions. " \
4549 "Omitting this flag searches the past year."
@@ -62,8 +66,13 @@ def run
6266
6367 results = { }
6468 grand_totals = { }
65- from = args . from . presence || Date . today . prev_year . iso8601
66- to = args . to . presence || ( Date . today + 1 ) . iso8601
69+
70+ quarter = args . quarter . presence . to_i
71+ odie "Value for `--quarter` must be between 1 and 4." if args . quarter . present? && !quarter . between? ( 1 , 4 )
72+ from = args . from . presence || quarter_dates [ quarter ] &.first || Date . today . prev_year . iso8601
73+ to = args . to . presence || quarter_dates [ quarter ] &.last || ( Date . today + 1 ) . iso8601
74+ puts "Date range is #{ time_period ( from :, to :) } ." if args . verbose?
75+
6776 organisation = nil
6877
6978 users = if ( team = args . team . presence )
@@ -136,7 +145,7 @@ def run
136145 contributions_string = [
137146 "#{ username } contributed" ,
138147 *contributions . to_sentence ,
139- "#{ time_period ( from :, to : args . to ) } ." ,
148+ "#{ time_period ( from :, to :) } ." ,
140149 ] . join ( " " )
141150 if args . csv?
142151 $stderr. puts contributions_string
@@ -270,6 +279,21 @@ def total(results)
270279
271280 totals
272281 end
282+
283+ sig { returns ( T ::Hash [ Integer , T ::Array [ String ] ] ) }
284+ def quarter_dates
285+ # These aren't standard quarterly dates. We've chosen our own so that we
286+ # can use recent maintainer activity stats as part of checking
287+ # eligibility for expensed attendance at the AGM in February each year.
288+ current_year = Date . today . year
289+ last_year = current_year - 1
290+ {
291+ 1 => [ Date . new ( last_year , 9 , 1 ) . iso8601 , Date . new ( last_year , 12 , 1 ) . iso8601 ] ,
292+ 2 => [ Date . new ( last_year , 12 , 1 ) . iso8601 , Date . new ( current_year , 3 , 1 ) . iso8601 ] ,
293+ 3 => [ Date . new ( current_year , 3 , 1 ) . iso8601 , Date . new ( current_year , 6 , 1 ) . iso8601 ] ,
294+ 4 => [ Date . new ( current_year , 6 , 1 ) . iso8601 , Date . new ( current_year , 9 , 1 ) . iso8601 ] ,
295+ }
296+ end
273297 end
274298 end
275299end
0 commit comments