Skip to content

Instantly share code, notes, and snippets.

@wifeofvillon
Last active May 17, 2019 07:06
Show Gist options
  • Save wifeofvillon/a45f7e2e6cf74e3b9c5883e36b2d22eb to your computer and use it in GitHub Desktop.
Save wifeofvillon/a45f7e2e6cf74e3b9c5883e36b2d22eb to your computer and use it in GitHub Desktop.

One way to get the commit history of GitHub wiki on browser

It's a memorandum to get the commit history of GitHub wiki on browser by JavaScript.

overview

parse the history page(s) and generate TSV or JSON by JavaScript

code

parseGitHubHistory.js

note

  • You can read the commit history of all pages of GitHub wiki from this URL: https://github.com/${author}/${repository}/wiki/Home/_history
    • This page paginates every 25 items
  • If you want to get the data as a blob, you can arrange and use this script.
    • LICENCE: CC0
{
let history = new Array();
/**
* parse HTML and hold data in ${history}
*/
// get <ul>
let elemUl = document.querySelector('.Box--condensed ul');
// get <li>
let elemLi = elemUl.children;
for (li of elemLi) {
let rev = {
id: "",
title: "",
author: "",
date: ""
};
// get the hash
rev.id = li.lastElementChild.innerText;
let mainCol = li.lastElementChild.previousElementSibling;
// get the commit message
rev.title = mainCol.firstElementChild.innerText;
// get the author/date
let subLow = mainCol.lastElementChild;
rev.author = subLow.firstElementChild.firstElementChild.getAttribute('alt');
rev.date = subLow.lastElementChild.getAttribute('datetime');
history.push(rev);
}
// console.log(history);
/**
* parse JavaScript Object to TSV
*/
let tsvRaw = new Array();
for (low of history) {
console.log(low.date);
tsvRaw.push(`${low.date}\t${low.author}\t${low.title}\t${low.id}`)
}
/**
* create and put textarea and display data
*/
// create and put elements
let wrapDiv = document.createElement('div');
let textarea = document.createElement('textarea');
wrapDiv.appendChild(textarea);
// display JSON
// textarea.textContent = JSON.stringify(history);
// display TSV
textarea.textContent = tsvRaw.join("\n");
// append textarea bottom of the page
document.getElementsByTagName('body')[0].appendChild(wrapDiv, document.querySelector('div.gh-header'));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment