@@ -4010,21 +4010,30 @@ module.exports.Format = CliFormat;
40104010
40114011"use strict";
40124012
4013+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4014+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4015+ return new (P || (P = Promise))(function (resolve, reject) {
4016+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
4017+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
4018+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
4019+ step((generator = generator.apply(thisArg, _arguments || [])).next());
4020+ });
4021+ };
40134022Object.defineProperty(exports, "__esModule", { value: true });
40144023exports.commitFile = void 0;
40154024const child_process_1 = __webpack_require__(129);
4016- const commitFile = async () => {
4017- await exec('git', [
4025+ const commitFile = () => __awaiter(void 0, void 0, void 0, function* () {
4026+ yield exec('git', [
40184027 'config',
40194028 '--global',
40204029 'user.email',
40214030 '41898282+github-actions[bot]@users.noreply.github.com'
40224031 ]);
4023- await exec('git', ['config', '--global', 'user.name', 'readme-bot']);
4024- await exec('git', ['add', 'README.md']);
4025- await exec('git', ['commit', '-m', 'Updated readme with learn section']);
4026- await exec('git', ['push']);
4027- };
4032+ yield exec('git', ['config', '--global', 'user.name', 'readme-bot']);
4033+ yield exec('git', ['add', 'README.md']);
4034+ yield exec('git', ['commit', '-m', 'Updated readme with learn section']);
4035+ yield exec('git', ['push']);
4036+ }) ;
40284037exports.commitFile = commitFile;
40294038const exec = (cmd, args = []) => new Promise((resolve, reject) => {
40304039 const app = child_process_1.spawn(cmd, args, { stdio: 'pipe' });
@@ -8980,6 +8989,15 @@ module.exports = isStream;
89808989
89818990"use strict";
89828991
8992+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8993+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8994+ return new (P || (P = Promise))(function (resolve, reject) {
8995+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8996+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8997+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8998+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8999+ });
9000+ };
89839001var __importDefault = (this && this.__importDefault) || function (mod) {
89849002 return (mod && mod.__esModule) ? mod : { "default": mod };
89859003};
@@ -9000,127 +9018,126 @@ const ColorMap = {
90009018 pink: '904d74',
90019019 red: '9f5c58'
90029020};
9003- async function main() {
9004- try {
9005- const databaseId = core_1.default.getInput('database_id');
9006- const NOTION_TOKEN_V2 = core_1.default.getInput('token_v2');
9007- const collectionViewData = await endpoints_1.NotionEndpoints.Queries.syncRecordValues({
9008- requests: [
9009- {
9010- id: databaseId,
9011- table: 'block',
9012- version: -1
9013- }
9014- ]
9015- }, {
9016- token: NOTION_TOKEN_V2,
9017- user_id: ''
9018- });
9019- core_1.default.info('Fetched database');
9020- const collectionView = collectionViewData.recordMap.block[databaseId]
9021- .value;
9022- if (!collectionView) {
9023- return core_1.default.setFailed(`Either your NOTION_TOKEN_V2 has expired or a database with id:${databaseId} doesn't exist`);
9024- }
9025- const collection_id = collectionView.collection_id;
9026- const collectionData = await endpoints_1.NotionEndpoints.Queries.syncRecordValues({
9027- requests: [
9028- {
9029- id: collection_id,
9030- table: 'collection',
9031- version: -1
9032- }
9033- ]
9034- }, {
9035- token: NOTION_TOKEN_V2,
9036- user_id: ''
9037- });
9038- core_1.default.info('Fetched collection');
9039- const { recordMap } = await endpoints_1.NotionEndpoints.Queries.queryCollection({
9040- collectionId: collection_id,
9041- collectionViewId: '',
9042- query: {},
9043- loader: {
9044- type: 'table',
9045- loadContentCover: false,
9046- limit: 10000,
9047- userTimeZone: ''
9021+ function main() {
9022+ return __awaiter(this, void 0, void 0, function* () {
9023+ try {
9024+ const databaseId = core_1.default.getInput('database_id');
9025+ const NOTION_TOKEN_V2 = core_1.default.getInput('token_v2');
9026+ const collectionViewData = yield endpoints_1.NotionEndpoints.Queries.syncRecordValues({
9027+ requests: [
9028+ {
9029+ id: databaseId,
9030+ table: 'block',
9031+ version: -1
9032+ }
9033+ ]
9034+ }, {
9035+ token: NOTION_TOKEN_V2,
9036+ user_id: ''
9037+ });
9038+ core_1.default.info('Fetched database');
9039+ const collectionView = collectionViewData.recordMap.block[databaseId]
9040+ .value;
9041+ if (!collectionView) {
9042+ return core_1.default.setFailed(`Either your NOTION_TOKEN_V2 has expired or a database with id:${databaseId} doesn't exist`);
90489043 }
9049- }, {
9050- token: NOTION_TOKEN_V2,
9051- user_id: ''
9052- });
9053- core_1.default.info('Fetched rows');
9054- const collection = collectionData.recordMap.collection[collection_id]
9055- .value;
9056- const { schema } = collection;
9057- const schema_entries = Object.entries(schema), category_schema_entry = schema_entries.find(([, schema_entry_value]) => schema_entry_value.type === 'multi_select' &&
9058- schema_entry_value.name === 'Category');
9059- if (!category_schema_entry)
9060- return core_1.default.setFailed("Couldn't find Category named multi_select type column in the database");
9061- const rows = Object.values(recordMap.block)
9062- .filter((block) => block.value.id !== databaseId)
9063- .map((block) => block.value);
9064- if (rows.length === 0)
9065- return core_1.default.error('No database rows detected');
9066- else {
9067- const categories = category_schema_entry[1].options
9068- .map((option) => ({
9069- color: option.color,
9070- value: option.value
9071- }))
9072- .sort((categoryA, categoryB) => categoryA.value > categoryB.value ? 1 : -1);
9073- const categories_map = new Map();
9074- categories.forEach((category) => {
9075- categories_map.set(category.value, {
9076- items: [],
9077- ...category
9078- });
9044+ const collection_id = collectionView.collection_id;
9045+ const collectionData = yield endpoints_1.NotionEndpoints.Queries.syncRecordValues({
9046+ requests: [
9047+ {
9048+ id: collection_id,
9049+ table: 'collection',
9050+ version: -1
9051+ }
9052+ ]
9053+ }, {
9054+ token: NOTION_TOKEN_V2,
9055+ user_id: ''
90799056 });
9080- rows.forEach((row) => {
9081- const category = row.properties[category_schema_entry[0]][0][0];
9082- if (!category)
9083- throw new Error('Each row must have a category value');
9084- const category_value = categories_map.get(category);
9085- category_value.items.push(row.properties.title[0][0]);
9057+ core_1.default.info('Fetched collection');
9058+ const { recordMap } = yield endpoints_1.NotionEndpoints.Queries.queryCollection({
9059+ collectionId: collection_id,
9060+ collectionViewId: '',
9061+ query: {},
9062+ loader: {
9063+ type: 'table',
9064+ loadContentCover: false,
9065+ limit: 10000,
9066+ userTimeZone: ''
9067+ }
9068+ }, {
9069+ token: NOTION_TOKEN_V2,
9070+ user_id: ''
90869071 });
9087- const newLines = [];
9088- for (const [category, category_info] of categories_map) {
9089- const content = [
9090- `<div><img height="20px" src="https://img.shields.io/badge/${category}-${ColorMap[category_info.color]}"/></div>`
9072+ core_1.default.info('Fetched rows');
9073+ const collection = collectionData.recordMap.collection[collection_id]
9074+ .value;
9075+ const { schema } = collection;
9076+ const schema_entries = Object.entries(schema), category_schema_entry = schema_entries.find(([, schema_entry_value]) => schema_entry_value.type === 'multi_select' &&
9077+ schema_entry_value.name === 'Category');
9078+ if (!category_schema_entry)
9079+ return core_1.default.setFailed("Couldn't find Category named multi_select type column in the database");
9080+ const rows = Object.values(recordMap.block)
9081+ .filter((block) => block.value.id !== databaseId)
9082+ .map((block) => block.value);
9083+ if (rows.length === 0)
9084+ return core_1.default.error('No database rows detected');
9085+ else {
9086+ const categories = category_schema_entry[1].options
9087+ .map((option) => ({
9088+ color: option.color,
9089+ value: option.value
9090+ }))
9091+ .sort((categoryA, categoryB) => categoryA.value > categoryB.value ? 1 : -1);
9092+ const categories_map = new Map();
9093+ categories.forEach((category) => {
9094+ categories_map.set(category.value, Object.assign({ items: [] }, category));
9095+ });
9096+ rows.forEach((row) => {
9097+ const category = row.properties[category_schema_entry[0]][0][0];
9098+ if (!category)
9099+ throw new Error('Each row must have a category value');
9100+ const category_value = categories_map.get(category);
9101+ category_value.items.push(row.properties.title[0][0]);
9102+ });
9103+ const newLines = [];
9104+ for (const [category, category_info] of categories_map) {
9105+ const content = [
9106+ `<div><img height="20px" src="https://img.shields.io/badge/${category}-${ColorMap[category_info.color]}"/></div>`
9107+ ];
9108+ category_info.items.forEach((item) => content.push(`<img src="https://img.shields.io/badge/-${item}-black?style=flat-square&logo=${item}" alt="${item}">`));
9109+ newLines.push(...content, '<hr>');
9110+ }
9111+ const README_PATH = `${process.env.GITHUB_WORKSPACE}/README.md`;
9112+ core_1.default.info(`Reading from ${README_PATH}`);
9113+ const readmeLines = fs_1.default.readFileSync(README_PATH, 'utf-8').split('\n');
9114+ let startIdx = readmeLines.findIndex((content) => content.trim() === '<!--START_SECTION:learn-->');
9115+ if (startIdx === -1) {
9116+ return core_1.default.setFailed(`Couldn't find the <!--START_SECTION:learn--> comment. Exiting!`);
9117+ }
9118+ const endIdx = readmeLines.findIndex((content) => content.trim() === '<!--END_SECTION:learn-->');
9119+ if (endIdx === -1) {
9120+ return core_1.default.setFailed(`Couldn't find the <!--END_SECTION:learn--> comment. Exiting!`);
9121+ }
9122+ const finalLines = [
9123+ ...readmeLines.slice(0, startIdx + 1),
9124+ ...newLines,
9125+ ...readmeLines.slice(endIdx)
90919126 ];
9092- category_info.items.forEach((item) => content.push(`<img src="https://img.shields.io/badge/-${item}-black?style=flat-square&logo=${item}" alt="${item}">`));
9093- newLines.push(...content, '<hr>');
9094- }
9095- const README_PATH = `${process.env.GITHUB_WORKSPACE}/README.md`;
9096- core_1.default.info(`Reading from ${README_PATH}`);
9097- const readmeLines = fs_1.default.readFileSync(README_PATH, 'utf-8').split('\n');
9098- let startIdx = readmeLines.findIndex((content) => content.trim() === '<!--START_SECTION:learn-->');
9099- if (startIdx === -1) {
9100- return core_1.default.setFailed(`Couldn't find the <!--START_SECTION:learn--> comment. Exiting!`);
9101- }
9102- const endIdx = readmeLines.findIndex((content) => content.trim() === '<!--END_SECTION:learn-->');
9103- if (endIdx === -1) {
9104- return core_1.default.setFailed(`Couldn't find the <!--END_SECTION:learn--> comment. Exiting!`);
9105- }
9106- const finalLines = [
9107- ...readmeLines.slice(0, startIdx + 1),
9108- ...newLines,
9109- ...readmeLines.slice(endIdx)
9110- ];
9111- core_1.default.info(`Writing to ${README_PATH}`);
9112- fs_1.default.writeFileSync(README_PATH, finalLines.join('\n'));
9113- try {
9114- await utils_1.commitFile();
9115- }
9116- catch (err) {
9117- return core_1.default.setFailed(err.message);
9127+ core_1.default.info(`Writing to ${README_PATH}`);
9128+ fs_1.default.writeFileSync(README_PATH, finalLines.join('\n'));
9129+ try {
9130+ yield utils_1.commitFile();
9131+ }
9132+ catch (err) {
9133+ return core_1.default.setFailed(err.message);
9134+ }
91189135 }
91199136 }
9120- }
9121- catch (error) {
9122- return core_1.default.setFailed(error.message);
9123- }
9137+ catch (error) {
9138+ return core_1.default.setFailed (error.message);
9139+ }
9140+ });
91249141}
91259142main();
91269143
0 commit comments