-
-
Save TheMetaphysicalCrook/6ec0b80b38bca18a25d0de9c06578de0 to your computer and use it in GitHub Desktop.
Quick 'n dirty Github PR JSON to CSV
This file contains hidden or 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
#!/usr/bin/env node | |
/* eslint-disable camelcase, no-console */ | |
/** | |
* Quick 'n dirty Github PR JSON to CSV | |
* Grab JSON with: | |
* | |
* curl -u $USER https://api.github.com/repos/$ORG/$REPO/pulls?per_page=100 \ | |
* -H X-GitHub-OTP:\ 123456 > pulls.json | |
*/ | |
const fs = require("fs"); | |
const _ = require("lodash"); | |
const moment = require("moment"); | |
const pulls = JSON.parse(fs.readFileSync("./pulls.json")); | |
const getPrDetails = pr => ({ | |
number: pr.number, | |
user: pr.user.login, | |
title: pr.title, | |
html_url: pr.html_url, | |
head: pr.head.ref, | |
base: pr.base.ref, | |
created_at: moment(pr.created_at).format("DD-MMM-YYYY"), | |
updated_at: -1 * moment(pr.updated_at).diff(moment(), "days") | |
}); | |
const columnOrder = [ | |
"number", | |
"created_at", | |
"updated_at", | |
"user", | |
"head", | |
"base", | |
"title", | |
"html_url" | |
]; | |
const stripSeparators = (val) => val.toString().replace(/[,\t]/, ' '); | |
const formatPr = pr => _.at(pr, columnOrder).map(stripSeparators).join("\t"); | |
console.log(pulls.map(getPrDetails).map(formatPr).join("\n")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment