Skip to content

Added constants for search API #1131

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

Merged
merged 5 commits into from
Oct 12, 2020

Conversation

valentingregoire
Copy link
Contributor

I added some constants for the search API. I used the official search API docs as reference: https://docs.gitlab.com/ee/api/search.html#project-search-api
It's always nice to be able to link to existing constants instead of having to manually foresee strings.

gitlab/const.py Outdated
SEARCH_SCOPE_GLOBAL_BLOBS = _SEARCH_SCOPE_BLOBS
SEARCH_SCOPE_GLOBAL_USERS = _SEARCH_SCOPE_USERS

SEARCH_SCOPE_GROUP_PROJECTS = _SEARCH_SCOPE_PROJECTS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the duplication needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean with duplication? There is a search scope for:

  1. global
  2. group
  3. project

These three scopes have similar criteria in which you can search, but not 100% the same. Those string literals that collide are extracted into a "private" field.
One could also do something like:

SEARCH_SCOPE_PROJECTS = "projects"
SEARCH_SCOPE_ISSUES = "issues"
SEARCH_SCOPE_MERGE_REQUESTS = "merge_requests"
SEARCH_SCOPE_MILESTONES = "milestones"
SEARCH_SCOPE_WIKI_BLOBS = "wiki_blobs"
SEARCH_SCOPE_COMMITS = "commits"
SEARCH_SCOPE_BLOBS = "blobs"
SEARCH_SCOPE_USERS = "users"
SEARCH_SCOPE_SNIPPET_TITLES = "snippet_titles"
SEARCH_SCOPE_NOTES = "notes"

But that would not allow you to see that the SEARCH_SCOPE_SNIPPET_TITLES only applies to the GLOBAL scope. Same story for the SEARCH_SCOPE_NOTES which only applies to projects scope.
I guess my entire code could be replaced with (now that I think about it while typing):

# all scopes (global, group and  project)
SEARCH_SCOPE_PROJECTS = "projects"
SEARCH_SCOPE_ISSUES = "issues"
SEARCH_SCOPE_MERGE_REQUESTS = "merge_requests"
SEARCH_SCOPE_MILESTONES = "milestones"
SEARCH_SCOPE_WIKI_BLOBS = "wiki_blobs"
SEARCH_SCOPE_COMMITS = "commits"
SEARCH_SCOPE_BLOBS = "blobs"
SEARCH_SCOPE_USERS = "users"

# global scope
SEARCH_SCOPE_GLOBAL_SNIPPET_TITLES = "snippet_titles"

# project scope
SEARCH_SCOPE_PROJECT_NOTES = "notes"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, +1 vote for this approach, I like your last suggestion in this comment, it's much more concise than in the original commit :)

@max-wittig
Copy link
Member

Thanks for the MR! Just a question.

@valentingregoire
Copy link
Contributor Author

@max-wittig, any updates on this matter?

@max-wittig
Copy link
Member

Hey @valentingregoire! Sorry for the delay! Could you maybe add some docs why or how those variables should be used?

Copy link
Contributor Author

@valentingregoire valentingregoire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @valentingregoire! Sorry for the delay! Could you maybe add some docs why or how those variables should be used?

@max-wittig, I have added documentation (and fixed a typo in the meantime).

gitlab/const.py Outdated
SEARCH_SCOPE_GLOBAL_BLOBS = _SEARCH_SCOPE_BLOBS
SEARCH_SCOPE_GLOBAL_USERS = _SEARCH_SCOPE_USERS

SEARCH_SCOPE_GROUP_PROJECTS = _SEARCH_SCOPE_PROJECTS
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean with duplication? There is a search scope for:

  1. global
  2. group
  3. project

These three scopes have similar criteria in which you can search, but not 100% the same. Those string literals that collide are extracted into a "private" field.
One could also do something like:

SEARCH_SCOPE_PROJECTS = "projects"
SEARCH_SCOPE_ISSUES = "issues"
SEARCH_SCOPE_MERGE_REQUESTS = "merge_requests"
SEARCH_SCOPE_MILESTONES = "milestones"
SEARCH_SCOPE_WIKI_BLOBS = "wiki_blobs"
SEARCH_SCOPE_COMMITS = "commits"
SEARCH_SCOPE_BLOBS = "blobs"
SEARCH_SCOPE_USERS = "users"
SEARCH_SCOPE_SNIPPET_TITLES = "snippet_titles"
SEARCH_SCOPE_NOTES = "notes"

But that would not allow you to see that the SEARCH_SCOPE_SNIPPET_TITLES only applies to the GLOBAL scope. Same story for the SEARCH_SCOPE_NOTES which only applies to projects scope.
I guess my entire code could be replaced with (now that I think about it while typing):

# all scopes (global, group and  project)
SEARCH_SCOPE_PROJECTS = "projects"
SEARCH_SCOPE_ISSUES = "issues"
SEARCH_SCOPE_MERGE_REQUESTS = "merge_requests"
SEARCH_SCOPE_MILESTONES = "milestones"
SEARCH_SCOPE_WIKI_BLOBS = "wiki_blobs"
SEARCH_SCOPE_COMMITS = "commits"
SEARCH_SCOPE_BLOBS = "blobs"
SEARCH_SCOPE_USERS = "users"

# global scope
SEARCH_SCOPE_GLOBAL_SNIPPET_TITLES = "snippet_titles"

# project scope
SEARCH_SCOPE_PROJECT_NOTES = "notes"

@valentingregoire
Copy link
Contributor Author

@max-wittig, any updates?

@max-wittig
Copy link
Member

All good 👍

@max-wittig max-wittig merged commit 8cb8040 into python-gitlab:master Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants