quinton-ashley
quinton-ashley

Reputation: 140

Can an npm script publish a package to Github using the Github API?

I'm trying to use this script to make a first commit and publish a package to Github publicly. { "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" } } I keep getting this error. I've scoured the docs and can't figure out why. Is this not possible? Please help! { "message": "Not Found", "documentation_url": "https://developer.github.com/v3" }

EDIT: Here's the working script! I had to make some changes to merge with Github's origin/master original commit that adds the license file. 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"

Upvotes: 1

Views: 173

Answers (1)

VonC
VonC

Reputation: 1327324

Try and remove commands from your script until it is working, in order to determine what part triggers that message.

The https://api.github.com/'$npm_package_author_name'/'$npm_package_name URL seems odd, since The GitHub API usually has a generic name after https://api.github.com/, like https://api.github.com/user (User API)

You could also consider more established npm packages, like release-it.

Upvotes: 1

Related Questions