FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

cli syntax issue · Issue #1732 · python-gitlab/python-gitlab · GitHub

Repository navigation

cli syntax issue #1732

Description

Description of the problem, including code/CLI snippet

Hello,
First of all thank you for the work done in this project, it is helpful.

I am trying to manage some gitlab configuration with python-gitlab CLI, however I do not find the right syntax to protect a branch. I am struggling with the parameters :

--allowed-to-push
--allowed-to-merge

Can someone help me ?

**The syntax below does not work

   gitlab project-protected-branch create --project-id xxx\
      --name master \
      --allowed-to-merge='user_id: xxx' \
      --code-owner-approval-required=true \
      --push-access-level=0 \
      --merge-access-level=0

Activity

  1. JohnVillalovos commented on Dec 6, 2021

    Member

    **The syntax below does not work

    How does it not work? Any messages? Silently fails?

  2. angegar commented on Dec 6, 2021

    Author

    The error message is Impossible to create object (400: allowed_to_merge is invalid)

    Probably because of a wrong synxtax, i do not know how to set the --allowed-to-merge parameter.

  3. JohnVillalovos commented on Dec 6, 2021

    Member

    The upstream docs ( https://docs.gitlab.com/ee/api/protected_branches.html#protect-repository-branches ) say that allowed_to_merge is a list of integers.

    So I would think on the command line it would be: --allowed-to-merge=1 your example above says user_id: xxx

  4. JohnVillalovos commented on Dec 6, 2021

    Member

    Sorry, the upstream docs say:

    allowed_to_merge:
    
    Array of access levels allowed to merge, with each described by a hash 
    

    So maybe: --allowed-to-merge=40 would be for maintainer access.

    I'm not quite sure what they mean by "described by a hash"

  5. angegar commented on Dec 6, 2021

    Author

    Thank you for your help :D

    I tried gitlab project-protected-branch create --project-id yyy --name master --code-owner-approval-required=true --allowed-to-merge=xxx but it failed with the same error

    Impossible to create object (400: allowed_to_merge is invalid)

    It should be a complex structure as it can be a list of user_id or a list of group_id.

  6. JohnVillalovos commented on Dec 6, 2021

    Member

    as it can be a list of user_id or a list of group_id.

    That doesn't seem to be what the docs say 😟

  7. JohnVillalovos commented on Dec 6, 2021

    Member

    If you can figure out how to make it work with a curl command then maybe we can then try to figure out how to make it work with the CLI.

  8. JohnVillalovos commented on Dec 6, 2021

    Member

    as it can be a list of user_id or a list of group_id.

    That doesn't seem to be what the docs say 😟

    But it seems like it might be what the code says. Confusing 😟

    https://gitlab.com/gitlab-org/gitlab/-/blob/1171f6fb3b81c3f7ebaf0a1295eee239e4ea9499/ee/lib/ee/api/helpers/protected_branches_helpers.rb#L21

  9. JohnVillalovos commented on Dec 7, 2021

    Member

    Looking more closely at the docs I found:

    https://docs.gitlab.com/ee/api/protected_branches.html#example-with-user--group-level-access

    Which says:

    Elements in the allowed_to_push / allowed_to_merge / allowed_to_unprotect array should take the form {user_id: integer}, {group_id: integer}, or {access_level: integer}. Each user must have access to the project and each group must have this project shared. These access levels allow more granular control over protected branch access.

    An example curl command:

    curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "\
    https://gitlab.example.com/api/v4/projects/5/protected_branches?name=*-stable&allowed_to_push%5B%5D%5Buser_id%5D=1"
    

    Which putting part of it into Python:

    >>> urllib.parse.unquote("allowed_to_push%5B%5D%5Buser_id%5D=1")
    'allowed_to_push[][user_id]=1'
    

    So we for sure don't support that data type yet 😟 Right now I have a PR up to better support the array type: #1699

    We will need to add support for the hash type in the future and the array of hashes.
    https://docs.gitlab.com/ee/api/#hash

  10. angegar commented on Dec 7, 2021

    Author

    OK, thus i have i will have to change my code. Thank you for your investigation.

  11. w7089 commented on Mar 20, 2023

    I see that 1735 got merged, but i'm still getting Impossible to create object (400: allowed_to_push is invalid) error on gitlab --debug --verbose project-protected-branch create --project-id 29 --name main --allowed-to-push '[{"access_level": 0}]'.

    I thought the array ALLOWED_TO_MERGE has to follow the API

    Am I wrong?

    The debug mode of the above cli command shows:

    send: b'{"name": "main", "allowed_to_push": "[{\\"access_level\\": 0}]"}'
    
  12. github-actions commented on Jul 9, 2025

    This issue was marked stale because it has been open 60 days with
    no activity. Please remove the stale label or comment on this
    issue. Otherwise, it will be closed in 15 days.

    As an open-source project, we rely on community contributions to
    address many of the reported issues. Without a proposed fix or
    active work towards a solution it is our policy to close inactive
    issues. This is documented in CONTRIBUTING.rst

    How to keep this issue open:

    • If you are still experiencing this issue and are willing to
      investigate a fix, please comment and let us know.
    • If you (or someone else) can propose a pull request with a
      solution, that would be fantastic.
    • Any significant update or active discussion indicating progress
      will also prevent closure.

    We value your input. If you can help provide a fix, we'd be happy
    to keep this issue open and support your efforts.

    This is documented in CONTRIBUTING.rst
    https://github.com/python-gitlab/python-gitlab/blob/main/CONTRIBUTING.rst

  13. github-actions commented on Jul 24, 2025

    This issue was closed because it has been marked stale for 15 days
    with no activity.

    This open-source project relies on community contributions, and
    while we value all feedback, we have a limited capacity to address
    every issue without a clear path forward.

    Currently, this issue hasn't received a proposed fix, and there
    hasn't been recent active discussion indicating someone is planning
    to work on it. To maintain a manageable backlog and focus our
    efforts, we will be closing this issue for now.

    This doesn't mean the issue isn't valid or important. If you or
    anyone else in the community is willing to investigate and propose
    a solution (e.g., by submitting a pull request), please do.

    We believe that those who feel a bug is important enough to fix
    should ideally be part of the solution. Your contributions are
    highly welcome.

    Thank you for your understanding and potential future
    contributions.

    This is documented in CONTRIBUTING.rst
    https://github.com/python-gitlab/python-gitlab/blob/main/CONTRIBUTING.rst

  14. locked as resolved and limited conversation to collaborators on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL