@@ -24,14 +24,14 @@ def get_commits(user, repository, force_refresh=False):
24
24
return commits
25
25
26
26
def 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" }
28
28
29
29
def create_contributor_node (contributor , group = 1 ):
30
30
return {"name" : contributor ["login" ], "image" : contributor ["avatar_url" ], "group" : group , "type" : "contributor" }
31
31
32
32
def 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
+
35
35
def create_graph_repos (repos = REPOS , use_custom_images = USE_CUSTOM_IMAGES , repo_img_dir = REPO_IMG_DIR , img_type = IMG_TYPE ):
36
36
graph = {"nodes" : [], "links" : []}
37
37
center_id = 0
@@ -41,7 +41,7 @@ def create_graph_repos(repos=REPOS, use_custom_images=USE_CUSTOM_IMAGES, repo_im
41
41
commits = get_commits (user , repository )
42
42
url = CENTER_IMG
43
43
if use_custom_images :
44
- url = repo_img_dir + user + "_" + repository + "." + img_type
44
+ url = repo_img_dir + user + "_" + repository + "." + img_type
45
45
repo_node = create_repo_node (repository , url , len (repo_ids ))
46
46
graph ["nodes" ].append (repo_node )
47
47
repo_id = len (graph ["nodes" ]) - 1
@@ -50,6 +50,8 @@ def create_graph_repos(repos=REPOS, use_custom_images=USE_CUSTOM_IMAGES, repo_im
50
50
for commit in commits :
51
51
duplicate = False
52
52
author = commit ["author" ]
53
+ if not author :
54
+ continue
53
55
for index , node in enumerate (graph ["nodes" ]):
54
56
if node ["name" ] == author ["login" ]:
55
57
duplicate = True
@@ -58,36 +60,36 @@ def create_graph_repos(repos=REPOS, use_custom_images=USE_CUSTOM_IMAGES, repo_im
58
60
node = create_contributor_node (author , group = len (repo_ids )- 1 )
59
61
graph ["nodes" ].append (node )
60
62
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 })
62
64
graph ["links" ].append ({"source" : repo_ids [0 ], "target" : repo_ids [- 1 ], "value" : 1 })
63
65
return graph
64
66
65
67
def 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
72
74
73
75
def 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 ))
77
79
78
80
def 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
+
91
93
92
94
if __name__ == "__main__" :
93
- main (command = sys .argv [1 :])
95
+ main (command = sys .argv [1 :])
0 commit comments