-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add support for Label exclusion in IssuesListOptions #3082
Comments
This worked fine for me: package main
import (
"context"
"log"
dbg "github.com/gmlewis/go-httpdebug/httpdebug"
"github.com/google/go-github/v59/github"
"golang.org/x/oauth2"
)
func main() {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: SECRET},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
tp := dbg.New(dbg.WithTransport(tc.Transport))
client := github.NewClient(tp.Client())
ctx := context.Background()
q := "is:open is:issue -label:bug repo:google/go-github"
log.Printf("q=%v", q)
opts := &github.SearchOptions{TextMatch: true}
pulls, _, err := client.Search.Issues(ctx, q, opts)
if err != nil {
log.Fatal(err)
}
log.Printf("Total: %v", pulls.GetTotal())
log.Printf("Incomplete Results: %v", pulls.GetIncompleteResults())
for i, pr := range pulls.Issues {
log.Printf("\n\nPullRequest #%v:", i+1)
log.Printf(" URL: %v", pr.GetHTMLURL())
}
} results in:
which matches your example query as of this moment in time: |
@gmlewis , thank you for taking the look and for the reply. While I agree, there are various ways to accomplish the desired outcome, this specific request deals with "IssueListOptions" https://github.com/google/go-github/blob/master/github/issues.go#L96 As a go-github library caller, I think it would be helpful to enhance the existing IssueListOptions to allow the following (mock-up) functionality: listOptions := &github.IssueListByRepoOptions{
State: "all",
Assignee: "user",
Labels: []{"foo"},
ExcludeLabels: []{"bar"},
}
issues, res, err := c.client.ListIssuesByRepo(ctx, "owner", "reop", listOptions) In other words, the caller can leverage existing "List" operations and primitives instead of using "query" semantics. What do you think? |
Naively thinking, something like this could do the trick. I tested this, and it seems to work. However, I would defer to go-github maintainers.
If needed, I don't mind creating a PR. However, I would like to run it by the maintainers first to get a 👍 . |
Looking at https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#list-repository-issues If the GitHub v3 API doesn't support what you are trying to do, then it will be nearly impossible for you to implement it in this repo, since this is a Go client library for the GitHub v3 API. If I'm reading the official documentation properly, they have not provided a way for you to exclude labels through that endpoint. Therefore, if you wish to exclude labels, you are forced to use query semantics. Or maybe I'm missing something? |
Hi @gmlewis, Thank you for taking a look and for replying. I apologize for the delayed response.
To clarify what you meant by "doesn't support", did you mean that it is not documented, or that it won't work? The "list-repository-issues" API supports the "labels" path parameter. Although it does not explicitly state the support or lack thereof for the "-labels" path parameter, if this was your point, I agree. The "-labels" path parameter is precisely what GitHub UI uses when listing issues with labels "exclusion" (as captured in the screenshot above). |
By "doesn't support" I mean that you cannot construct an equivalent So my point is that it doesn't really matter what their user interface is capable of doing (and therefore, a screenshot of their user interface isn't really helpful) unless they are strictly using their v3 API and you can figure out how to do the same thing (typically, by searching through their v3 API documentation). If, for example, they are using their v4 (graphql) API or some other mechanism to implement their UI, then we won't be able to duplicate this functionality unless the v3 (RESTful) API supports it. I hope this makes sense, but please let me know if this is still unclear. |
Glenn, I truly appreciate the detailed explanation you've provided. It has shed light on the importance of explicit support for the REST API query parameter, even if it's not officially documented. Your clarification makes perfect sense. Regarding your comment about the limitations of constructing an equivalent curl command "using their v3 API," I completely understand the distinction you're making, with emphasis on v3 API list issues query parameters support (or lack thereof). Because, if the point is otherwise different, it appears, I can construct the following
The bottom line is that we don't want to add support for features that rely on unsupported/undocumented v3 RESTful API elements, irrespective of the actual state (working), because of taking the risk of some other mechanism not supporting said elements. |
Ah! That indeed looks like a valid v3 API URL! |
Currently, the go-github library supports GitHub Issue labels filtering as an "inclusion" filter, meaning it matches issues containing the provided labels. However, it's important to note that the GitHub API (as well as the user interface) offers support for both positive (inclusion) and negative (exclusion) label matches.
https://github.com/google/go-github/issues?q=is%3Aopen+is%3Aissue+-label%3Abug
Indeed, label exclusion functionality can be crucial for various use cases when listing issues. It allows users to filter out issues that have specific labels, which can be valuable for focusing on particular subsets of issues or excluding those that are irrelevant to a specific task or context. Integrating label exclusion support into the go-github library would enhance its flexibility and usefulness for managing GitHub issues programmatically.
The text was updated successfully, but these errors were encountered: