目前在 github UI 中,用户可以在单个操作中编辑文件并创建新分支。这也可以通过 github api 使用如下方式完成:
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='
我想做的是使用 github cli* (gh) 执行相同的操作。我尝试使用以下命令:
gh api <my_org>/<my_repo>/tree-save/master/<path_to_file> -F "filename=<filename>" -F ...
和
gh api repos/<my_org>/<my_repo>/contents/<path_to_file> -F "filename=<filename>" -F ...
对于这两种情况(以及这些选项的许多变体),我都得到了 404**。任何想法我做错了什么?github cli 是否甚至允许上述 curl 中允许的功能?
* 对于那些好奇的人,我想使用 CLI,因为它如何处理身份验证并且它是无状态的。我无法生成要使用的令牌,就像上面的 curl 一样。而且,由于多个问题,我也无法在本地克隆 repo。
** 我可以使用简单的 GET 命令很好地检索文件(上面的第二个命令没有'-F'标志)