Skip to content

gitlab project-commit create does not work with valid actions #3052

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

Open
Anthony-Fiddes opened this issue Nov 29, 2024 · 1 comment
Open
Labels

Comments

@Anthony-Fiddes
Copy link

Anthony-Fiddes commented Nov 29, 2024

Description of the problem, including code/CLI snippet

It appears that the CLI may be passing the actions flag as a string instead of as JSON. I saw this potentially related discussion (it's an old discussion, so it may be out of date), but I couldn't find a corresponding issue.

Command run: gitlab -d project-commit create --project-id ****** --branch main --commit-message 'create multiple/' --actions '[{"action": "create", "file_path": "multiple/file-to-commit1.txt", "content": "@multiple/file-to-commit1.txt"}, {"action": "create", "file_path": "multiple/file-to-commit2.txt", "content": "@multiple/file-to-commit2.txt"}, {"action": "create", "file_path": "multiple/file-to-commit3.txt", "content": "@multiple/file-to-commit3.txt"}]'

Output:

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): *************:443
DEBUG:http.client:send: b'GET /api/v4/user HTTP/1.1\r\nHost: *************\r\nUser-Agent: *********************\r\nAccept-Encoding: gzip, deflate\r\nAccept: _/_\r\nConnection: keep-alive\r\nContent-type: application/json\r\nAuthorization: Bearer [MASKED]\r\n\r\n'
DEBUG:http.client:reply: 'HTTP/1.1 200 OK\r\n'
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Date: Fri, 29 Nov 2024 16:18:55 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Transfer-Encoding: chunked
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Vary: Accept-Encoding
DEBUG:http.client:header: Cache-Control: max-age=0, private, must-revalidate
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation*id":"***********","version":"1"}
DEBUG:http.client:header: X-Request-Id: ***************
DEBUG:http.client:header: Referrer-Policy: strict-origin-when-cross-origin
DEBUG:http.client:header: Content-Encoding: gzip
DEBUG:urllib3.connectionpool:https://*************:443 "GET /api/v4/user HTTP/11" 200 None
DEBUG:http.client:send: b'POST /api/v4/******/repository/commits
HTTP/1.1\r\nHost: *************\r\nUser-Agent: **********\r\nAccept-Encoding: gzip, deflate\r\nAccept: */\_\r\nConnection: keep-alive\r\nContent-type: application/json\r\nContent-Length: 368\r\nAuthorization: Bearer [MASKED]\r\n\r\n'

LINE OF POTENTIAL INTEREST
vvvvvvvvvvvvvvvvvvvvvvvvvvv
DEBUG:http.client:send: b'{"branch": "main", "commit_message": "create multiple/", "actions": "[{action: create, file_path: multiple/file-to-commit1.txt, content: @multiple/file-to-commit1.txt}, {action: create, file_path: multiple/file-to-commit2.txt, content: @multiple/file-to-commit2.txt}, {action: create, file_path: multiple/file-to-commit3.txt, content: @multiple/file-to-commit3.txt}]"}'


DEBUG:http.client:reply: 'HTTP/1.1 400 Bad Request\r\n'
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Date: Fri, 29 Nov 2024 16:18:55 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Content-Length: 30
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Cache-Control: no-cache
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation_id":"***************","version":"1"}
DEBUG:http.client:header: X-Request-Id: ***************
DEBUG:urllib3.connectionpool:https://*************:443 "POST /api/v4/******/repository/commits HTTP/11" 400 30
Impossible to create object (400: actions is invalid)

Expected Behavior

Create a new commit in the repo with the new files.

Actual Behavior

Fails with a 400 error saying "actions is invalid" (and it's possible I could be missing something here. I checked that my JSON was valid and checked with the official Gitlab API spec as first steps in debugging).

Specifications

  • python-gitlab version: 5.0.0
  • Gitlab server version (or gitlab.com):
@nejch nejch added the cli label Dec 5, 2024
@nejch
Copy link
Member

nejch commented Dec 5, 2024

Thanks for the report @Anthony-Fiddes! Yes, this is currently still an issue with the CLI unfortunately and we haven't picked this up. See #1735 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants