2023-09-13 20:19:31 +02:00
|
|
|
import { rootDir } from './tool-utils';
|
|
|
|
|
2019-07-18 19:36:29 +02:00
|
|
|
const request = require('request');
|
|
|
|
|
2023-08-22 12:40:27 +02:00
|
|
|
interface Contributor {
|
|
|
|
avatar_url: string;
|
|
|
|
login: string;
|
|
|
|
html_url: string;
|
|
|
|
}
|
|
|
|
|
2023-09-13 20:19:31 +02:00
|
|
|
rootDir;
|
|
|
|
|
|
|
|
const readmePath = `${rootDir}/README.md`;
|
2019-07-18 19:36:29 +02:00
|
|
|
const { insertContentIntoFile } = require('./tool-utils.js');
|
|
|
|
|
2023-08-22 12:40:27 +02:00
|
|
|
async function gitHubContributors(page: number): Promise<Contributor[]> {
|
2019-07-18 19:36:29 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
request.get({
|
2019-09-19 23:51:18 +02:00
|
|
|
url: `https://api.github.com/repos/laurent22/joplin/contributors${page ? `?page=${page}` : ''}`,
|
2019-07-18 19:36:29 +02:00
|
|
|
json: true,
|
2020-02-05 00:09:34 +02:00
|
|
|
headers: { 'User-Agent': 'Joplin Readme Updater' },
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-08-22 12:40:27 +02:00
|
|
|
}, (error: any, response: any, data: any) => {
|
2019-07-18 19:36:29 +02:00
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
} else if (response.statusCode !== 200) {
|
2019-09-19 23:51:18 +02:00
|
|
|
reject(new Error(`Error HTTP ${response.statusCode}`));
|
2019-07-18 19:36:29 +02:00
|
|
|
} else {
|
|
|
|
resolve(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-22 12:40:27 +02:00
|
|
|
function contributorTable(contributors: Contributor[]) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const rows = [];
|
2019-07-18 19:36:29 +02:00
|
|
|
|
2023-08-22 12:40:27 +02:00
|
|
|
let row: string[] = [];
|
2019-07-18 19:36:29 +02:00
|
|
|
rows.push(row);
|
2020-03-14 01:46:14 +02:00
|
|
|
const rowLength = 5;
|
2019-07-18 19:36:29 +02:00
|
|
|
let contributorIndex = 0;
|
|
|
|
while (contributorIndex < contributors.length) {
|
|
|
|
const c = contributors[contributorIndex];
|
|
|
|
contributorIndex++;
|
|
|
|
|
2020-11-09 21:36:49 +02:00
|
|
|
const cell = `<img width="50" src="${c.avatar_url}"/></br>[${c.login}](${c.html_url})`;
|
2019-07-18 19:36:29 +02:00
|
|
|
|
|
|
|
row.push(cell);
|
|
|
|
|
|
|
|
if (row.length >= rowLength) {
|
|
|
|
row = [];
|
|
|
|
rows.push(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (rows[rows.length - 1].length < rowLength) rows[rows.length - 1].push('');
|
|
|
|
|
|
|
|
const header = [];
|
|
|
|
const headerLine = [];
|
|
|
|
for (let i = 0; i < rowLength; i++) {
|
|
|
|
header.push(' ');
|
|
|
|
headerLine.push(':---:');
|
|
|
|
}
|
|
|
|
|
|
|
|
const lines = [];
|
2019-09-19 23:51:18 +02:00
|
|
|
lines.push(`| ${header.join(' | ')} |`);
|
|
|
|
lines.push(`| ${headerLine.join(' | ')} |`);
|
2019-07-18 19:36:29 +02:00
|
|
|
|
|
|
|
for (const row of rows) {
|
2019-09-19 23:51:18 +02:00
|
|
|
lines.push(`| ${row.join(' | ')} |`);
|
2019-07-18 19:36:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return lines.join('\n');
|
|
|
|
}
|
|
|
|
|
2019-09-13 00:16:42 +02:00
|
|
|
async function main() {
|
2023-08-22 12:40:27 +02:00
|
|
|
let contributors: Contributor[] = [];
|
2019-07-18 19:36:29 +02:00
|
|
|
let pageIndex = 0;
|
|
|
|
const doneNames = [];
|
|
|
|
while (true) {
|
|
|
|
const response = await gitHubContributors(pageIndex);
|
|
|
|
pageIndex++;
|
|
|
|
if (!response.length) break;
|
|
|
|
|
|
|
|
// Remove duplicates
|
|
|
|
const temp = [];
|
|
|
|
for (const r of response) {
|
|
|
|
if (doneNames.indexOf(r.login) >= 0) continue;
|
|
|
|
doneNames.push(r.login);
|
|
|
|
temp.push(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
contributors = contributors.concat(temp);
|
|
|
|
}
|
|
|
|
|
2023-08-22 12:40:27 +02:00
|
|
|
contributors = contributors.filter(c => {
|
|
|
|
return !['joplinbot', 'renovate[bot]', 'github-actions[bot]'].includes(c.login);
|
|
|
|
});
|
|
|
|
|
2019-07-18 19:36:29 +02:00
|
|
|
const tableHtml = contributorTable(contributors);
|
|
|
|
|
|
|
|
await insertContentIntoFile(
|
|
|
|
readmePath,
|
|
|
|
'<!-- CONTRIBUTORS-TABLE-AUTO-GENERATED -->\n',
|
|
|
|
'\n<!-- CONTRIBUTORS-TABLE-AUTO-GENERATED -->',
|
2023-08-22 12:58:53 +02:00
|
|
|
tableHtml,
|
2019-07-18 19:36:29 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-22 12:40:27 +02:00
|
|
|
main().catch((error) => {
|
2019-07-18 19:36:29 +02:00
|
|
|
console.error('Fatal error', error);
|
|
|
|
process.exit(1);
|
2019-07-30 09:35:42 +02:00
|
|
|
});
|