(
resource_type: ResourceType,
organisation_id: int,
params: IssueQueryParams,
)
| 152 | |
| 153 | |
| 154 | def 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"], |
no test coverage detected
searching dependent graphs…