Created
October 17, 2016 07:14
-
-
Save claudius108/8c687fc72b8d210c686181a6bc150bb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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