-
Notifications
You must be signed in to change notification settings - Fork 1
/
github_search_result_item.py
61 lines (34 loc) · 1.31 KB
/
github_search_result_item.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
GITHUB_URL = 'https:/github.com'
GITHUB_PATH = '/blob/'
GITHUB_RAW_CONTENT_URL = 'https://raw.githubusercontent.com'
GITHUB_RAW_CONTENT_PATH = '/'
class GithubSearchResultItem:
def __init__(self, search_result):
self.search_result = search_result
def has_respoitory_url(self):
if 'repository' not in self.search_result:
return False
if 'url' not in self.search_result['repository']:
return False
return True
def get_repository_url(self):
if 'repository' not in self.search_result:
return None
if 'url' not in self.search_result['repository']:
return None
return self.search_result['repository']['url']
def get_item_url(self):
if 'url' not in self.search_result:
return None
return self.search_result['url']
def get_html_url(self):
if 'html_url' not in self.search_result:
return None
return self.search_result['html_url']
def get_raw_content_url(self):
html_url = self.get_html_url()
if not html_url:
return None
html_url = html_url.replace(GITHUB_URL, GITHUB_RAW_CONTENT_URL)
html_url = html_url.replace(GITHUB_PATH, GITHUB_RAW_CONTENT_PATH)
return html_url