@@ -24,14 +24,14 @@ def get_commits(user, repository, force_refresh=False):
2424 return commits
2525
2626def create_repo_node (repo_name , image_url , count ):
27- return {"name" : repo_name , "image" : image_url , "group" : count , "type" : "repo" }
27+ return {"name" : repo_name , "image" : image_url , "group" : count , "type" : "repo" }
2828
2929def create_contributor_node (contributor , group = 1 ):
3030 return {"name" : contributor ["login" ], "image" : contributor ["avatar_url" ], "group" : group , "type" : "contributor" }
3131
3232def create_center_node (image = CENTER_IMG ):
33- return {"name" : "JUPYTER" , "image" : image , "group" : 0 , "type" : "center" }
34-
33+ return {"name" : "JUPYTER" , "image" : image , "group" : 0 , "type" : "center" }
34+
3535def create_graph_repos (repos = REPOS , use_custom_images = USE_CUSTOM_IMAGES , repo_img_dir = REPO_IMG_DIR , img_type = IMG_TYPE ):
3636 graph = {"nodes" : [], "links" : []}
3737 center_id = 0
@@ -41,7 +41,7 @@ def create_graph_repos(repos=REPOS, use_custom_images=USE_CUSTOM_IMAGES, repo_im
4141 commits = get_commits (user , repository )
4242 url = CENTER_IMG
4343 if use_custom_images :
44- url = repo_img_dir + user + "_" + repository + "." + img_type
44+ url = repo_img_dir + user + "_" + repository + "." + img_type
4545 repo_node = create_repo_node (repository , url , len (repo_ids ))
4646 graph ["nodes" ].append (repo_node )
4747 repo_id = len (graph ["nodes" ]) - 1
@@ -50,6 +50,8 @@ def create_graph_repos(repos=REPOS, use_custom_images=USE_CUSTOM_IMAGES, repo_im
5050 for commit in commits :
5151 duplicate = False
5252 author = commit ["author" ]
53+ if not author :
54+ continue
5355 for index , node in enumerate (graph ["nodes" ]):
5456 if node ["name" ] == author ["login" ]:
5557 duplicate = True
@@ -58,36 +60,36 @@ def create_graph_repos(repos=REPOS, use_custom_images=USE_CUSTOM_IMAGES, repo_im
5860 node = create_contributor_node (author , group = len (repo_ids )- 1 )
5961 graph ["nodes" ].append (node )
6062 contrib_id = len (graph ["nodes" ]) - 1
61- graph ["links" ].append ({"source" : repo_id , "target" : contrib_id , "value" : 2 })
63+ graph ["links" ].append ({"source" : repo_id , "target" : contrib_id , "value" : 2 })
6264 graph ["links" ].append ({"source" : repo_ids [0 ], "target" : repo_ids [- 1 ], "value" : 1 })
6365 return graph
6466
6567def should_refresh (timestamp_file = TIMESTAMP_FILE , refresh_interval = REFRESH_INTERVAL ):
66- now = time .time ()
67- then = 0
68- if os .path .isfile (timestamp_file ):
69- with open (timestamp_file , 'r' ) as f :
70- then = float (f .readline ().strip ())
71- return now - then > refresh_interval
68+ now = time .time ()
69+ then = 0
70+ if os .path .isfile (timestamp_file ):
71+ with open (timestamp_file , 'r' ) as f :
72+ then = float (f .readline ().strip ())
73+ return now - then > refresh_interval
7274
7375def update_timestamp (timestamp_file = TIMESTAMP_FILE ):
74- now = time .time ()
75- with open (timestamp_file , 'w' ) as f :
76- f .write (str (now ))
76+ now = time .time ()
77+ with open (timestamp_file , 'w' ) as f :
78+ f .write (str (now ))
7779
7880def main (command = []):
79- force_refresh = False
80- if len (command ) > 0 and command [0 ] == "force-refresh" :
81- force_refresh = True
82- if force_refresh or should_refresh ():
83- graph = create_graph_repos ()
84- if graph is not None and len (graph ["nodes" ]) > 0 :
85- with open (DATA_FILE , 'w' ) as f :
86- json .dump (graph , f )
87- else :
88- raise ValueError ("Empty graph generated" )
89- update_timestamp ()
90-
81+ force_refresh = False
82+ if len (command ) > 0 and command [0 ] == "force-refresh" :
83+ force_refresh = True
84+ if force_refresh or should_refresh ():
85+ graph = create_graph_repos ()
86+ if graph is not None and len (graph ["nodes" ]) > 0 :
87+ with open (DATA_FILE , 'w' ) as f :
88+ json .dump (graph , f , indent = 1 , sort_keys = True )
89+ else :
90+ raise ValueError ("Empty graph generated" )
91+ update_timestamp ()
92+
9193
9294if __name__ == "__main__" :
93- main (command = sys .argv [1 :])
95+ main (command = sys .argv [1 :])
0 commit comments