2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

chore(ci): improved contributors & PRs sections generator; (#5453)

This commit is contained in:
Dmitriy Mozgovoy
2023-01-09 15:24:02 +02:00
committed by GitHub
parent 18772ed8fd
commit e2a1e280f6
7 changed files with 279 additions and 139 deletions
+31 -16
View File
@@ -1,27 +1,31 @@
import fs from 'fs/promises';
import path from 'path';
import {renderContributorsList} from './contributors.js';
import {renderContributorsList, getTagRef, renderPRsList} from './contributors.js';
import asyncReplace from 'string-replace-async';
import {fileURLToPath} from "url";
import {colorize} from "./helpers/colorize.js";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const injectContributors = async (infile, injector) => {
console.log(`Checking contributors sections in ${infile}`);
const CONTRIBUTORS_TEMPLATE = path.resolve(__dirname, '../templates/contributors.hbs');
const PRS_TEMPLATE = path.resolve(__dirname, '../templates/prs.hbs');
const injectSection = async (name, contributorsRE, injector, infile = '../CHANGELOG.md') => {
console.log(colorize()`Checking ${name} sections in ${infile}`);
infile = path.resolve(__dirname, infile);
const content = String(await fs.readFile(infile));
const headerRE = /^#+\s+\[([-_\d.\w]+)].+?$/mig;
const contributorsRE = /^\s*### Contributors/mi;
let tag;
let index = 0;
let isFirstTag = true;
const newContent = await asyncReplace(content, headerRE, async (match, nextTag, offset) => {
const releaseContent = content.slice(index, offset);
const hasContributorsSection = contributorsRE.test(releaseContent);
const hasSection = contributorsRE.test(releaseContent);
const currentTag = tag;
@@ -29,20 +33,25 @@ const injectContributors = async (infile, injector) => {
index = offset + match.length;
if(currentTag) {
if (hasContributorsSection) {
console.log(`[${currentTag}]: ✓ OK`);
if (hasSection) {
console.log(colorize()`[${currentTag}]: ✓ OK`);
} else {
console.log(`[${currentTag}]: ❌ MISSED`);
console.log(`Generating contributors list...`);
const target = isFirstTag && (!await getTagRef(currentTag)) ? '' : currentTag;
const section = await injector(currentTag);
console.log(colorize()`[${currentTag}]: ❌ MISSED` + (!target ? ' (UNRELEASED)' : ''));
console.log(`\nRENDERED CONTRIBUTORS LIST [${currentTag}]:`);
isFirstTag = false;
console.log(`Generating section...`);
const section = await injector(target);
console.log(colorize()`\nRENDERED SECTION [${name}] for [${currentTag}]:`);
console.log('-------------BEGIN--------------\n');
console.log(section);
console.log('--------------END---------------\n');
return section + match;
return section + '\n' + match;
}
}
@@ -52,8 +61,14 @@ const injectContributors = async (infile, injector) => {
await fs.writeFile(infile, newContent);
}
await injectSection(
'PRs',
/^\s*### PRs/mi,
(tag) => !tag && renderPRsList(tag, PRS_TEMPLATE, {awesome_threshold: 5, comments_threshold: 7}),
);
await injectContributors(
'../CHANGELOG.md',
(tag) => renderContributorsList(tag, true, path.resolve(__dirname, '../templates/contributors.hbs')
));
await injectSection(
'contributors',
/^\s*### Contributors/mi,
(tag) => renderContributorsList(tag, CONTRIBUTORS_TEMPLATE)
);