Question about repository search
Hi, we're able to get results through this URL: https://github.com/search?l=&q=filename%3A.forgeindex&type=code and we are trying to get the result by using this library.
Tried the following lines:
client.Search.Repositories(context.Background(), "q=filename=forgeindex&type=code", nil)
client.Search.Repositories(context.Background(), "q=filename:forgeindex&type=code", nil)
but couldn't get any response. Any chance to share a hint about how we could proceed?
Thanks and best,
This seems to work:
package main
import (
"context"
"log"
"github.com/google/go-github/v41/github"
"golang.org/x/oauth2"
)
const SECRET = "...personal-access-token-elided..."
func main() {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: SECRET},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
client := github.NewClient(tc)
ctx := context.Background()
q := "filename:.forgeindex"
code, _, err := client.Search.Code(ctx, q, nil)
if err != nil {
log.Fatal(err)
}
log.Printf("Total: %v", code.GetTotal())
log.Printf("Incomplete Results: %v", code.GetIncompleteResults())
// log.Printf("CodeResults: %#v", code.CodeResults)
for i, cr := range code.CodeResults {
log.Printf("\n\nCodeResult #%v:", i+1)
log.Printf(" Name: %v", cr.GetName())
log.Printf(" Path: %v", cr.GetPath())
log.Printf(" SHA: %v", cr.GetSHA())
log.Printf(" URL: %v", cr.GetHTMLURL())
// log.Printf(" Repo: %#v", cr.GetRepository())
for j, match := range cr.TextMatches {
log.Printf(" Text match #%v: ", j+1)
log.Printf(" URL: %v", match.GetObjectURL())
log.Printf(" Type: %v", match.GetObjectType())
log.Printf(" Property: %v", match.GetProperty())
log.Printf(" Fragment: %v", match.GetFragment())
for k, m := range match.Matches {
log.Printf(" Match #%v: %q, indices=%+v", k+1, m.GetText, m.Indices)
}
}
}
}
gives:
$ go run main.go
2021/12/07 13:33:00 Total: 11
2021/12/07 13:33:00 Incomplete Results: false
2021/12/07 13:33:00
CodeResult #1:
2021/12/07 13:33:00 Name: www.ics.uci.edu~forgeindex.html
2021/12/07 13:33:00 Path: resources/index/www.ics.uci.edu~forgeindex.html
2021/12/07 13:33:00 SHA: 9a8ef3b123b4b2cdf7517472c6c7ccd711174d83
2021/12/07 13:33:00 URL: https://github.com/brian-byungsookim/Search_ICS/blob/28c972818ff406a0120640f2f3269d43b24b4500/resources/index/www.ics.uci.edu~forgeindex.html
2021/12/07 13:33:00
CodeResult #2:
2021/12/07 13:33:00 Name: forgeindex.config
2021/12/07 13:33:00 Path: config/forge/forgeindex.config
2021/12/07 13:33:00 SHA: 3b2044479663dc894f7747ff7dadd75d90d51952
2021/12/07 13:33:00 URL: https://github.com/YiAng-YiAo/zxj/blob/803d81eb4f15df5a00ef0fa4a3e714c9d71d0062/config/forge/forgeindex.config
2021/12/07 13:33:00
CodeResult #3:
2021/12/07 13:33:00 Name: forgeindex.config
2021/12/07 13:33:00 Path: config/forge/forgeindex.config
2021/12/07 13:33:00 SHA: 3b2044479663dc894f7747ff7dadd75d90d51952
2021/12/07 13:33:00 URL: https://github.com/YiAng-YiAo/configchange/blob/b4a87b6945ce8a0ff625e0a57d842df639761db0/config/forge/forgeindex.config
2021/12/07 13:33:00
CodeResult #4:
2021/12/07 13:33:00 Name: forgeindex.config
2021/12/07 13:33:00 Path: output/client/forge/forgeindex.config
2021/12/07 13:33:00 SHA: bd170a6d8ba8a20e0aa844f3d5d955834c5a2e8b
2021/12/07 13:33:00 URL: https://github.com/YiAng-YiAo/test-zxj/blob/cabce1e7b673cab05118aea4d0e0cc649a974fa3/output/client/forge/forgeindex.config
2021/12/07 13:33:00
CodeResult #5:
2021/12/07 13:33:00 Name: forgeindex.config
2021/12/07 13:33:00 Path: output/server/forge/forgeindex.config
2021/12/07 13:33:00 SHA: 3b2044479663dc894f7747ff7dadd75d90d51952
2021/12/07 13:33:00 URL: https://github.com/YiAng-YiAo/test-zxj/blob/cabce1e7b673cab05118aea4d0e0cc649a974fa3/output/server/forge/forgeindex.config
2021/12/07 13:33:00
CodeResult #6:
2021/12/07 13:33:00 Name: forgeindex.config
2021/12/07 13:33:00 Path: server/data/config/forge/forgeindex.config
2021/12/07 13:33:00 SHA: 3b2044479663dc894f7747ff7dadd75d90d51952
2021/12/07 13:33:00 URL: https://github.com/YiAng-YiAo/test-zxj/blob/cabce1e7b673cab05118aea4d0e0cc649a974fa3/server/data/config/forge/forgeindex.config
2021/12/07 13:33:00
CodeResult #7:
2021/12/07 13:33:00 Name: forgeindex.config
2021/12/07 13:33:00 Path: config/forge/forgeindex.config
2021/12/07 13:33:00 SHA: 3b2044479663dc894f7747ff7dadd75d90d51952
2021/12/07 13:33:00 URL: https://github.com/YiAng-YiAo/cq/blob/cd8009afb6d7483329e16fa72d0524e810611935/config/forge/forgeindex.config
2021/12/07 13:33:00
CodeResult #8:
2021/12/07 13:33:00 Name: www.ics.uci.edu~forgeindex.html
2021/12/07 13:33:00 Path: Assignment 3 SE/Html/www.ics.uci.edu~forgeindex.html
2021/12/07 13:33:00 SHA: 9a8ef3b123b4b2cdf7517472c6c7ccd711174d83
2021/12/07 13:33:00 URL: https://github.com/AndrewHarryKim/cs121/blob/a5b3f786aa5e0c20da26e8115b8b8a1340aa866d/Assignment%203%20SE/Html/www.ics.uci.edu~forgeindex.html
2021/12/07 13:33:00
CodeResult #9:
2021/12/07 13:33:00 Name: www.ics.uci.edu~forgeindex.html
2021/12/07 13:33:00 Path: FinalSet/Html/www.ics.uci.edu~forgeindex.html
2021/12/07 13:33:00 SHA: aea663029e6a8efde63efde2eacd04468d918961
2021/12/07 13:33:00 URL: https://github.com/lordnahor/qicseek/blob/770fb753f3744b43dcc680cdb1221ebe3d4d8ae8/FinalSet/Html/www.ics.uci.edu~forgeindex.html
2021/12/07 13:33:00
CodeResult #10:
2021/12/07 13:33:00 Name: .forgeindex
2021/12/07 13:33:00 Path: .forgeindex
2021/12/07 13:33:00 SHA: 8b137891791fe96927ad78e64b0aad7bded08bdc
2021/12/07 13:33:00 URL: https://github.com/qubitro/nrf52-bss/blob/7cc05b503308113525c5ee955d79394213043d67/.forgeindex
2021/12/07 13:33:00
CodeResult #11:
2021/12/07 13:33:00 Name: forgeindex.config
2021/12/07 13:33:00 Path: root/config/data/client/forge/forgeindex.config
2021/12/07 13:33:00 SHA: 8cc4c7477e463bc7e46a75b153c1b3c1060fca31
2021/12/07 13:33:00 URL: https://github.com/keda666666/game/blob/65ab32fe40305c3121893bc53ae2879181be7c89/root/config/data/client/forge/forgeindex.config
@gmlewis did you manage to print TextMatches?
@gmlewis did you manage to print TextMatches?
If you want the TextMatch data, change two lines above to:
opts := &github.SearchOptions{TextMatch: true}
code, _, err := client.Search.Code(ctx, q, opts)
I came across this issue and I'm facing something quite similar. I can see some weird inconsistencies in the way the .Search.Code behaves compared to the search on Github's UI.
Examples:
This search works on the GH UI but not using go-github for some reason: org:google path:**/.github/CODEOWNERS "gnostic". Using go-github returns an empty list of occurences with no errors.
In opposite to this query which works with go-github but the UI complains about it: org:google filename:.github/CODEOWNERS "gnostic"
Both give the same results as far as I can tell but the inconsistency is weird. Any ideas @gmlewis ?
Sorry, @migueleliasweb - no clue for the inconsistent results from the GitHub v3 API. Please contact GitHub tech support and ask them if they have an explanation for you.
I'm going to go ahead and close this issue, as I believe this issue is more of a GitHub v3 API issue than it is an issue with this repo.
Feel free, however, to report back any responses you get from the GitHub tech support team as to what is going on. Thanks.