Skip to content

Instantly share code, notes, and snippets.

@ishikawam
Last active July 2, 2023 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishikawam/48c026a353be9cfa4ddbd0bbf664492d to your computer and use it in GitHub Desktop.
Save ishikawam/48c026a353be9cfa4ddbd0bbf664492d to your computer and use it in GitHub Desktop.
githubのプロフィールページからContribution activityのサマリーをテキストで出力
/**
* githubのプロフィールページからContribution activityのサマリーをテキストで出力
* "Show more activity" で開いて表示されている分を取得する
*/
(function () {
const commits = new Map();
const openedSet = new Set();
const reviewedSet = new Set();
document.querySelectorAll('div.TimelineItem-body > details.Details-element.details-reset').forEach(function (c) {
type = c.querySelector('summary > span').textContent.trim().match(/^(.*) /);
type = type ? type[1] : "NONE";
switch (type) {
case "Created":
c.querySelectorAll("li").forEach(function (c) {
if (c.querySelector("a.f6") == null) {
return;
}
const commit = Number(c.querySelector("a.f6").text.trim().replace(/ .*/, ""));
const repo = c.querySelector("a[data-hovercard-type]").text;
commits.set(repo, (commits.get(repo) ?? 0) + commit);
});
break;
case "Opened":
c.querySelectorAll('details.my-1 a').forEach(function (c) {
const pull = c.href.replace(/https:\/\/github\.com\//, '');
const repo = pull.replace(/\/pull\/.*/, '');
openedSet.add(pull + " : " + c.text.trim());
});
break;
case "Reviewed":
c.querySelectorAll('details.my-1 a').forEach(function (c) {
const pull = c.href.replace(/https:\/\/github\.com\//, '');
const repo = pull.replace(/\/pull\/.*/, '');
reviewedSet.add(pull + " : " + c.text.trim());
});
break;
case "NONE":
break;
default:
console.log("UNKNOWN TYPE!! : " + type);
}
});
// created a pull request をopenedに追加
document.querySelectorAll('div[data-repository-hovercards-enabled="true"] a[data-hovercard-type="pull_request"]').forEach(function (c) {
openedSet.add(c.href.replace(/https:\/\/github\.com\//, '') + " : " + c.text);
});
const opened = new Map();
openedSet.forEach(function (c) {
const repo = c.replace(/\/pull\/.*/, '');
opened.set(repo, (opened.get(repo) ?? 0) + 1);
});
const reviewed = new Map();
reviewedSet.forEach(function (c) {
const repo = c.replace(/\/pull\/.*/, '');
reviewed.set(repo, (reviewed.get(repo) ?? 0) + 1);
});
console.log({commits: commits, opened: opened, openedSet: openedSet, reviewed: reviewed, reviewedSet: reviewedSet});
// サマリー
let report = "\nサマリー\n";
let total = 0;
report += "\nCommits:\n";
[...commits].sort().forEach(function (c) {
report += (c[0] + " : " + c[1] + "\n");
total += c[1];
});
report += "Total: " + total + "\n";
total = 0;
report += "\nOpened pull requests:\n";
[...opened].sort().forEach(function (c) {
report += (c[0] + " : " + c[1] + "\n");
total += c[1];
});
report += "Total: " + total + "\n";
total = 0;
report += "\nReviewed pull requests:\n";
[...reviewed].sort().forEach(function (c) {
report += (c[0] + " : " + c[1] + "\n");
total += c[1];
});
report += "Total: " + total + "\n";
report += "\n";
console.log(report);
// pull requests 詳細
report = "\nすべて\n";
report += "\nAll opened pull requests:\n";
[...openedSet].sort().forEach(function (c) {
report += c + "\n";
});
report += "\nAll reviewed pull requests:\n";
[...reviewedSet].sort().forEach(function (c) {
report += c + "\n";
});
report += "\n";
console.log(report);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment