Skip to content

Add project push rules configuration #520

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 7 commits into from
Jun 11, 2018

Conversation

esabouraud
Copy link
Contributor

This PR introduces support for project push rules configuration.

@gpocentek
Copy link
Contributor

Hi @esabouraud

I don't really understand why you removed the CreateMixin, it looks like creation is possible (from the docs and the code). The only thing that doesn't seem possible is to get a single rule. Did I miss something?

@esabouraud
Copy link
Contributor Author

Hi @gpocentek

At first glance the /projects/:id/push_rule API endpoint looked like a perfect match for CRUDMixin. However this approach broke the tests. My understanding is that CRUDMixin and GetWithoutIdMixin (with _id_attr = None) do not play nice with each other. I could not find this exact pairing anywhere else in the code and did not quite know how to fix it.

======================================================================
FAIL: gitlab.tests.test_cli.TestV4CLI.test_parser
tags: worker-1
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/esabouraud/python-gitlab/gitlab/tests/test_cli.py", line 96, in test_parser
    parser = cli._get_parser(gitlab.v4.cli)
  File "/home/travis/build/esabouraud/python-gitlab/gitlab/cli.py", line 115, in _get_parser
    return cli_module.extend_parser(parser)
  File "/home/travis/build/esabouraud/python-gitlab/gitlab/v4/cli.py", line 254, in extend_parser
    _populate_sub_parser_by_class(cls, object_subparsers)
  File "/home/travis/build/esabouraud/python-gitlab/gitlab/v4/cli.py", line 146, in _populate_sub_parser_by_class
    id_attr = cls._id_attr.replace('_', '-')
AttributeError: 'NoneType' object has no attribute 'replace'

As for the API itself, it's a bit unusual in that push rules are not referenced by id. Rather they are optional attributes that can be edited. The documentation itself is inconsistent as it sometimes refers to "a push rule", and sometimes to "push rules".

@gpocentek
Copy link
Contributor

This endpoint is really weird, and indeed the mixins don't really work well together. The only solution I see to implement all the features, including create and delete, is to write class-specific methods instead of using the mixins. Mixins make most objects very simple to define, but sometimes duplicating a little bit of code is necessary. Could you try that?

Thanks for your work!

@esabouraud
Copy link
Contributor Author

OK I've implemented the create and delete methods of the endpoint, while keeping things fairly nice and tidy (I think). It was mostly a matter of allowing delete without an object id.

@gpocentek gpocentek merged commit 2c22a34 into python-gitlab:master Jun 11, 2018
@gpocentek
Copy link
Contributor

Thanks @esabouraud !

@gpocentek gpocentek mentioned this pull request Jun 11, 2018
@esabouraud
Copy link
Contributor Author

Thank you @gpocentek for your diligent work on this module.

@esabouraud esabouraud deleted the feature-projectpushrules branch June 12, 2018 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants