-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
64 lines (53 loc) · 2.23 KB
/
bot.js
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
const axios = require("axios");
const fs = require("fs");
const moment = require("moment");
const readline = require("readline");
const rl = readline.createInterface(process.stdin, process.stdout);
rl.question("Repository owner: ", function (owner) {
rl.question("Repository name: ", function (name) {
rl.question("File name: ", function (fname) {
const repoOwner = owner; //The owner of the repository you want to access
const repoName = name; //The name of the repository you want to access
const apiUrl = `https://api.github.com/repos/${repoOwner}/${repoName}/pulls?state=closed&sort=created&direction=desc`;
const outputFilePath = `${fname}.md`; //Edit the filename to be created as in the example
axios
.get(apiUrl)
.then(async (response) => {
const closedPullRequests = response.data.filter((pr) => {
const closedAt = moment(pr.closed_at);
return closedAt.isBetween(startDate, endDate);
});
const markdownContent = await generateMarkdown(closedPullRequests);
fs.writeFile(outputFilePath, markdownContent, (err) => {
if (err) {
console.error("Error writing file:", err);
} else {
console.log(`File "${outputFilePath}" created successfully.`);
}
});
})
.catch((error) => {
console.error("Error fetching data:", error);
});
rl.close();
});
});
});
const startDate = "2023-08-12T00:00:00Z"; //Set the start date in the date range you want to access
const endDate = "2023-08-26T23:59:59Z"; //Set the first date in the date range you want to access
const generateMarkdown = async (pullRequests) => {
let markdown = "";
for (const pr of pullRequests) {
markdown += `## [${pr.title}](${pr.html_url})\n\n`;
markdown += `##${pr.body}\n`;
const contributor = await getContributor(pr.user.login);
markdown += `### Contributor: [${contributor.login}](${contributor.html_url})\n`;
markdown += `### Link: ${pr.html_url}\n`;
markdown += `-----\n`;
}
return markdown;
};
const getContributor = async (login) => {
const response = await axios.get(`https://api.github.com/users/${login}`);
return response.data;
};