1616)
1717
1818
19- def v3_fetch_file (parsed_url , gh_config : GithubModel ):
19+ def _clean_nones (items ):
20+ return list (filter (None , items ))
21+
22+
23+ def _fetch_file (parsed_url , gh_config : GithubModel ):
2024 """
2125 Fetch files using Github v3 protocol.
2226 """
@@ -30,11 +34,13 @@ def v3_fetch_file(parsed_url, gh_config: GithubModel):
3034
3135 auth = (username , gh_config .app_token )
3236 url = "/" .join (
33- (
34- endpoint ,
35- version ,
36- "users" ,
37- username ,
37+ _clean_nones (
38+ [
39+ endpoint ,
40+ version ,
41+ "users" ,
42+ username ,
43+ ]
3844 )
3945 )
4046 resp = requests .get (url , auth = auth , timeout = 180 )
@@ -47,7 +53,7 @@ def v3_fetch_file(parsed_url, gh_config: GithubModel):
4753 raise ValueError ('URL must begin with "/"' )
4854
4955 fpath = parsed_url .path .split ("/" )
50- ubuild = [endpoint , version , "repos" , fpath [1 ], fpath [2 ], "contents" ]
56+ ubuild = _clean_nones ( [endpoint , version , "repos" , fpath [1 ], fpath [2 ], "contents" ])
5157 ubuild .extend (fpath [3 :])
5258 url = "/" .join (ubuild )
5359 resp = requests .get (url , auth = auth , timeout = 180 )
@@ -97,9 +103,9 @@ def fetch_file(parsed_url, config: GlobalConfig):
97103 )
98104
99105 ver = nlcfg .version
100- # NOTE: potentially the v3_fetch_file () works for other github API versions.
101- if ver == "v3" :
102- contents = v3_fetch_file (parsed_url , nlcfg )
106+ # NOTE: potentially the _fetch_file () works for other github API versions.
107+ if ver == "v3" or ver is None :
108+ contents = _fetch_file (parsed_url , nlcfg )
103109 else :
104110 raise NotImplementedError (f"No version support for github API version { ver } " )
105111
0 commit comments