Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not detecting query path:**/*.yaml #2894

Open
rr-jino-jose opened this issue Aug 22, 2023 · 2 comments
Open

Not detecting query path:**/*.yaml #2894

rr-jino-jose opened this issue Aug 22, 2023 · 2 comments

Comments

@rr-jino-jose
Copy link

Hello I am using "github.com/google/go-github/v54/github" to search codes in my org. While I do search for "org: XX path:**/*.yaml" in github UI it works but while using the below it doesn't

token := os.Getenv("GITHUB_TOKEN")
query := "org:XX path:**/*.yaml"

ctx := context.Background()
ts := oauth2.StaticTokenSource(
	&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(ctx, ts)

client := github.NewClient(tc)

opts := &github.SearchOptions{
		Sort:        "score",
		Order:       "desc",
		ListOptions: github.ListOptions{Page: 1, PerPage: 100},
	}

result, _, err := client.Search.Code(ctx, query, opts)
fmt.Println(result.CodeResults)

wonder if i am querying it wrong can anyone help? please?

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 22, 2023

I'm not able to get this to work either. I also tried client.Search.Repositories and that didn't work either.

Going back to the official GitHub v3 REST API documentation, I'm only finding mention of "path:" in the legacy section:
https://docs.github.com/en/search-github/searching-on-github/searching-code#search-by-file-location

Could you please contact official GitHub technical support and ask them how you are supposed to add "path:" to their v3 REST API, and report back here?

I'll leave this issue open for you to report back their response. Feel free to point them to this issue to describe the problem.
Thank you!

@WillAbides
Copy link
Contributor

First off, if **/*.yaml is really the path you want to search for, you can get around this problem by using language:yaml instead of path:**/*.yaml. But that trick obviously only works where you are searching for a file extension that happens to identify a language.

To confirm this is a limitation of the GitHub API and not go-github, I reproduced this issue with curl.

$ curl -fG \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -H "Accept: application/vnd.github.v3+json" \
  --data-urlencode 'q=your-auth-token-here org:google path:**/*.yaml' \
  'https://api.github.com/search/code'
{
  "total_count": 0,
  "incomplete_results": false,
  "items": [

  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants