Skip to content

Commit

Permalink
fix crash when 0 results returned
Browse files Browse the repository at this point in the history
  • Loading branch information
Tillson Galloway committed Nov 18, 2022
1 parent ec1798c commit f1b640c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions config.example.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Required
github_username: "tillson"
github_password: "a8ueifjq4jkasdfoiulk"
# Optional
github_totp_seed: "ABCDEF1234567890" # Obtained via https://github.com/settings/two_factor_authentication/verify
# Optional (comment out if not using)
# github_totp_seed: "ABCDEF1234567890" # Obtained via https://github.com/settings/two_factor_authentication/verify
4 changes: 3 additions & 1 deletion internal/app/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func LoginToGitHub(credentials GitHubCredentials) (httpClient *http.Client, err
// fmt.Println(resp.StatusCode)
data, err := ioutil.ReadAll(resp.Body)
dataStr := string(data)
if strings.Index(dataStr, "Incorrect username or password.") > -1 {
return nil, fmt.Errorf("Incorrect username or password.")
}
if strings.Index(dataStr, "name=\"otp\"") > -1 {
csrf, err = GrabCSRFTokenBody(dataStr)
if err != nil {
Expand All @@ -81,7 +84,6 @@ func LoginToGitHub(credentials GitHubCredentials) (httpClient *http.Client, err
})
data, err = ioutil.ReadAll(resp.Body)
}
// fmt.Println(string(data))
}

return &client, err
Expand Down
5 changes: 4 additions & 1 deletion internal/app/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ func SearchGitHub(query string, options SearchOptions, client *http.Client, resu

resultRegex := regexp.MustCompile("href=\"\\/((.*)\\/blob\\/([0-9a-f]{40}\\/([^#\"]+)))\">")
matches := resultRegex.FindAllStringSubmatch(responseStr, -1)

if page == 0 {
if len(matches) == 0 {
resultRegex = regexp.MustCompile("(?s)react-app\\.embeddedData\">(.*)<\\/script>")
match := resultRegex.FindStringSubmatch(responseStr)
// fmt.Println(smatch)
var resultPayload NewSearchPayload
// fmt.Println(match[1])
if len(match) == 0 {
page++
continue
}
json.Unmarshal([]byte(match[1]), &resultPayload)
if !GetFlags().ResultsOnly && !GetFlags().JsonOutput {
if pages != resultPayload.Payload.PageCount {
Expand Down

0 comments on commit f1b640c

Please sign in to comment.