@@ -21108,12 +21108,23 @@ var libs = __nccwpck_require__(1109);
2110821108// EXTERNAL MODULE: external "fs"
2110921109var external_fs_ = __nccwpck_require__(5747);
2111021110var external_fs_default = /*#__PURE__*/__nccwpck_require__.n(external_fs_);
21111- ;// CONCATENATED MODULE: external "querystring"
21112- const external_querystring_namespaceObject = require("querystring");;
21113- var external_querystring_default = /*#__PURE__*/__nccwpck_require__.n(external_querystring_namespaceObject);
21111+ ;// CONCATENATED MODULE: ./src/utils/checkForSections.ts
21112+
21113+ const checkForSections = (readmeLines) => {
21114+ let startIdx = readmeLines.findIndex((content) => content.trim() === '<!--START_SECTION:learn-->');
21115+ if (startIdx === -1) {
21116+ core.setFailed(`Couldn't find the <!--START_SECTION:learn--> comment. Exiting!`);
21117+ }
21118+ const endIdx = readmeLines.findIndex((content) => content.trim() === '<!--END_SECTION:learn-->');
21119+ if (endIdx === -1) {
21120+ core.setFailed(`Couldn't find the <!--END_SECTION:learn--> comment. Exiting!`);
21121+ }
21122+ return [startIdx, endIdx];
21123+ };
21124+
2111421125;// CONCATENATED MODULE: external "child_process"
2111521126const external_child_process_namespaceObject = require("child_process");;
21116- ;// CONCATENATED MODULE: ./src/utils.ts
21127+ ;// CONCATENATED MODULE: ./src/utils/commitFile .ts
2111721128var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
2111821129 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2111921130 return new (P || (P = Promise))(function (resolve, reject) {
@@ -21124,18 +21135,6 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
2112421135 });
2112521136};
2112621137
21127- const commitFile = () => __awaiter(void 0, void 0, void 0, function* () {
21128- yield exec('git', [
21129- 'config',
21130- '--global',
21131- 'user.email',
21132- '41898282+github-actions[bot]@users.noreply.github.com'
21133- ]);
21134- yield exec('git', ['config', '--global', 'user.name', 'readme-bot']);
21135- yield exec('git', ['add', 'README.md']);
21136- yield exec('git', ['commit', '-m', 'Updated readme with learn section']);
21137- yield exec('git', ['push']);
21138- });
2113921138const exec = (cmd, args = []) => new Promise((resolve, reject) => {
2114021139 const app = (0,external_child_process_namespaceObject.spawn)(cmd, args, { stdio: 'pipe' });
2114121140 let stdout = '';
@@ -21152,22 +21151,38 @@ const exec = (cmd, args = []) => new Promise((resolve, reject) => {
2115221151 });
2115321152 app.on('error', reject);
2115421153});
21154+ const commitFile = () => __awaiter(void 0, void 0, void 0, function* () {
21155+ yield exec('git', [
21156+ 'config',
21157+ '--global',
21158+ 'user.email',
21159+ '41898282+github-actions[bot]@users.noreply.github.com'
21160+ ]);
21161+ yield exec('git', ['config', '--global', 'user.name', 'readme-bot']);
21162+ yield exec('git', ['add', 'README.md']);
21163+ yield exec('git', ['commit', '-m', 'Updated readme with learn section']);
21164+ yield exec('git', ['push']);
21165+ });
2115521166
21156-
21157- ;// CONCATENATED MODULE: ./src/index.ts
21158- var src_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
21159- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21160- return new (P || (P = Promise))(function (resolve, reject) {
21161- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21162- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21163- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
21164- step((generator = generator.apply(thisArg, _arguments || [])).next());
21167+ ;// CONCATENATED MODULE: ./src/utils/constructCategoriesMap.ts
21168+ const constructCategoriesMap = (schema_unit) => {
21169+ const categories = schema_unit.options
21170+ .map((option) => ({
21171+ color: option.color,
21172+ value: option.value
21173+ }))
21174+ .sort((categoryA, categoryB) => categoryA.value > categoryB.value ? 1 : -1);
21175+ const categories_map = new Map();
21176+ categories.forEach((category) => {
21177+ categories_map.set(category.value, Object.assign({ items: [] }, category));
2116521178 });
21179+ return categories_map;
2116621180};
2116721181
21168-
21169-
21170-
21182+ ;// CONCATENATED MODULE: external "querystring"
21183+ const external_querystring_namespaceObject = require("querystring");;
21184+ var external_querystring_default = /*#__PURE__*/__nccwpck_require__.n(external_querystring_namespaceObject);
21185+ ;// CONCATENATED MODULE: ./src/utils/constructNewContents.ts
2117121186
2117221187const ColorMap = {
2117321188 default: '505558',
@@ -21182,6 +21197,49 @@ const ColorMap = {
2118221197 red: '9f5c58',
2118321198 teal: '467870'
2118421199};
21200+ const constructNewContents = (categories_map, color_schema_unit_key) => {
21201+ const newContents = [];
21202+ for (const [category, category_info] of categories_map) {
21203+ const content = [
21204+ `<h3><img height="20px" src="https://img.shields.io/badge/${category}-${ColorMap[category_info.color]}"/></h3>`
21205+ ];
21206+ category_info.items.forEach((item) => content.push(`<span><img src="https://img.shields.io/badge/-${external_querystring_default().escape(item.title[0][0])}-${item[color_schema_unit_key][0][0]}?style=flat-square&logo=${external_querystring_default().escape(item.title[0][0])}" alt="${item.title[0][0]}"/></span>`));
21207+ newContents.push(...content, '<hr>');
21208+ }
21209+ return newContents;
21210+ };
21211+
21212+ ;// CONCATENATED MODULE: ./src/utils/getSchemaEntries.ts
21213+
21214+ const getSchemaEntries = (schema) => {
21215+ const schema_entries = Object.entries(schema), category_schema_entry = schema_entries.find(([, schema_entry_value]) => schema_entry_value.type === 'multi_select' &&
21216+ schema_entry_value.name === 'Category'), color_schema_entry = schema_entries.find(([, schema_entry_value]) => schema_entry_value.type === 'text' &&
21217+ schema_entry_value.name === 'Color');
21218+ if (!category_schema_entry)
21219+ core.setFailed("Couldn't find Category named multi_select type column in the database");
21220+ if (!color_schema_entry)
21221+ core.setFailed("Couldn't find Color named text type column in the database");
21222+ return [category_schema_entry, color_schema_entry];
21223+ };
21224+
21225+ ;// CONCATENATED MODULE: ./src/index.ts
21226+ var src_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
21227+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21228+ return new (P || (P = Promise))(function (resolve, reject) {
21229+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21230+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21231+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
21232+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21233+ });
21234+ };
21235+
21236+
21237+
21238+
21239+
21240+
21241+
21242+
2118521243function main() {
2118621244 return src_awaiter(this, void 0, void 0, function* () {
2118721245 try {
@@ -21237,57 +21295,27 @@ function main() {
2123721295 const collection = collectionData.recordMap.collection[collection_id]
2123821296 .value;
2123921297 const { schema } = collection;
21240- const schema_entries = Object.entries(schema), category_schema_entry = schema_entries.find(([, schema_entry_value]) => schema_entry_value.type === 'multi_select' &&
21241- schema_entry_value.name === 'Category'), color_schema_entry = schema_entries.find(([, schema_entry_value]) => schema_entry_value.type === 'text' &&
21242- schema_entry_value.name === 'Color');
21243- if (!category_schema_entry)
21244- return core.setFailed("Couldn't find Category named multi_select type column in the database");
21245- if (!category_schema_entry)
21246- return core.setFailed("Couldn't find Color named text type column in the database");
21298+ const [category_schema_entry, color_schema_entry] = getSchemaEntries(schema);
2124721299 const rows = Object.values(recordMap.block)
2124821300 .filter((block) => block.value.id !== databaseId)
21249- .map((block) => block.value);
21301+ .map((block) => block.value)
21302+ .sort((rowA, rowB) => rowA.properties.title[0][0] > rowB.properties.title[0][0] ? 1 : -1);
2125021303 if (rows.length === 0)
2125121304 return core.error('No database rows detected');
2125221305 else {
21253- const categories = category_schema_entry[1].options
21254- .map((option) => ({
21255- color: option.color,
21256- value: option.value
21257- }))
21258- .sort((categoryA, categoryB) => categoryA.value > categoryB.value ? 1 : -1);
21259- const categories_map = new Map();
21260- categories.forEach((category) => {
21261- categories_map.set(category.value, Object.assign({ items: [] }, category));
21262- });
21263- rows
21264- .sort((rowA, rowB) => rowA.properties.title[0][0] > rowB.properties.title[0][0] ? 1 : -1)
21265- .forEach((row) => {
21306+ const categories_map = constructCategoriesMap(category_schema_entry[1]);
21307+ rows.forEach((row) => {
2126621308 const category = row.properties[category_schema_entry[0]][0][0];
2126721309 if (!category)
2126821310 throw new Error('Each row must have a category value');
2126921311 const category_value = categories_map.get(category);
2127021312 category_value.items.push(row.properties);
2127121313 });
21272- const newLines = [];
21273- for (const [category, category_info] of categories_map) {
21274- const content = [
21275- `<h3><img height="20px" src="https://img.shields.io/badge/${category}-${ColorMap[category_info.color]}"/></h3>`
21276- ];
21277- category_info.items.forEach((item) => content.push(`<span><img src="https://img.shields.io/badge/-${external_querystring_default().escape(item.title[0][0])}-${item[color_schema_entry[0]][0][0]}?style=flat-square&logo=${external_querystring_default().escape(item.title[0][0])}" alt="${item.title[0][0]}"/></span>`));
21278- newLines.push(...content, '<hr>');
21279- }
2128021314 const README_PATH = `${process.env.GITHUB_WORKSPACE}/README.md`;
2128121315 core.info(`Reading from ${README_PATH}`);
2128221316 const readmeLines = external_fs_default().readFileSync(README_PATH, 'utf-8').split('\n');
21283- let startIdx = readmeLines.findIndex((content) => content.trim() === '<!--START_SECTION:learn-->');
21284- if (startIdx === -1) {
21285- return core.setFailed(`Couldn't find the <!--START_SECTION:learn--> comment. Exiting!`);
21286- }
21287- const endIdx = readmeLines.findIndex((content) => content.trim() === '<!--END_SECTION:learn-->');
21288- if (endIdx === -1) {
21289- return core.setFailed(`Couldn't find the <!--END_SECTION:learn--> comment. Exiting!`);
21290- }
21317+ const [startIdx, endIdx] = checkForSections(readmeLines);
21318+ const newLines = constructNewContents(categories_map, color_schema_entry[0]);
2129121319 const finalLines = [
2129221320 ...readmeLines.slice(0, startIdx + 1),
2129321321 ...newLines,
0 commit comments