Skip to content

Commit e8f039d

Browse files
committed
- Fixed paging for API calls which returns total_count followed by results in dictionary format.
- Added GH REST API calls for getting commit comments, issues comments, PR comments - Added GH REST API calls for getting workflow action runs - Added GH REST API calls for getting labels - Added GH REST API calls for getting environment protection rules
1 parent 2514d8c commit e8f039d

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/gitxray/include/gh_api.py

+29-8
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,22 @@ def github_request_json(url, params=None, limit_results=None):
6161
continue # and restart the loop
6262

6363
if all_results is None:
64-
all_results = data
65-
elif isinstance(all_results, list) and isinstance(data, list):
64+
all_results = data
65+
# if we come from all_results being a list, then we're extending it.
66+
elif isinstance(all_results, list):
6667
all_results.extend(data)
67-
elif isinstance(all_results, dict) and isinstance(data, dict):
68-
all_results.update(data)
68+
elif isinstance(all_results, dict) and data.get('total_count') != None:
69+
all_results[list(all_results.keys())[1]].extend(list(data.values())[1])
6970
else:
70-
raise TypeError("Inconsistent data types received from pagination.")
71+
all_results.update(data)
7172

7273
# Reset next_url
7374
next_url = None
7475

7576
# Using "limit" we can cap the amount of results in order to prevent huge amounts of requests.
76-
if limit_results == None or len(all_results) < limit_results:
77+
if limit_results == None or \
78+
((isinstance(all_results, list) and len(all_results) < limit_results) \
79+
or (isinstance(all_results, dict) and all_results.get('total_count') != None and len(list(all_results.values())[1]) < limit_results)):
7780
if 'rel="next"' in links:
7881
for link in links.split(','):
7982
if 'rel="next"' in link:
@@ -126,18 +129,33 @@ def fetch_repository_custom_values(repo):
126129
def fetch_repository_public_events(repo):
127130
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/events")
128131

132+
def fetch_repository_commit_comments(repo):
133+
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/comments")
134+
135+
def fetch_repository_issues_comments(repo):
136+
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/issues/comments")
137+
138+
def fetch_repository_pulls_comments(repo):
139+
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/pulls/comments")
140+
129141
def fetch_repository_actions_workflows(repo):
130142
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/actions/workflows")
131143

132-
def fetch_repository_actions_artifacts(repo):
133-
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/actions/artifacts")
144+
def fetch_repository_actions_artifacts(repo, limit):
145+
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/actions/artifacts", limit_results=limit)
146+
147+
def fetch_repository_actions_runs(repo, limit):
148+
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/actions/runs", limit_results=limit)
134149

135150
def fetch_repository_releases(repo):
136151
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/releases")
137152

138153
def fetch_repository_tags(repo):
139154
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/tags")
140155

156+
def fetch_repository_labels(repo):
157+
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/labels")
158+
141159
def fetch_repository_branches(repo):
142160
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/branches")
143161

@@ -150,6 +168,9 @@ def fetch_repository_deployments(repo):
150168
def fetch_repository_environments(repo):
151169
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/environments")
152170

171+
def fetch_environment_protection_rules(repo, environment):
172+
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/environments/{environment}/deployment_protection_rules")
173+
153174
def fetch_repository_pull_requests(repo):
154175
return github_request_json(repo.get('pulls_url').replace("{/number}",""), {'state':'all'})
155176

0 commit comments

Comments
 (0)