Skip to content

Instantly share code, notes, and snippets.

@nickcarenza
Created April 3, 2017 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickcarenza/f9b4259f14a5cbe44e61da106f1908a2 to your computer and use it in GitHub Desktop.
Save nickcarenza/f9b4259f14a5cbe44e61da106f1908a2 to your computer and use it in GitHub Desktop.
Get first commit of private repo
// extended from https://github.com/FarhadG/init
(b=>fetch(new Request('https://api.github.com/repos/'+b[1]+'/commits?sha='+(b[2]||''),{
headers: new Headers({Authorization:'token ...'}),
}))
.then(c=>Promise.all([c.headers.get('link'),c.json()]))
.then(c=>{
if(c[0]){
var d=c[0].split(',')[1].split(';')[0].slice(2,-1);
return fetch(new Request(d,{
headers: new Headers({Authorization:'token ...'}),
})).then(e=>e.json());
}
return c[1];
})
.then(c=>c.pop().html_url)
.then(c=>window.location=c)
)(window.location.pathname.match(/\/([^\/]+\/[^\/]+)(?:\/tree\/([^\/]+))?/));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment