Skip to content

Commit

Permalink
1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sarisia committed Mar 20, 2021
1 parent e2b1720 commit 5ee3432
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
6 changes: 1 addition & 5 deletions lib/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ const parser = new rss_parser_1.default({
});
function getFeedItems(url) {
return __awaiter(this, void 0, void 0, function* () {
const feed = yield parser.parseURL(url);
if (!feed.items) {
throw new Error('item not found in feed.');
}
return feed.items;
return (yield parser.parseURL(url)).items || [];
});
}
exports.getFeedItems = getFeedItems;
Expand Down
44 changes: 37 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,28 @@ const format_1 = require("./format");
function run() {
return __awaiter(this, void 0, void 0, function* () {
const sort = core.getInput('sort').toLowerCase() === 'true';
const maxEntry = parseInt(core.getInput('max_entry')) || 5;
const maxEntry = parseInt(core.getInput('max_entry'), 10) || 5;
if (maxEntry < 0) {
core.setFailed("cannot set `maxEntry` to lower than 0");
return;
}
const format = process.env['INPUT_FORMAT'] || '- ${monthshort} ${02day} - [${title}](${url})';
const startFlag = core.getInput('start_flag') || '<!-- feed start -->';
const endFlag = core.getInput('end_flag') || '<!-- feed end -->';
const locale = core.getInput('locale') || 'en-US';
const timezone = core.getInput('timezone') || 'UTC';
const nowrite = core.getInput('nowrite').toLowerCase() === 'true';
const retry = parseInt(core.getInput('retry'), 10) || 3;
if (retry < 0) {
core.setFailed("cannot set `retry` to lower than 0");
return;
}
const retryBackoff = parseInt(core.getInput('retry_backoff'), 10) || 5;
if (retryBackoff < 0) {
core.setFailed("cannot set `retryBackoff` to lower than 0");
return;
}
const ensureAll = core.getInput('ensure_all').toLowerCase() === 'true';
const url = core.getInput('url') || '';
const urls = url.split('\n').filter(x => x || false);
urls.forEach((u) => {
Expand Down Expand Up @@ -74,19 +89,34 @@ function run() {
const fetchers = urls.map((u, i) => {
return function () {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield feed_1.getFeedItems(u);
for (let trycount = 0; trycount < retry; ++trycount) {
if (trycount) {
yield new Promise(resolve => setTimeout(resolve, retryBackoff * 1000));
}
try {
return yield feed_1.getFeedItems(u);
}
catch (e) {
core.error(`[feed ${i + 1}/${urls.length}][try ${trycount + 1}/${retry}] failed to get feed: ${e}`);
}
}
catch (e) {
core.error(`failed to get feed ${i + 1}/${urls.length}: ${e}`);
core.error(`[feed ${i + 1}/${urls.length}] max retry count exceeded. Abort.`);
if (ensureAll) {
throw new Error("failed to fetch some feeds.");
}
return [];
});
};
});
const results = yield Promise.all(fetchers.map(f => f()));
let allItems = [];
allItems = allItems.concat(...results);
try {
const results = yield Promise.all(fetchers.map(f => f()));
allItems = allItems.concat(...results);
}
catch (e) {
core.setFailed("Aborted by ensure_all");
return;
}
if (!allItems.length) {
core.setFailed('Nothing was fetched');
return;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "actions-readme-feed",
"version": "1.5.0",
"version": "1.6.0",
"description": "",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 5ee3432

Please sign in to comment.