Skip to content
Advertisement

How to use `not` condition in the gitlab api issue query

I am trying to read the list of open issues title which doesn’t have label resolved. For that I am referring the API documentation (https://docs.gitlab.com/ee/api/issues.html) which mentions NOT but I couldn’t able to get the NOT to work.

The following python script I have tried so far to read the list of issues now I am not able to find how to use NOT to filter the issue which doesn’t have resolved label.

import gitlab

# private token or personal token authentication
gl = gitlab.Gitlab('https://example.com', private_token='XXXYYYZZZ')

# make an API request to create the gl.user object. This is mandatory if you
# use the username/password authentication.
gl.auth()

# list all the issues
issues = gl.issues.list(all=True,scope='all',state='opened',assignee_username='username')
for issue in issues:
    print(issue.title)

Advertisement

Answer

From Gitlab issues api documentation, not is of type Hash. It’s a special type documented here

For example to exclude the labels Category:DAST and devops::secure, and to exclude the milestone 13.11, you would use the following parameters:

not[labels]=Category:DAST,devops::secure
not[milestone]=13.11

api example: https://gitlab.com/api/v4/issues?scope=all&state=opened&assignee_username=derekferguson&not[labels]=Category:DAST,devops::secure&not[milestone]=13.11

Using gitlab python module, you would need to pass some extra parameters by adding more keyword arguments:

import gitlab

gl = gitlab.Gitlab('https://gitlab.com')

extra_params = {
    'not[labels]': "Category:DAST,devops::secure",
    "not[milestone]": "13.11"
}
issues = gl.issues.list(all=True, scope='all', state='opened',
                        assignee_username='derekferguson', **extra_params)
for issue in issues:
    print(issue.title)
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement