MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / fetch_search_github_resource

Function fetch_search_github_resource

api/integrations/github/client.py:154–223  ·  view source on GitHub ↗
(
    resource_type: ResourceType,
    organisation_id: int,
    params: IssueQueryParams,
)

Source from the content-addressed store, hash-verified

152
153
154def fetch_search_github_resource(
155 resource_type: ResourceType,
156 organisation_id: int,
157 params: IssueQueryParams,
158) -> dict[str, Any]:
159 github_configuration = GithubConfiguration.objects.get(
160 organisation_id=organisation_id, deleted_at__isnull=True
161 )
162 # Build Github search query
163 q = ["q="]
164 if params.search_text:
165 q.append(params.search_text)
166 q.append(f"repo:{params.repo_owner}/{params.repo_name}")
167 q.append(f"is:{resource_type.value}")
168 if params.state:
169 q.append(f"is:{params.state}")
170 q.append("in:title")
171 if params.search_in_body:
172 q.append("in:body")
173 if params.search_in_comments:
174 q.append("in:comments")
175 if params.author:
176 q.append(f"author:{params.author}")
177 if params.assignee:
178 q.append(f"assignee:{params.assignee}")
179
180 url = (
181 f"{GITHUB_API_URL}search/issues?"
182 + " ".join(q)
183 + f"&per_page={params.page_size}&page={params.page}"
184 )
185 headers: dict[str, str] = build_request_headers(
186 github_configuration.installation_id
187 )
188 try:
189 response = requests.get(url, headers=headers, timeout=GITHUB_API_CALLS_TIMEOUT)
190 response.raise_for_status()
191 json_response = response.json()
192
193 except HTTPError:
194 response_content = response.content.decode("utf-8")
195 error_message = (
196 "The resources do not exist or you do not have permission to view them"
197 )
198 error_data = json.loads(response_content)
199 if error_data.get("message", "") == "Validation Failed" and any(
200 error.get("code", "") == "invalid" for error in error_data.get("errors", [])
201 ):
202 logger.warning(error_message)
203 raise ValueError(error_message)
204
205 results = [
206 {
207 "html_url": i["html_url"],
208 "id": i["id"],
209 "title": i["title"],
210 "number": i["number"],
211 "state": i["state"],

Callers 2

fetch_pull_requestsFunction · 0.90
fetch_issuesFunction · 0.90

Calls 7

build_request_headersFunction · 0.85
build_paginated_responseFunction · 0.85
decodeMethod · 0.80
getMethod · 0.45
appendMethod · 0.45
raise_for_statusMethod · 0.45
jsonMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…