Created
October 1, 2016 00:55
-
-
Save JamesWP/9ef8eff086da854aa057f5f97483df8c to your computer and use it in GitHub Desktop.
Slowest way to find base commit of repo on github
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
| var apibase = 'https://api.github.com/repos/Homebrew/brew'; | |
| var auth = { | |
| username: '<CHANGEME>', | |
| apikey: '<CHANGEME>' | |
| }; | |
| auth.token = 'Basic ' + btoa(auth.username + ':' + auth.apikey); | |
| var opts = { | |
| method: 'GET', | |
| headers: {'Authorization': auth.token} | |
| }; | |
| var dbgPrint = (msg) => ( (value) => { console.log(msg + ': %o', value); return value;} ) | |
| var apiReq = (url)=>fetch(apibase + url, opts).then(function (response) { return response.json();}) | |
| var getFirstSha = () => apiReq('/commits').then(obj=>obj[0].sha); | |
| var getParentSha = (childSha) => { | |
| return apiReq('/git/commits/' + childSha) | |
| .then(obj=>( obj.parents.length!==0 ? obj.parents[0].sha : {final:obj.sha} ) ); | |
| var finished = (obj) => { return typeof(obj) == "object" }; | |
| var cont = sha => { | |
| if(finished(sha)) dbgPrint('Complete')(sha); // base case | |
| else getParentSha(sha).then(dbgPrint('Next')).then(cont); // reursive call | |
| }; | |
| getFirstSha() | |
| .then(dbgPrint('GetFistSha')) | |
| .then(cont); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment