Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination helper to easily collect all items #1498

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Jun 13, 2022

  1. Add pagination helper to easily collect all items

    The xanzy#1496 Pull Request triggered
    some thinking for how to do this in a more "generic" way.
    
    Thus, I drafted this `gitlab.Collect()` function, which can be used to
    "easily" collect all items of a specific "list" API (I've implement a
    *collect* function which eagerly collects all items, but something
    similar can be implemented for channels to stream).
    
    The only downside of the current implementation so far is that Go
    doesn't really support generics / interfaces with direct field access as
    of now ... effectively, you'll always need methods.
    This means that, because the `ListOptions` field is somewhat
    inconsistently (sometimes as subfield, sometimes it's promoted)
    implemented over this package every `gitlab.List*Options` struct needs
    it's own `GetPage() int` and `SetPage(int)` implementation ...
    
    One improvement for this could be that we split out the `ListOptions`
    from the API endpoint specific options and make it an additional
    argument to the list methods - so that `Collect()` could profit from
    this and `GetPage() int` and `SetPage(int)` would only need to be
    implemented once.
    
    Another one would be to just use `gitlab.ListOptions` for endpoints
    which don't have additional parameters instead of doing this `type
    ListInstanceVariablesOptions ListOptions`.
    
    However, I think best would be to separate the generic `ListOptions` to
    a separate argument in the long term ...
    timofurrer committed Jun 13, 2022
    Configuration menu
    Copy the full SHA
    4bf9f9a View commit details
    Browse the repository at this point in the history