0

Currently in the github UI, a user can edit a file and create a new branch in a single action. This can also be done through the github api using something like this:

curl 'https://github.com/<my_org>/<my_repo>/tree-save/master/<path_to_file>' \
  -H 'content-type: application/x-www-form-urlencoded' \
  --data-raw 'authenticity_token=<generated_token>&filename=<filename>&new_filename=<filename>&content_changed=true&value=<new_contents_of_file>&message=Updated+file+in+my+repo&placeholder_message=Update+<filename>&description=&commit-choice=quick-pull&target_branch=<new_branch_name>&quick_pull=master&guidance_task=&commit=<target_commit_checksum>&same_repo=1&pr='

What I would like to be able to do, is perform the same action using the github cli* (gh). I have tried using the following commands:

gh api <my_org>/<my_repo>/tree-save/master/<path_to_file> -F "filename=<filename>" -F ...

and

gh api repos/<my_org>/<my_repo>/contents/<path_to_file> -F "filename=<filename>" -F ...

For both cases (and many variations on these options), I'm getting a 404** back. Any ideas what I'm doing wrong? Does the github cli even allow the functionality allowed in the above curl?

* For those curious, I want to use the CLI because of how it handles auth and it's statelessness. I can't generate a token to use, like in the curl above. And, due to multiple issues, I also can't clone the repo locally.

** I'm able to retrieve the file just fine using the simple GET command (the second command above without the '-F' flags)

JRogerC
  • 598
  • 6
  • 17

1 Answers1

0

After reading documentation, and then verifying by altering credentials, it appears to be a permissions issue. Evidently, for security reasons, if a token is used that does not meet the required permissions, a 404 is returned instead of a 403.

Interesting that I can still use the curl above through the browser. So, now i need to figure out why the gh cli token does not have the same permissions as my user.

JRogerC
  • 598
  • 6
  • 17