Skip to content

Commit a3da666

Browse files
committed
Fix sourcegraph regex and add better error handling.
1 parent 8683d33 commit a3da666

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

gato/search/search.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ def use_sourcegraph_api(
8181
headers = {"Content-Type": "application/json"}
8282
params = {
8383
"q": (
84-
"('self-hosted' OR "
85-
"(/runs-on/ AND NOT "
84+
"context:global "
85+
"self-hosted OR "
86+
"(runs-on AND NOT "
8687
"/(ubuntu-16.04|ubuntu-18.04|ubuntu-20.04|ubuntu-22.04|ubuntu-latest|"
8788
"windows-2019|windows-2022|windows-latest|macos-11|macos-12|macos-13|"
88-
"macos-12-xl|macos-13-xl|macos-latest|matrix.[a-zA-Z]\\s)/)) "
89+
"macos-12-xl|macos-13-xl|macos-latest)/) "
8990
f"{repo_filter}"
9091
"lang:YAML file:.github/workflows/ count:30000"
9192
)
@@ -107,13 +108,24 @@ def use_sourcegraph_api(
107108
if line and line.decode().startswith("data:"):
108109
json_line = line.decode().replace("data:", "").strip()
109110
event = json.loads(json_line)
111+
112+
if "title" in event and event["title"] == "Unable To Process Query":
113+
Output.error("SourceGraph was unable to process the query!")
114+
Output.error(f"Error: {Output.bright(event['description'])}")
115+
return False
116+
110117
for element in event:
111118
if "repository" in element:
112119
results.add(
113120
element["repository"].replace("github.com/", "")
114121
)
122+
else:
123+
Output.error(
124+
f"SourceGraph returned an error: {Output.bright(response.status_code)}"
125+
)
126+
return False
115127

116-
return results
128+
return sorted(results)
117129

118130
def use_search_api(self, organization: str, query=None):
119131
"""Utilize GitHub Code Search API to try and identify repositories
@@ -153,7 +165,7 @@ def use_search_api(self, organization: str, query=None):
153165
organization, custom_query=query
154166
)
155167

156-
return candidates
168+
return sorted(candidates)
157169

158170
def present_results(self, results, output_text=None):
159171
"""

0 commit comments

Comments
 (0)