4141
4242import matplotlib .dates as mdates
4343import matplotlib .pyplot as plt
44+ import matplotlib .ticker as ticker
4445import pandas as pd
4546import requests
4647
@@ -157,10 +158,11 @@ def fetch_merged_prs(
157158 "Authentification refusée (401). Vérifiez votre GITHUB_TOKEN."
158159 ) from exc
159160 if status == 403 :
160- raise RuntimeError (
161+ print (
161162 "Accès refusé (403). Vous avez peut-être atteint la limite de "
162163 "l'API GitHub (60 requêtes/h sans token). Définissez GITHUB_TOKEN."
163- ) from exc
164+ )
165+ break
164166 if status == 404 :
165167 raise RuntimeError (
166168 f"Dépôt introuvable (404) : { owner } /{ repo } . "
@@ -288,9 +290,13 @@ def plot_bar(pivot: pd.DataFrame, title: str, output_path: pathlib.Path) -> None
288290 ax .xaxis .set_major_formatter (mdates .DateFormatter ("%Y-%m-%d" ))
289291 ax .xaxis .set_major_locator (mdates .WeekdayLocator (byweekday = mdates .MO , interval = 4 ))
290292 plt .xticks (rotation = 45 , ha = "right" )
291- ax .set_xlabel ("Semaine " )
292- ax .set_ylabel ("Nombre de PR fusionnées " )
293+ ax .set_xlabel ("Week " )
294+ ax .set_ylabel ("PR merged per week " )
293295 ax .set_title (title )
296+ ax .yaxis .set_major_locator (ticker .MultipleLocator (50 ))
297+ ax .yaxis .set_minor_locator (ticker .MultipleLocator (10 ))
298+ ax .grid (which = "major" )
299+ ax .grid (which = "minor" )
294300 ax .legend (loc = "upper left" , bbox_to_anchor = (1 , 1 ), title = "Auteur" )
295301 plt .tight_layout ()
296302 plt .savefig (output_path , dpi = 150 )
@@ -316,6 +322,10 @@ def plot_heatmap(pivot: pd.DataFrame, title: str, output_path: pathlib.Path) ->
316322 ax .set_title (title )
317323 ax .set_xlabel ("Semaine" )
318324 ax .set_ylabel ("Auteur" )
325+ ax .yaxis .set_major_locator (ticker .MultipleLocator (50 ))
326+ ax .yaxis .set_minor_locator (ticker .MultipleLocator (10 ))
327+ ax .grid (which = "major" )
328+ ax .grid (which = "minor" )
319329 plt .tight_layout ()
320330 plt .savefig (output_path , dpi = 150 )
321331 plt .close (fig )
@@ -330,17 +340,13 @@ def plot_lines_by_repo(
330340 Chaque dépôt est représenté par une ligne, ce qui permet de comparer
331341 visuellement l'activité entre dépôts.
332342 """
333- repo_weekly = (
334- weekly .groupby (["repo" , "week" ])["pr_count" ].sum ().reset_index ()
335- )
343+ repo_weekly = weekly .groupby (["repo" , "week" ])["pr_count" ].sum ().reset_index ()
336344 all_weeks = sorted (repo_weekly ["week" ].unique ())
337345
338346 fig , ax = plt .subplots (figsize = (14 , 5 ))
339347 for repo_name , grp in repo_weekly .groupby ("repo" ):
340348 grp_indexed = grp .set_index ("week" ).reindex (all_weeks , fill_value = 0 )
341- week_nums = mdates .date2num (
342- pd .to_datetime (grp_indexed .index ).to_pydatetime ()
343- )
349+ week_nums = mdates .date2num (pd .to_datetime (grp_indexed .index ).to_pydatetime ())
344350 ax .plot (
345351 week_nums ,
346352 grp_indexed ["pr_count" ].values ,
@@ -352,10 +358,14 @@ def plot_lines_by_repo(
352358 ax .xaxis .set_major_formatter (mdates .DateFormatter ("%Y-%m-%d" ))
353359 ax .xaxis .set_major_locator (mdates .WeekdayLocator (byweekday = mdates .MO , interval = 4 ))
354360 plt .xticks (rotation = 45 , ha = "right" )
355- ax .set_xlabel ("Semaine " )
356- ax .set_ylabel ("Nombre de PR fusionnées " )
361+ ax .set_xlabel ("Week " )
362+ ax .set_ylabel ("PR merged per week " )
357363 ax .set_title (title )
358364 ax .legend (loc = "upper left" , bbox_to_anchor = (1 , 1 ), title = "Dépôt" )
365+ ax .yaxis .set_major_locator (ticker .MultipleLocator (50 ))
366+ ax .yaxis .set_minor_locator (ticker .MultipleLocator (10 ))
367+ ax .grid (which = "major" )
368+ ax .grid (which = "minor" )
359369 plt .tight_layout ()
360370 plt .savefig (output_path , dpi = 150 )
361371 plt .close (fig )
@@ -399,26 +409,21 @@ def main() -> None:
399409
400410 # 4. Graphiques combinés (toutes repos)
401411 print ("\n Génération des graphiques combinés…" )
402- plot_bar (
403- pivot_all ,
404- "PR fusionnées par semaine" ,
405- OUTPUT_DIR / "github_stat_pr_bar.png" ,
406- )
412+ plot_bar (pivot_all , "PR merged per week" , OUTPUT_DIR / "github_stat_pr_bar.png" )
407413 plot_heatmap (
408- pivot_all ,
409- "Heatmap des PR fusionnées" ,
410- OUTPUT_DIR / "github_stat_pr_heatmap.png" ,
414+ pivot_all , "Heatmap of merged PR" , OUTPUT_DIR / "github_stat_pr_heatmap.png"
411415 )
412416
413417 # 4b. Graphe en lignes : une ligne par dépôt, auteurs agrégés (données non filtrées)
414418 if len (REPOS ) > 1 :
415419 plot_lines_by_repo (
416420 weekly_all ,
417- "PR fusionnées par semaine — comparaison entre dépôts " ,
421+ "PR merged per week / repositories " ,
418422 OUTPUT_DIR / "github_stat_pr_lines.png" ,
419423 )
420424
421425 print ("\n Terminé." )
422426
427+
423428if __name__ == "__main__" :
424429 main ()
0 commit comments