Created
July 10, 2018 21:52
-
-
Save DV8FromTheWorld/8e39cdc8273ccb27c04bd22fe53cfbda to your computer and use it in GitHub Desktop.
First Github Commit w/ Auth Support
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
javascript: | |
const token = '<TOKEN>'; | |
const opts = {}; | |
if (token !== '<TOKEN>') { | |
opts.headers = { | |
'Authorization': 'token ' + token | |
} | |
}; | |
(b => fetch('https://api.github.com/repos/' + b[1] + '/commits?sha=' + (b[2] || ''), opts) | |
.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(d, opts).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