Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save duncdrum/13abbf99c4418e4c88dea30485fe447a to your computer and use it in GitHub Desktop.
Save duncdrum/13abbf99c4418e4c88dea30485fe447a to your computer and use it in GitHub Desktop.
xquery version "3.1";
import module namespace http = "http://expath.org/ns/http-client";
(: For generating the personal access token to be used in this script, please select "public_repo | Access public repositories". :)
let $git-token := "<your-github-token>"
let $user-name := "<your-github-username>"
let $repo-name := "<your-repo-name>"
let $file-path := "<file=path>"
let $message := "<commit-message>"
let $new-file-content := serialize(<a/>)
let $json-serialization-parameters :=
<output:serialization-parameters xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization">
<output:method value="json"/>
<output:media-type value="text/javascript"/>
</output:serialization-parameters>
let $file-url := xs:anyURI("https://api.github.com/repos/" || $user-name || "/" || $repo-name || "/contents/" || $file-path)
let $authorisation-header := <http:header name="Authorization" value="{concat('token ', $git-token)}"/>
let $file-sha-request :=
<http:request href="{$file-url}" method="GET">
{$authorisation-header}
</http:request>
let $file-sha-response := http:send-request($file-sha-request)[2]
let $file-sha :=
let $decoded-response := util:base64-decode($file-sha-response)
return map:get(parse-json($decoded-response), "sha")
let $commit-file-parameters :=
<json>
<path>{$file-path}</path>
<message>{$message}</message>
<content>{util:base64-encode($new-file-content)}</content>
<sha>{$file-sha}</sha>
</json>
let $commit-file-request :=
<http:request href="{$file-url}" method="PUT">
{$authorisation-header}
<http:body media-type="text/javascript">
{serialize($commit-file-parameters, $json-serialization-parameters)}
</http:body>
</http:request>
let $commit-file := http:send-request($commit-file-request)
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment