Issues based on labels


#1

How to specify a query to find issues with specific labels, can someone please help


#2

Hi @abhivijay96,

When in the context of a repository, you can find issues by a particular label with a query like this:

query {
  repository(owner:"rails",name:"rails") {
    issues(labels:["activerecord"], last:30) {
      edges {
        node {
          title
          labels(last:30) {
            edges {
              node {
                name
              }
            }
          }
        }
      }
    }
  }
}

#3

Hey the above query works. Thanks :slight_smile:
What if I want to search all repos based on a tag and get the issue title, url and the language of the repo
basically like this in REST terms…
https://api.github.com/search/issues?q=label:bit-size+is:issue+is:open&sort=updated&order=desc
I formulated the query like this… but it searches for the querystring in the title; I want to search in the labels.

query queryIssue($labelName: String!) {
 search( query:$labelName, type: ISSUE, last:20){
  	edges{
      node{
        ... on Issue{
          title
          url
          repository {
            name
            languages(first:1) {
              edges {
                node {
                  name
                }
              }
            }
          }
        }
      }
    }
}
}
#query string 
{
 "labelName": "bit-size"
}

Can someone help me improve this. Thanks :smiley:


#4

ok, thanks to this article I figured out that I just need to change the query string to
{“labelName”: “label:bit-size”}

Now, I got just the data I need…:smiley:
GraphQL is uber cool!


#5

Ok, I think I just got greedy. :smile:
Is there anyway I can query by multiple labels.
I want to have all the issues having either bit-size or easy.

The reason its important because some issues might have both the labels.
With the current setup I need to query twice and filter for common issues in the frontend.
Hope GraphQL provides this functionality.

@abhivijay96 Sorry for hijacking the thread! :slightly_smiling_face:


#6

I found this syntax, labelName: "label:bit-size label:easy"
But it does an AND operation is there anyway to do an OR.
Thanks!


#7

:wave: @cg-cnu,

Do you mean across all repositories on GitHub, or across a predefined list that you have? If it’s across all repositories, I think the search query that you posted above is probably the as close as you’ll be able to get :confused:, since this schema request is still pending. Ideally if there were a top level repositories field, you could pass the labels argument to it.

I’m sorry I couldn’t be more helpful, but hopefully it will be easier to accomplish this when How to list up all users in GitHub? is complete.


#8

Hey @bswinnerton
Ok, I guess then I need to query for each label and filter them to make it unique.
Thanks for confirming it. Cheers :smile:


#9

Hey @bswinnerton,

As mentioned above, I am trying to find a way to query issues containing labels from a given list.
ie, Get all the issues having labels either enhancement or design after the specified time.

I came up with this query but couldn’t validate from the output am getting from the graphql explorer :confused:

query queryIssue {
    enhancements: search( query:"label:enhancement updated:>2017-04-30T00:00:00Z", type: ISSUE, first:4){
        edges{
        node{
            ... on Issue{
            title
            url
            labels(first:10) {
                edges {
                    node {
                        name
                        }
                    }
                }
            repository {
                name
                    primaryLanguage {
                        name
                        }
                    }
                }
            }
        }
    },
    
    designs: search( query:"label:design updated:>2017-04-30T00:00:00Z", type: ISSUE, first:4){
        edges{
        node{
            ... on Issue{
            title
            url
            labels(first:10) {
                edges {
                    node {
                        name
                        }
                    }
                }
                repository {
                    name
                    primaryLanguage {
                        name
                        }
                    }
                }
            }
        }
    }
}

Basically, the above query should return the first four issues created after the given time with label as enhancement and first four issues tagged as design. In case of issues having both the tags it will return only once ?

Am i understanding it correct :thinking:

Thanks! :smile: