-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathscript.js
More file actions
82 lines (80 loc) · 2.03 KB
/
script.js
File metadata and controls
82 lines (80 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const fetch = require("node-fetch");
const createCsvWriter = require("csv-writer").createObjectCsvWriter;
require("dotenv").config();
let input = process.argv.slice(2);
let OWNER = input[0];
let REPO_NAME = input[1];
let NO_OF_REQUEST = input[2];
let obj;
const query = `query {
repository(owner: "${OWNER}", name: "${REPO_NAME}") {
url
pullRequests(first:${NO_OF_REQUEST}, states:OPEN) {
nodes {
number
url
state
author {
login
url
}
comments(first:100) {
nodes {
author {
login
}
bodyText
}
}
}
}
}
}
`;
(async function () {
let res;
try {
res = await fetch("https://api.github.com/graphql", {
method: "POST",
body: JSON.stringify({ query }),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.ACCESS_TOKEN}`,
},
});
let body = await res.text();
obj = JSON.parse(body);
const csvWriter = createCsvWriter({
path: "output.csv",
header: [
{ id: "repo", title: "Repository" },
{ id: "PR", title: "PR No." },
{ id: "url", title: `URL` },
{ id: "comments", title: "comments" },
{ id: "author", title: "username of commentor" },
],
});
let data = [];
let repo = obj.data.repository.url;
let node = obj.data.repository.pullRequests.nodes;
for (let i = 0; i < node.length; i++) {
let n = node[i];
let c = n.comments.nodes;
for (let j = 0; j < c.length; j++) {
let d = {
repo: `${repo}`,
PR: `${node[i].number}`,
url: `${node[i].url}`,
comments: `${c[j].bodyText}`,
author: `${c[j].author.login}`,
};
data.push(d);
}
}
csvWriter
.writeRecords(data)
.then(() => console.log("The CSV file was written successfully"));
} catch (err) {
console.log(err);
}
})();