Skip to content

Instantly share code, notes, and snippets.

@shalomb
Last active October 24, 2023 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shalomb/61e19a41f23a34bb69022ff8945f14f3 to your computer and use it in GitHub Desktop.
Save shalomb/61e19a41f23a34bb69022ff8945f14f3 to your computer and use it in GitHub Desktop.
Update git content via API
#!/bin/bash
set -eu -o pipefail
content="foo and bar and baz"
content="$(base64 <<<"$content")"
sha=$(git ls-files -s foo | awk '{print $2}')
# curl -L \
# -X DELETE \
# -H "Accept: application/vnd.github+json" \
# -H "Authorization: Bearer ghp_4YXXXXXXJN" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/octokat/terraform-developer-ShalomBhooshi/contents/foo \
# -d '{"message":"my commit message","committer":{"name":"Monalisa Octocat","email":"octocat@github.com"},"sha":"0d5a690c8fad5e605a6e8766295d9d459d65de42"}'
curl -L \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ghp_4YXXXXXXJN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/oktokat/demorepo/contents/foo \
-d '{
"message":"my commit message",
"branch": "bom-stream",
"committer":{
"name":"Monalisa Octocat",
"email":"octocat@github.com"
},
"content":"'"$content"'",
"sha": "'"$sha"'"
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment