Skip to content

Instantly share code, notes, and snippets.

@bpceee
Created May 23, 2018 10:52
Show Gist options
  • Save bpceee/a009f5f68be9cf8c91ebe932b746c658 to your computer and use it in GitHub Desktop.
Save bpceee/a009f5f68be9cf8c91ebe932b746c658 to your computer and use it in GitHub Desktop.
openOdestCommitPage
(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