Skip to content

Instantly share code, notes, and snippets.

@RammusXu
Last active November 28, 2024 20:44
Show Gist options
  • Save RammusXu/f3a01b4fe0fbc2096d65bf36204580ed to your computer and use it in GitHub Desktop.
Save RammusXu/f3a01b4fe0fbc2096d65bf36204580ed to your computer and use it in GitHub Desktop.
Github REST API update file with commit
REPO=rammus/action-demo
FILE=README.md
INPUT_GITHUB_TOKEN=
# https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#get-repository-content
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $INPUT_GITHUB_TOKEN" \
"https://api.github.com/repos/${REPO}/contents/${FILE}"
# https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#create-or-update-file-contents
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $INPUT_GITHUB_TOKEN" \
"https://api.github.com/repos/${REPO}/contents/${FILE}" \
-d '{"message":"message","content":"'$(echo content|base64)'", "sha":"SHA_FROM_ABOVE"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment