3 ms·
author here
by wonderfuly 11y ago
author here
- brudgers 11y agoHow does the code work?
- wonderfuly 11y agoyou can check out the source code here: https://github.com/wong2/first-commit https://github.com/wong2/first-commit
- jasode 11y agoI think wonderfuly's reply missed the point of the question which is to explain it without having someone dissect the source code line by line. Anyways, I did a quick look at the source file[1] and it looks like it depends on the assumption of github returning 35 commit titles per page. From that, it divides total # of commits by 35 to derive the url for the last page containing the 1st commit. (The url you'd arrive at if you if you repeatedly clicked the "Older" button on github to get to the final page which contains the 1st commit.) It then scrapes that url for relevant data. (It uses the cheerio library to help with scraping.) I'm not familiar enough with github's HTML navigation and page formatting to know if this method is fragile or robust. Github does offer an API[2] so it may be possible to get the 1st commit that way instead of scraping HTML that was intended for display in a web browser. Excerpt of the arithmetic: function getFirstPageUrl(repo, num_of_commits) { const COMMITS_PER_PAGE = 35; var first_page = Math.ceil(num_of_commits / COMMITS_PER_PAGE); return `${BASE_URL}/${repo}/commits?page=${first_page}`; } [1]https://github.com/wong2/first-commit/blob/master/app/github.js#L37 https://github.com/wong2/first-commit/blob/master/app/github... [2]https://developer.github.com/v3/git/commits/ https://developer.github.com/v3/git/commits/
- wonderfuly 11y agothanks for you explanation!
- brudgers 11y agoYes, my intent was to provide the author a chance to talk about their work and share their enthusiasm. It's why I asked about code, since the answer "to how does it work?" is "type the repository url into the box".
- neverpanic 11y agoDoesn't seem to work with a test export I made for MacPorts: http://first-commit.com/neverpanic/macports-ports http://first-commit.com/neverpanic/macports-ports says https://github.com/neverpanic/macports-ports/commit/46e4271b506ab4b493c1c9e854634c69d323760a https://github.com/neverpanic/macports-ports/commit/46e4271b... is the first commit, but it really is https://github.com/neverpanic/macports-ports/commit/876ca39254fa677cca66b716964be468c94d899f https://github.com/neverpanic/macports-ports/commit/876ca392....