def get(self, request, organization, integration_id): try: integration = Integration.objects.get(organizations=organization, id=integration_id) except Integration.DoesNotExist: return Response(status=404) field = request.GET.get("field") query = request.GET.get("query") if field is None: return Response({"detail": "field is a required parameter"}, status=400) if not query: return Response({"detail": "query is a required parameter"}, status=400) installation = integration.get_installation(organization.id) if field == "externalIssue": repo = request.GET.get("repo") if repo is None: return Response({"detail": "repo is a required parameter"}, status=400) try: response = installation.search_issues( query=("repo:%s %s" % (repo, query)).encode("utf-8") ) except ApiError as err: if err.code == 403: return Response({"detail": "Rate limit exceeded"}, status=429) raise return Response( [ {"label": "#%s %s" % (i["number"], i["title"]), "value": i["number"]} for i in response.get("items", []) ] ) if field == "repo": full_query = build_repository_query(integration.metadata, integration.name, query) try: response = installation.get_client().search_repositories(full_query) except ApiError as err: if err.code == 403: return Response({"detail": "Rate limit exceeded"}, status=429) if err.code == 422: return Response( { "detail": "Repositories could not be searched because they do not exist, or you do not have access to them." }, status=404, ) raise return Response( [{"label": i["name"], "value": i["full_name"]} for i in response.get("items", [])] ) return Response(status=400)
def get_repositories(self, query=None): if not query: return [ {"name": i["name"], "identifier": i["full_name"]} for i in self.get_client().get_repositories() ] full_query = build_repository_query(self.model.metadata, self.model.name, query) response = self.get_client().search_repositories(full_query) return [ {"name": i["name"], "identifier": i["full_name"]} for i in response.get("items", []) ]
def get(self, request, organization, integration_id): try: integration = Integration.objects.get( organizations=organization, id=integration_id, ) except Integration.DoesNotExist: return Response(status=404) field = request.GET.get('field') query = request.GET.get('query') if field is None: return Response({'detail': 'field is a required parameter'}, status=400) if not query: return Response({'detail': 'query is a required parameter'}, status=400) installation = integration.get_installation(organization.id) if field == 'externalIssue': repo = request.GET.get('repo') if repo is None: return Response({'detail': 'repo is a required parameter'}, status=400) try: response = installation.search_issues( query=(u'repo:%s %s' % (repo, query)).encode('utf-8'), ) except ApiError as err: if err.code == 403: return Response({'detail': 'Rate limit exceeded'}, status=429) raise return Response([{ 'label': '#%s %s' % (i['number'], i['title']), 'value': i['number'] } for i in response.get('items', [])]) if field == 'repo': full_query = build_repository_query(integration.metadata, integration.name, query) try: response = installation.get_client().search_repositories(full_query) except ApiError as err: if err.code == 403: return Response({'detail': 'Rate limit exceeded'}, status=429) if err.code == 422: return Response({ 'detail': 'Repositories could not be searched because they do not exist, or you do not have access to them.' }, status=404) raise return Response([{ 'label': i['name'], 'value': i['full_name'] } for i in response.get('items', [])]) return Response(status=400)
def get_repositories(self, query=None): if not query: return [{ 'name': i['name'], 'identifier': i['full_name'] } for i in self.get_client().get_repositories()] full_query = build_repository_query(self.model.metadata, self.model.name, query) response = self.get_client().search_repositories(full_query) return [{ 'name': i['name'], 'identifier': i['full_name'] } for i in response.get('items', [])]