Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
matbrady committed Aug 17, 2017
1 parent 64dc192 commit 96ae75e
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Ignore local dev only files

*.cache
*.dump
*.gem
*.log
*.pid
*.rbc
*.sqlite3
*.sqlite3-journal
.bundle
.config
.env
.env.test
.yardoc
config/database.yml
coverage
export
InstalledFiles
lib/bundler/man
node_modules
pkg
public/system/**/*
/public/packs
/public/packs-test
rdoc
rerun.txt
spec/reports
spec/tmp/**/*
tags
test/tmp
test/version_tmp
vendor/**/*
vim/.netrwhist
zeus.json
_yardoc

# Ignore compilation junk

**.orig
*.rbc
*.sassc
*.sw[nop]
.rspec
.sass-cache
capybara-*.html
pickle-email-*.html
rerun.txt

# Ignore filesystem trash

*.DS_Store
*Thumbs.db
.DS_Store?
ehthumbs.db
Thumbs.db

# Ignore tmp/, but keep it empty in the repo
# Rails does not always automatically create this folder for you

tmp/**/*

# Ignore log/, but keep it empty in the repo
# Rails does not always automatically create this folder for you

log/**/*

# Specifically DO NOT ignore these other things

!.gitignore
!.slugignore
!.ruby-version
!*.gitkeep
!*.keep
/public/packs
/node_modules
*.csv
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 8.4.0
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Github Issue Exporter

A script written in Node to export Github issues into a csv file using their Graphql API.

## Running the Script

```shell
node index.js --token YOUR_TOKEN --owner REPO_OWNER --repo REPO_NAME
```

### Script Options

```
Usage: node index.js [options]
Options:
--token [value] Github OAuth token
--owner [value] Github repo owner name
--repo [value] Github repo name
```

## Modifying the Query
91 changes: 91 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const graphql = require("graphql-request");
const json2csv = require("json2csv");
const fs = require("fs");
const argv = require("minimist")(process.argv.slice(2));
const fileName = "issues.csv";

const fields = [
"node.title",
"node.number",
"node.state",
"node.author.login",
"node.bodyText",
"node.url",
"node.milestone.id",
"node.labels.edges.node.name",
"node.comments.edges.node.bodyText",
"node.comments.edges.node.createdAt",
"node.comments.edges.node.author.avatarUrl",
"node.comments.edges.node.author.login",
"node.comments.edges.node.author.resourcepath",
"node.comments.edges.node.author.url"
];

const client = new graphql.GraphQLClient("https://api.github.com/graphql", {
headers: {
Authorization: `Bearer ${argv.token}`
}
});

// console.log(argv);

const query = `{
repository(owner: "${argv.owner}", name: "${argv.repo}") {
issues(last: 100, states: OPEN) {
edges {
node {
title
number
state
author {
login
}
bodyText
url
milestone {
id
}
labels(first: 10) {
edges {
node {
name
}
}
}
comments(last: 3) {
edges {
node {
author {
avatarUrl
login
resourcePath
url
}
bodyText
createdAt
}
}
}
}
}
}
}
}`;

client
.request(query)
.then(data => {
const json2csvConfig = {
data: data.repository.issues.edges,
fields: fields,
includeEmptyRows: true,
unwindPath: ["node.labels.edges", "node.comments.edges"]
};
const csv = json2csv(json2csvConfig);

fs.writeFile(fileName, csv, function(err) {
if (err) throw err;
console.log(`${fileName} file saved`);
});
})
.catch(error => console.error(error));
118 changes: 118 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


cli-table@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/cli-table/-/cli-table-0.3.1.tgz#f53b05266a8b1a0b934b3d0821e6e2dc5914ae23"
dependencies:
colors "1.0.3"

[email protected]:
version "1.0.3"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"

commander@^2.8.1:
version "2.11.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"

debug@^2.2.0:
version "2.6.8"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
dependencies:
ms "2.0.0"

encoding@^0.1.11:
version "0.1.12"
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
dependencies:
iconv-lite "~0.4.13"

flat@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/flat/-/flat-2.0.1.tgz#70e29188a74be0c3c89409eed1fa9577907ae32f"
dependencies:
is-buffer "~1.1.2"

graphql-request@^1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-1.3.4.tgz#94d5f2e6644d9d9cbce0d06953e100c30e5cb633"
dependencies:
isomorphic-fetch "^2.2.1"

iconv-lite@~0.4.13:
version "0.4.18"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.18.tgz#23d8656b16aae6742ac29732ea8f0336a4789cf2"

is-buffer@~1.1.2:
version "1.1.5"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc"

is-stream@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"

isomorphic-fetch@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
dependencies:
node-fetch "^1.0.1"
whatwg-fetch ">=0.10.0"

json2csv@^3.11.1:
version "3.11.1"
resolved "https://registry.yarnpkg.com/json2csv/-/json2csv-3.11.1.tgz#347756566910ccb323062a9436cb13717b81f9b7"
dependencies:
cli-table "^0.3.1"
commander "^2.8.1"
debug "^2.2.0"
flat "^2.0.0"
lodash.clonedeep "^4.5.0"
lodash.flatten "^4.4.0"
lodash.get "^4.4.0"
lodash.set "^4.3.0"
lodash.uniq "^4.5.0"
path-is-absolute "^1.0.0"

lodash.clonedeep@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"

lodash.flatten@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"

lodash.get@^4.4.0:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"

lodash.set@^4.3.0:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"

lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"

minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"

node-fetch@^1.0.1:
version "1.7.2"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.2.tgz#c54e9aac57e432875233525f3c891c4159ffefd7"
dependencies:
encoding "^0.1.11"
is-stream "^1.0.1"

path-is-absolute@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"

whatwg-fetch@>=0.10.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz#9c84ec2dcf68187ff00bc64e1274b442176e1c84"

0 comments on commit 96ae75e

Please sign in to comment.