@@ -172,23 +172,110 @@ def contributors() -> None:
172
172
else :
173
173
print ('No contributors found.' )
174
174
175
- def new_contributors () -> None :
175
+ def new_contributors (new_date : str ) -> None :
176
176
"""
177
- Lists contributors sorted by email.
177
+ Lists all new contributors to a repo since the specified date.
178
+
179
+ Args:
180
+ new_date (str): Cutoff date for being considered "new" in 'YYYY-MM-DD' format.
181
+
182
+ Returns:
183
+ None
178
184
"""
179
-
180
- cmd = ['git' , 'log' , '--format=%aN|%aE' ]
185
+
186
+ # Attempt to handle date in YYYY-MM-DD format
187
+ try :
188
+ new_date_dt = datetime .strptime (new_date , '%Y-%m-%d' )
189
+ new_date_ts = int (new_date_dt .timestamp ())
190
+ except ValueError :
191
+ print ("Invalid date format. Please use YYYY-MM-DD." )
192
+ return
193
+
194
+ # User adjustable vars
195
+ # TODO: Fix these later on
196
+ merges = "--no-merges"
197
+ since = "" # Include the world for now
198
+ until = ""
199
+ log_options = ""
200
+ pathspec = ""
201
+
202
+ # Original command:
203
+ # git -c log.showSignature=false log --use-mailmap $_merges \
204
+ # "$_since" "$_until" --format='%aE' $_log_options \
205
+ # $_pathspec | sort -u
206
+ cmd = [
207
+ 'git' ,
208
+ '-c' , 'log.showSignature=false' ,
209
+ 'log' ,
210
+ '--use-mailmap' ,
211
+ merges ,
212
+ since ,
213
+ until ,
214
+ '--format=%aE|%at' ,
215
+ log_options ,
216
+ pathspec
217
+ ]
218
+
219
+ # Remove any empty strings from the command to prevent Git misinterpretation
220
+ # Needed when we start messing with datetime stuff
221
+ cmd = [arg for arg in cmd if arg ]
222
+
181
223
output = run_git_command (cmd )
182
224
if output :
183
- contributors = set (output .split ('\n ' ))
184
- new_contributors_list = sorted (contributors , key = lambda x : x .split ('|' )[1 ])
185
- print ("New contributors:" )
186
- for contributor in new_contributors_list :
225
+ # Dictionary to store the earliest commit timestamp for each contributor
226
+ contributors_dict = {}
227
+
228
+ # Process each line of the Git output
229
+ for line in output .split ('\n ' ):
187
230
try :
188
- name , email = contributor .split ('|' )
189
- print (f"{ name } <{ email } >" )
231
+ email , timestamp = line .split ('|' )
232
+ timestamp = int (timestamp )
233
+ # If the contributor is not in the dictionary or the current timestamp is earlier
234
+ if email not in contributors_dict or timestamp < contributors_dict [email ]:
235
+ contributors_dict [email ] = timestamp
190
236
except ValueError :
191
- continue # Skip lines that don't match the expected format
237
+ continue # Skip lines that don't match format
238
+
239
+ # List to hold new contributors
240
+ new_contributors_list = []
241
+
242
+ # Iterate over contributors to find those who are new since 'new_date'
243
+ for email , first_commit_ts in contributors_dict .items ():
244
+ if first_commit_ts >= new_date_ts :
245
+ # Retrieve the contributor's name
246
+ # Original command:
247
+ # git -c log.showSignature=false log --author="$c" \
248
+ # --reverse --use-mailmap $_merges "$_since" "$_until" \
249
+ # --format='%at' $_log_options $_pathspec | head -n 1
250
+ name_cmd = [
251
+ 'git' ,
252
+ '-c' , 'log.showSignature=false' ,
253
+ 'log' ,
254
+ '--use-mailmap' ,
255
+ '--format=%aN' ,
256
+ '--author=' + email ,
257
+ '-n' , '1'
258
+ ]
259
+
260
+ # Grab name + email if we can. Otherwise, just grab email
261
+ name = run_git_command (name_cmd )
262
+ if name :
263
+ new_contributors_list .append ((name , email ))
264
+ else :
265
+ new_contributors_list .append (("" , email ))
266
+
267
+ # Sort the list alphabetically by name to match the original
268
+ # and print all of this out
269
+ if new_contributors_list :
270
+ print (f"New contributors since { new_date } :\n " )
271
+ sorted_new_contributors = sorted (new_contributors_list , key = lambda x : (x [0 ], x [1 ]))
272
+ for idx , (name , email ) in enumerate (sorted_new_contributors , 1 ):
273
+ if name :
274
+ print (f"{ name } <{ email } >" )
275
+ else :
276
+ print (f"<{ email } >" )
277
+ else :
278
+ print ("No new contributors found since the specified date." )
192
279
else :
193
280
print ('No contributors found.' )
194
281
0 commit comments