Add a way to break out of current scope
Summary
Allow the user to break out of the current scope by providing and argument to group and/or project.
Description
In cases where a constraint can be set both by compiler flag and within the language, such as group/project, the language takes precedent. In fact, the chain of precedence goes:
- language (`group = "foo"`)
- compiler flag (`-g "foo")
- default value
Currently, with group and project however, there is no way to "break out" of a value given as a compiler flag using the language. If the compiler flag for group is given as "gitlab-org/gitlab-query-language" the user can override it by setting it to "gitlab-com" or even higher in the hierarchy "gitlab-org". But they can't remove the group constraint entirely.
Since the language must be used in an asset somewhere, and these assets all live at some level of scope, there's really no way to embed any issue outside of the top level of the current hierarchy.
This would be useful to do when considering queries such as assignee = currentUser(), or when collecting the contributions of a team across the whole instance.
Proposal
Add a wildcard to group and project. Perhaps resuse the any keyword.
The following rules should be observed:
-
group = anyremove any preset scope -
project = anyremove any preset scope -
group = any and project = anyequivalent to either of the previous two -
group = "gitlab-org" and project = anyequivalent togroup = "gitlab-org" -
group = any and project = "gitlab-org/gitlab"equivalent toproject = "gitlab-org/gitlab"
Implementation guide
Group and Project are known as 'scope' internally in the compiler. They are treated specially because they're expected to be referred to multiple times during the compilation of a query. The Optimizer plucks them out of the syntax tree and stores their values in the first node, alongside other settings.
When it does this it uses the functions projectFromTree and groupFromTree to scan the tree for each and override any previous value set by a compiler flag (the default is no scope).
This could be a relatively straightforward change. An additional case will need to be added to either or both *FromTree functions to detect the any bareword and set the corresponding scope to Nothing. It should also be tested so that the expected rules are observed.
In fact it would be also good to detect and error on other, unsupported barewords, such as none .