Created
August 10, 2016 18:43
-
-
Save nucleartide/fbdcabc04287e21f313330f73ed8d351 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// seeing if github always returns a 409 conflict - seems like it does | |
// this is also a good way of teasing out github's error responses, which are undocumented (or i haven't browsed the docs carefully enough) | |
const co = require('co') | |
const request = require('superagent') | |
const sleep = require('co-sleep') | |
const btoa = require('btoa') | |
const token = process.env.TOKEN | |
if (!token) throw new Error('need token') | |
// get | |
// update 1 | |
// wait | |
// update 2, using same sha | |
co(function*(){ | |
let res = yield request | |
.get('https://api.github.com/repos/RisingTideGames/slots-live-data-dev/contents/test.json') | |
.set('Authorization', `token ${token}`) | |
.then(res => res.body) | |
console.log('get succeeded') | |
yield sleep(3 * 1000) | |
let res2 = yield request | |
.put('https://api.github.com/repos/RisingTideGames/slots-live-data-dev/contents/test.json') | |
.set('Authorization', `token ${token}`) | |
.send({ | |
message: 'first update', | |
content: btoa(JSON.stringify({ | |
first: 'update' | |
}, null, 4) + '\n'), | |
sha: res.sha, | |
}) | |
console.log('update 1 succeeded') | |
yield sleep(3 * 1000) | |
let res3 = yield request | |
.put('https://api.github.com/repos/RisingTideGames/slots-live-data-dev/contents/test.json') | |
.set('Authorization', `token ${token}`) | |
.send({ | |
message: 'second update', | |
content: btoa(JSON.stringify({ | |
second: 'update' | |
}, null, 4) + '\n'), | |
sha: res.sha, | |
}) | |
console.log('update 2 succeeded') | |
}).catch(err => { | |
console.log('status:', err.status) | |
console.error(err.stack) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment