Skip to content

Instantly share code, notes, and snippets.

@scips
Created November 28, 2017 14:45
Show Gist options
  • Save scips/0329d8eee140d3e2bbc4e71c0ad1540e to your computer and use it in GitHub Desktop.
Save scips/0329d8eee140d3e2bbc4e71c0ad1540e to your computer and use it in GitHub Desktop.
Quickly upload an XML file to a gist command line

XML 2 secret gist + oauth

Why

I wanted to automatically retrieve an xml file (phpunit junit log) from a travis server.

I don't know why but rsync and scp failed so I assumed I could post it to pastebin but the pulbic api shut down years ago.

So I tried with github and gist...

I have 2 factor authentication... and I wanted an easy easy way to do things so I finally found the option to create a token password with limited scope. And that's awesome and easy.

How

  1. Go to your account and create a secret token with limited scope (check only gist)
  2. Copy and store the token value (you will not be able to see it after a while)
  3. Now you can try in command line the token curl -u username:token https://api.github.com/user
  4. The limit is the JSON, so you will have to put your file in json. I used the following php script with php -a
$content=file_get_contents("log/test.xml");
$topost = ["description"=>"test xml","public"=>false,"files"=>["test.xml"=>["content"=>""]]];
$topost["files"]["test.xml"]["content"]=$content;
file_put_contents("log/test.xml.gist.json",json_encode($topost));

It will create the log/test.xml.gist.json file that contains the payload that will create a gists:

  • private
  • with the description: text xml
  • with a file: text.xml
  • that contains: the xml generated by phpunit

Now it's time to push it to gists.

Just follow the gist api

curl -u username:**token** -d @log/test.xml.gist.json  https://api.github.com/gists

That's all Folk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment