-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-experience.js
83 lines (69 loc) · 2.39 KB
/
generate-experience.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const { Octokit } = require('@octokit/rest');
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
const fs = require('fs');
const palisaDoesReadmeData = require('./Palisadoes/readmeData');
const cncfJaegerReadmeData = require('./CNCF - JaegerTracing/readmeData');
const asyncapiReadmeData = require('./AsyncAPI/readmeData');
// Input variables from the workflow
const token = process.env.GITHUB_TOKEN;
const author = 'anshgoyalevil';
const outputDirs = [
{
dirname: 'Palisadoes',
readmeData: palisaDoesReadmeData,
repository: 'PalisadoesFoundation/talawa-api',
},
{
dirname: 'CNCF - JaegerTracing',
readmeData: cncfJaegerReadmeData,
repository: 'jaegertracing/jaeger-ui',
},
{
dirname: 'AsyncAPI',
readmeData: asyncapiReadmeData,
repository: 'asyncapi/website',
}
];
const octokit = new Octokit({
auth: token,
request: {
fetch: fetch,
},
});
async function generateMarkdownTable() {
try {
for (let i = 0; i < outputDirs.length; i++) {
const [owner, repo] = outputDirs[i].repository.split('/');
// Fetch merged PRs by the author
const allPRs = [];
let page = 1;
while (true) {
const { data: prs } = await octokit.pulls.list({
owner,
repo,
state: 'closed',
sort: 'updated',
direction: 'asc',
per_page: 100,
page: page++,
});
if (prs.length === 0) break;
allPRs.push(...prs);
}
// Filter PRs by the author
const authorPRs = allPRs.filter((pr) => pr.user.login === author);
// Generate markdown table
const markdownTable = `
${outputDirs[i].readmeData}
| Date | Pull Request Title | Link to PR |
| --- | --- | --- |
${authorPRs.map((pr) =>
`| ${new Date(pr.merged_at).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', })} | ${pr.title} | [Link to PR](${pr.html_url}) |`).join('\n')}`;
fs.writeFileSync(`${outputDirs[i].dirname}/README.md`, markdownTable);
}
} catch (error) {
console.error(error.message);
process.exit(1);
}
}
generateMarkdownTable();