@@ -16775,79 +16775,86 @@ async function main() {
1677516775 .filter((block) => block.value.id !== databaseId)
1677616776 .map((block) => block.value);
1677716777
16778- const categories = category_schema_entry[1].options
16779- .map((option) => ({
16780- color: option.color,
16781- value: option.value
16782- }))
16783- .sort((categoryA, categoryB) =>
16784- categoryA.value > categoryB.value ? 1 : -1
16785- );
16778+ if (rows.length === 0) return core.warn('No database rows detected');
16779+ else {
16780+ const categories = category_schema_entry[1].options
16781+ .map((option) => ({
16782+ color: option.color,
16783+ value: option.value
16784+ }))
16785+ .sort((categoryA, categoryB) =>
16786+ categoryA.value > categoryB.value ? 1 : -1
16787+ );
1678616788
16787- const categories_map = new Map();
16789+ const categories_map = new Map();
1678816790
16789- categories.forEach((category) => {
16790- categories_map.set(category.value, {
16791- items: [],
16792- ...category
16791+ categories.forEach((category) => {
16792+ categories_map.set(category.value, {
16793+ items: [],
16794+ ...category
16795+ });
1679316796 });
16794- });
1679516797
16796- rows.forEach((row) => {
16797- const category = row.properties[category_schema_entry[0]][0][0];
16798- if (!category) throw new Error('Each row must have a category value');
16799- const category_value = categories_map.get(category);
16800- category_value.items.push(row.properties.title[0][0]);
16801- });
16798+ rows.forEach((row) => {
16799+ const category = row.properties[category_schema_entry[0]][0][0];
16800+ if (!category) throw new Error('Each row must have a category value');
16801+ const category_value = categories_map.get(category);
16802+ category_value.items.push(row.properties.title[0][0]);
16803+ });
1680216804
16803- const newLines = [];
16805+ const newLines = [];
1680416806
16805- for (const [category, category_info] of categories_map) {
16806- const content = [
16807- `<img height="20px" src="https://img.shields.io/badge/${category}-${category_info.color}"/>`,
16808- '</br>'
16809- ];
16810- category_info.items.forEach((item) =>
16811- content.push(
16812- `<img src="https://img.shields.io/badge/-${item}-black?style=flat-square&logo=${item}" alt="${item}">`
16813- )
16807+ for (const [category, category_info] of categories_map) {
16808+ const content = [
16809+ `<div><img height="20px" src="https://img.shields.io/badge/${category}-${category_info.color}"/></div>`
16810+ ];
16811+ category_info.items.forEach((item) =>
16812+ content.push(
16813+ `<img src="https://img.shields.io/badge/-${item}-black?style=flat-square&logo=${item}" alt="${item}">`
16814+ )
16815+ );
16816+ newLines.push(...content, '<hr>');
16817+ }
16818+
16819+ const README_PATH = `${process.env.GITHUB_WORKSPACE}/README.md`;
16820+ core.info(`Reading from ${README_PATH}`);
16821+
16822+ const readmeLines = fs.readFileSync(README_PATH, 'utf-8').split('\n');
16823+ let startIdx = readmeLines.findIndex(
16824+ (content) => content.trim() === '<!--START_SECTION:learn-->'
1681416825 );
16815- newLines.push(...content, '</br>');
16816- }
1681716826
16818- const README_PATH = `${process.env.GITHUB_WORKSPACE}/README.md`;
16819- core.info(`Reading from ${README_PATH}`);
16827+ if (startIdx === -1) {
16828+ return core.setFailed(
16829+ `Couldn't find the <!--START_SECTION:learn--> comment. Exiting!`
16830+ );
16831+ }
1682016832
16821- const readmeLines = fs.readFileSync(README_PATH, 'utf-8').split('\n');
16822- let startIdx = readmeLines.findIndex(
16823- (content) => content.trim() === '<!--START_SECTION:notion_learn-->'
16824- );
16833+ if (endIdx === -1) {
16834+ return core.setFailed(
16835+ `Couldn't find the <!--END_SECTION:learn--> comment. Exiting!`
16836+ );
16837+ }
1682516838
16826- if (startIdx === -1) {
16827- return core.setFailed(
16828- `Couldn't find the <!--START_SECTION:notion_learn--> comment. Exiting!`
16839+ const endIdx = readmeLines.findIndex(
16840+ (content) => content.trim() === '<!--END_SECTION:learn-->'
1682916841 );
16830- }
16831-
16832- const endIdx = readmeLines.findIndex(
16833- (content) => content.trim() === '<!--END_SECTION:notion_learn-->'
16834- );
1683516842
16836- const finalLines = [
16837- ...readmeLines.slice(0, startIdx + 1),
16838- ...newLines,
16839- ...readmeLines.slice(endIdx)
16840- ];
16843+ const finalLines = [
16844+ ...readmeLines.slice(0, startIdx + 1),
16845+ ...newLines,
16846+ ...readmeLines.slice(endIdx)
16847+ ];
1684116848
16842- core.info(`Writing to ${README_PATH}`);
16849+ core.info(`Writing to ${README_PATH}`);
1684316850
16844- fs.writeFileSync(README_PATH, finalLines.join('\n'));
16851+ fs.writeFileSync(README_PATH, finalLines.join('\n'));
1684516852
16846- try {
16847- await commitFile();
16848- } catch (err) {
16849- tools.log.debug('Something went wrong' );
16850- return core.setFailed(err.message);
16853+ try {
16854+ await commitFile();
16855+ } catch (err) {
16856+ return core.setFailed(err.message );
16857+ }
1685116858 }
1685216859 } catch (error) {
1685316860 return core.setFailed(error.message);
0 commit comments