【问题标题】:Can an npm script publish a package to Github using the Github API?npm 脚本可以使用 Github API 将包发布到 Github 吗?
【发布时间】:2018-11-25 20:27:33
【问题描述】:

我正在尝试使用此脚本进行首次提交并将包公开发布到 Github。 { "scripts": { "first": "git add -A && git commit -m \"First commit\" && A='{\"name\":\"'$npm_package_name'\",\"description\":\"'$npm_package_description'\",\"license_template\":\"'$npm_package_license'\"}' && echo \"${A}\" && curl -u $npm_package_author_name 'https://api.github.com/'$npm_package_author_name'/'$npm_package_name -d \"$A\" && git remote add origin 'https://github.com/'$npm_package_author_name'/'$npm_package_name'.git' && git push -u origin master" } } 我不断收到此错误。我已经搜索了文档,但不知道为什么。这不可能吗?请帮忙! { "message": "Not Found", "documentation_url": "https://developer.github.com/v3" }

编辑: 这是工作脚本!我必须进行一些更改才能与添加许可证文件的 Github 的原始/主原始提交合并。 github api create repository doc for reference

"first": "O='{\"name\":\"'$npm_package_name'\",\"description\":\"'$npm_package_description'\",\"license_template\":\"'$npm_package_license'\"}' && echo \"${O}\" && curl -u $npm_package_author_name https://api.github.com/user/repos -d \"${A}\" && git add -A && git commit -m \"initial\" && git remote add origin 'https://github.com/'$npm_package_author_name'/'$npm_package_name'.git' && git merge origin/master --allow-unrelated-histories -m $npm_package_version && git push --set-upstream origin master && git push && git push --tags"

【问题讨论】:

    标签: bash npm github-api npm-scripts


    【解决方案1】:

    尝试从脚本中删除命令,直到脚本正常运行,以确定触发该消息的部分。

    https://api.github.com/'$npm_package_author_name'/'$npm_package_name URL 看起来很奇怪,因为GitHub API 通常在https://api.github.com/ 之后有一个通用名称,例如https://api.github.com/user (User API)

    您还可以考虑更成熟的 npm 包,例如 release-it

    【讨论】:

    • 谢谢哈哈 我以为api.github.com/user 中的用户一词只是用户名的占位符?
    • @quinton.ashley 是的,一般占位符是:xxx(冒号在前),比如GET /users/:username:你需要替换:username,而不是users
    猜你喜欢
    • 2022-09-24
    • 2021-01-01
    • 2022-10-21
    • 2021-04-08
    • 2014-08-19
    • 2021-06-27
    • 2016-05-03
    • 2021-11-02
    • 2021-03-20
    相关资源
    最近更新 更多