Created
May 23, 2018 10:52
-
-
Save bpceee/a009f5f68be9cf8c91ebe932b746c658 to your computer and use it in GitHub Desktop.
openOdestCommitPage
This file contains 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
(function openOdestCommitPage([_, repo, branch='master']) { | |
return fetch('https://api.github.com/repos/' + repo + '/commits?sha=' + branch) | |
// the link header has additional urls for paging | |
// parse the original JSON for the case where no other pages exist | |
.then(res => Promise.all([res.headers.get('link'), res.json()])) | |
// get last page of commits | |
.then(([link, commits]) => { | |
if (!link) { | |
return; | |
} | |
let pageurl = link.split(',')[1].split(';')[0].slice(2, -1); | |
let totalPage = Number(pageurl.split('page=').pop()); | |
let firstCommitId = commits[0].sha; | |
var afterNum = (totalPage - 1) * 30; | |
var url = `https://github.com/${repo}/commits/${branch}?after=${firstCommitId}+${afterNum}`; | |
window.location = url; | |
}) | |
})(window.location.pathname.match(/\/([^\/]+\/[^\/]+)(?:\/(?:tree|commits)\/(.+))?/)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment