From b04694a1c026a74d45cfca1abd3ce4959ba229bb Mon Sep 17 00:00:00 2001 From: gkr-bot Date: Sun, 1 Nov 2020 07:40:32 +0000 Subject: [PATCH] [skip-ci] Published 1.3.9 --- dist/blog-post-workflow.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/blog-post-workflow.js b/dist/blog-post-workflow.js index a1668da..f0c2910 100644 --- a/dist/blog-post-workflow.js +++ b/dist/blog-post-workflow.js @@ -119,5 +119,5 @@ function i(i,n,r,t){return JSON.stringify(i,e(n,t),r)}function e(i,e){var n=[],r },{}],"KFkI":[function(require,module,exports) { "use strict";var n=require("json-stringify-safe"),r=function(){var n=4022871197;return function(r){if(r){r=r.toString();for(var t=0;t>>0,n=(e*=n)>>>0,n+=4294967296*(e-=n)}return 2.3283064365386963e-10*(n>>>0)}n=4022871197}},t=function(t){return function(){var e,o,i=48,u=1,a=i,f=new Array(i),c=0,l=new r;for(e=0;e=i&&(a=0);var n=1768863*f[a]+2.3283064365386963e-10*u;return f[a]=n-(u=0|n)},h=function(n){return Math.floor(n*(g()+1.1102230246251565e-16*(2097152*g()|0)))};h.string=function(n){var r,t="";for(r=0;r{const r=core.getInput("comment_tag_name"),o=r?`\x3c!-- ${r}:`:"\x3c!-- BLOG-POST-LIST:",s=core.getInput("tag_post_pre_newline"),a=e.indexOf(`${o}START`),n=e.indexOf("--\x3e",a),i=e.indexOf(`${o}END`,n);return-1!==a&&-1!==n&&-1!==i||(core.error(`Cannot find the comment tag on the readme:\n\x3c!-- ${o}:START --\x3e\n\x3c!-- ${o}:END --\x3e`),process.exit(1)),[e.slice(0,n+"--\x3e".length),s?"\n":"",t,s?"\n":"",e.slice(i)].join("")},commitReadme=async()=>{const e=core.getInput("committer_username"),t=core.getInput("committer_email"),r=core.getInput("commit_message");await exec("git",["config","--global","user.email",t]),GITHUB_TOKEN&&await exec("git",["remote","set-url","origin",`https://${GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`]),await exec("git",["config","--global","user.name",e]),await exec("git",["add",README_FILE_PATH]),await exec("git",["commit","-m",r]),await exec("git",["push"]),core.info("Readme updated successfully in the upstream repository"),process.exit(jobFailFlag?1:0)},userAgent=core.getInput("user_agent"),acceptHeader=core.getInput("accept_header"),TOTAL_POST_COUNT=Number.parseInt(core.getInput("max_post_count")),TITLE_MAX_LENGTH=core.getInput("title_max_length")?Number.parseInt(core.getInput("title_max_length")):null,ITEM_EXEC=core.getInput("item_exec"),README_FILE_PATH=core.getInput("readme_path"),GITHUB_TOKEN=core.getInput("gh_token"),FILTER_PARAMS={stackoverflow:"Comment by $author",stackexchange:"Comment by $author"},CUSTOM_TAGS={},updateAndParseCompoundParams=(e,t)=>{const r=e.split("/");return 3===r.length?(Object.assign(t,{[r[0]]:r[1]}),r[0]):e},getParameterisedTemplate=(e,t)=>e.indexOf("$"+t)>-1&&e.match(new RegExp("\\$"+t+"\\((.)*\\)","g"))?e.match(new RegExp("\\$"+t+"\\((.)*\\)","g"))[0].replace("$"+t+"(","").replace(")","").split(",").map(e=>e.trim()):null;core.setSecret(GITHUB_TOKEN);const COMMENT_FILTERS=core.getInput("filter_comments").trim().split(",").map(e=>(e=e.trim()).startsWith("stackoverflow")||e.startsWith("stackexchange")?updateAndParseCompoundParams(e,FILTER_PARAMS):e);core.getInput("custom_tags").trim().split(",").forEach(e=>{e=e.trim(),updateAndParseCompoundParams(e,CUSTOM_TAGS)});const promiseArray=[],runnerNameArray=[];let postsArray=[],jobFailFlag=!1;const feedObjString=core.getInput("feed_list").trim();let feedList=feedObjString.split(",").map(e=>e.trim());0===feedList.length&&(core.error("Please double check the value of feed_list"),process.exit(1));const ignoreMediumComments=e=>!(-1!==COMMENT_FILTERS.indexOf("medium")&&e.link&&e.link.includes("medium.com")&&void 0===e.categories),ignoreStackOverflowComments=e=>!(-1!==COMMENT_FILTERS.indexOf("stackoverflow")&&e.link&&e.link.includes("stackoverflow.com")&&e.title.startsWith(FILTER_PARAMS.stackoverflow.replace(/\$author/g,e.author))),ignoreStackExchangeComments=e=>!(-1!==COMMENT_FILTERS.indexOf("stackexchange")&&e.link&&e.link.includes("stackexchange.com")&&e.title.startsWith(FILTER_PARAMS.stackexchange.replace(/\$author/g,e.author))),customTagArgs=Object.keys(CUSTOM_TAGS).map(e=>[CUSTOM_TAGS[e],e]);let parser=new Parser({headers:{"User-Agent":userAgent,Accept:acceptHeader},customFields:{item:[...customTagArgs]}});feedList.forEach(siteUrl=>{runnerNameArray.push(siteUrl),promiseArray.push(new Promise((resolve,reject)=>{parser.parseURL(siteUrl).then(data=>{if(data.items){const responsePosts=data.items,posts=responsePosts.filter(ignoreMediumComments).filter(ignoreStackOverflowComments).filter(ignoreStackExchangeComments).map(item=>{item.pubDate||reject("Cannot read response->item->pubDate"),item.title||reject("Cannot read response->item->title"),item.link||reject("Cannot read response->item->link");let customTags={};Object.keys(CUSTOM_TAGS).forEach(e=>{item[e]&&Object.assign(customTags,{[e]:item[e]})});let post=_objectSpread({title:item.title.trim(),url:item.link.trim(),date:new Date(item.pubDate.trim())},customTags);if(ITEM_EXEC)try{eval(ITEM_EXEC)}catch(e){core.error("Failure in executing `item_exec` parameter"),core.error(e),process.exit(1)}return TITLE_MAX_LENGTH&&post&&post.title&&(post.title=post.title.trim().slice(0,TITLE_MAX_LENGTH)===post.title.trim()?post.title.trim():post.title.trim().slice(0,TITLE_MAX_LENGTH)+"..."),post});resolve(posts)}else reject("Cannot read response->item")}).catch(reject)}))}),Promise.allSettled(promiseArray).then(e=>{e.forEach((e,t)=>{"fulfilled"===e.status?(core.info(runnerNameArray[t]+" runner succeeded. Post count: "+e.value.length),postsArray.push(...e.value)):(jobFailFlag=!0,core.error(runnerNameArray[t]+" runner failed, please verify the configuration. Error:"),core.error(e.reason))})}).finally(()=>{if(postsArray=postsArray.filter(e=>null!==e),"false"===core.getInput("disable_sort")&&postsArray.sort(function(e,t){return t.date-e.date}),(postsArray=postsArray.slice(0,TOTAL_POST_COUNT)).length>0)try{process.env.TEST_MODE||(exec("git",["config","pull.rebase","true"]),exec("git",["pull"]));const t=fs.readFileSync(README_FILE_PATH,"utf8"),r=core.getInput("template"),o=getParameterisedTemplate(r,"randomEmoji"),s=getParameterisedTemplate(r,"emojiKey"),a=postsArray.reduce((e,t,a)=>{if("default"===r)return e+`\n- [${t.title}](${t.url})`+(a+1===postsArray.length?"\n":"");{const n=dateFormat(t.date,core.getInput("date_format"));let i=r.replace(/\$title\b/g,t.title).replace(/\$url\b/g,t.url).replace(/\$date\b/g,n).replace(/\$newline/g,"\n");if(Object.keys(CUSTOM_TAGS).forEach(e=>{const r=t[e]?t[e]:"";i=i.replace(new RegExp("\\$"+e+"\\b","g"),r)}),o){const e=(process.env.GITHUB_REPOSITORY&&!process.env.TEST_MODE?process.env.GITHUB_REPOSITORY:"example")+a,t=o[rand.create(e).range(o.length)];i=i.replace(/\$randomEmoji\((\S)*\)/g,t)}return s&&(i=i.replace(/\$emojiKey\((\S)*\)/g,s[a%s.length])),e+i}},""),n=buildReadme(t,a);n!==t?(core.info("Writing to "+README_FILE_PATH),fs.writeFileSync(README_FILE_PATH,n),process.env.TEST_MODE||commitReadme()):(core.info("No change detected, skipping"),process.exit(0))}catch(e){core.error(e),process.exit(1)}else core.info("0 blog posts fetched"),process.exit(jobFailFlag?1:0)}); +function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,o)}return r}function _objectSpread(e){for(var t=1;t{const r=core.getInput("comment_tag_name"),o=r?`\x3c!-- ${r}:`:"\x3c!-- BLOG-POST-LIST:",s=core.getInput("tag_post_pre_newline"),a=e.indexOf(`${o}START`),n=e.indexOf("--\x3e",a),i=e.indexOf(`${o}END`,n);return-1!==a&&-1!==n&&-1!==i||(core.error(`Cannot find the comment tag on the readme:\n${o}:START --\x3e\n${o}:END --\x3e`),process.exit(1)),[e.slice(0,n+"--\x3e".length),s?"\n":"",t,s?"\n":"",e.slice(i)].join("")},commitReadme=async()=>{const e=core.getInput("committer_username"),t=core.getInput("committer_email"),r=core.getInput("commit_message");await exec("git",["config","--global","user.email",t]),GITHUB_TOKEN&&await exec("git",["remote","set-url","origin",`https://${GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`]),await exec("git",["config","--global","user.name",e]),await exec("git",["add",README_FILE_PATH]),await exec("git",["commit","-m",r]),await exec("git",["push"]),core.info("Readme updated successfully in the upstream repository"),process.exit(jobFailFlag?1:0)},userAgent=core.getInput("user_agent"),acceptHeader=core.getInput("accept_header"),TOTAL_POST_COUNT=Number.parseInt(core.getInput("max_post_count")),TITLE_MAX_LENGTH=core.getInput("title_max_length")?Number.parseInt(core.getInput("title_max_length")):null,ITEM_EXEC=core.getInput("item_exec"),README_FILE_PATH=core.getInput("readme_path"),GITHUB_TOKEN=core.getInput("gh_token"),FILTER_PARAMS={stackoverflow:"Comment by $author",stackexchange:"Comment by $author"},CUSTOM_TAGS={},updateAndParseCompoundParams=(e,t)=>{const r=e.split("/");return 3===r.length?(Object.assign(t,{[r[0]]:r[1]}),r[0]):e},getParameterisedTemplate=(e,t)=>e.indexOf("$"+t)>-1&&e.match(new RegExp("\\$"+t+"\\((.)*\\)","g"))?e.match(new RegExp("\\$"+t+"\\((.)*\\)","g"))[0].replace("$"+t+"(","").replace(")","").split(",").map(e=>e.trim()):null;core.setSecret(GITHUB_TOKEN);const COMMENT_FILTERS=core.getInput("filter_comments").trim().split(",").map(e=>(e=e.trim()).startsWith("stackoverflow")||e.startsWith("stackexchange")?updateAndParseCompoundParams(e,FILTER_PARAMS):e);core.getInput("custom_tags").trim().split(",").forEach(e=>{e=e.trim(),updateAndParseCompoundParams(e,CUSTOM_TAGS)});const promiseArray=[],runnerNameArray=[];let postsArray=[],jobFailFlag=!1;const feedObjString=core.getInput("feed_list").trim();let feedList=feedObjString.split(",").map(e=>e.trim());0===feedList.length&&(core.error("Please double check the value of feed_list"),process.exit(1));const ignoreMediumComments=e=>!(-1!==COMMENT_FILTERS.indexOf("medium")&&e.link&&e.link.includes("medium.com")&&void 0===e.categories),ignoreStackOverflowComments=e=>!(-1!==COMMENT_FILTERS.indexOf("stackoverflow")&&e.link&&e.link.includes("stackoverflow.com")&&e.title.startsWith(FILTER_PARAMS.stackoverflow.replace(/\$author/g,e.author))),ignoreStackExchangeComments=e=>!(-1!==COMMENT_FILTERS.indexOf("stackexchange")&&e.link&&e.link.includes("stackexchange.com")&&e.title.startsWith(FILTER_PARAMS.stackexchange.replace(/\$author/g,e.author))),customTagArgs=Object.keys(CUSTOM_TAGS).map(e=>[CUSTOM_TAGS[e],e]);let parser=new Parser({headers:{"User-Agent":userAgent,Accept:acceptHeader},customFields:{item:[...customTagArgs]}});feedList.forEach(siteUrl=>{runnerNameArray.push(siteUrl),promiseArray.push(new Promise((resolve,reject)=>{parser.parseURL(siteUrl).then(data=>{if(data.items){const responsePosts=data.items,posts=responsePosts.filter(ignoreMediumComments).filter(ignoreStackOverflowComments).filter(ignoreStackExchangeComments).map(item=>{item.pubDate||reject("Cannot read response->item->pubDate"),item.title||reject("Cannot read response->item->title"),item.link||reject("Cannot read response->item->link");let customTags={};Object.keys(CUSTOM_TAGS).forEach(e=>{item[e]&&Object.assign(customTags,{[e]:item[e]})});let post=_objectSpread({title:item.title.trim(),url:item.link.trim(),date:new Date(item.pubDate.trim())},customTags);if(ITEM_EXEC)try{eval(ITEM_EXEC)}catch(e){core.error("Failure in executing `item_exec` parameter"),core.error(e),process.exit(1)}return TITLE_MAX_LENGTH&&post&&post.title&&(post.title=post.title.trim().slice(0,TITLE_MAX_LENGTH)===post.title.trim()?post.title.trim():post.title.trim().slice(0,TITLE_MAX_LENGTH)+"..."),post});resolve(posts)}else reject("Cannot read response->item")}).catch(reject)}))}),Promise.allSettled(promiseArray).then(e=>{e.forEach((e,t)=>{"fulfilled"===e.status?(core.info(runnerNameArray[t]+" runner succeeded. Post count: "+e.value.length),postsArray.push(...e.value)):(jobFailFlag=!0,core.error(runnerNameArray[t]+" runner failed, please verify the configuration. Error:"),core.error(e.reason))})}).finally(()=>{if(postsArray=postsArray.filter(e=>null!==e),"false"===core.getInput("disable_sort")&&postsArray.sort(function(e,t){return t.date-e.date}),(postsArray=postsArray.slice(0,TOTAL_POST_COUNT)).length>0)try{process.env.TEST_MODE||(exec("git",["config","pull.rebase","true"]),exec("git",["pull"]));const t=fs.readFileSync(README_FILE_PATH,"utf8"),r=core.getInput("template"),o=getParameterisedTemplate(r,"randomEmoji"),s=getParameterisedTemplate(r,"emojiKey"),a=postsArray.reduce((e,t,a)=>{if("default"===r)return e+`\n- [${t.title}](${t.url})`+(a+1===postsArray.length?"\n":"");{const n=dateFormat(t.date,core.getInput("date_format"));let i=r.replace(/\$title\b/g,t.title).replace(/\$url\b/g,t.url).replace(/\$date\b/g,n).replace(/\$newline/g,"\n");if(Object.keys(CUSTOM_TAGS).forEach(e=>{const r=t[e]?t[e]:"";i=i.replace(new RegExp("\\$"+e+"\\b","g"),r)}),o){const e=(process.env.GITHUB_REPOSITORY&&!process.env.TEST_MODE?process.env.GITHUB_REPOSITORY:"example")+a,t=o[rand.create(e).range(o.length)];i=i.replace(/\$randomEmoji\((\S)*\)/g,t)}return s&&(i=i.replace(/\$emojiKey\((\S)*\)/g,s[a%s.length])),e+i}},""),n=buildReadme(t,a);n!==t?(core.info("Writing to "+README_FILE_PATH),fs.writeFileSync(README_FILE_PATH,n),process.env.TEST_MODE||commitReadme()):(core.info("No change detected, skipping"),process.exit(0))}catch(e){core.error(e),process.exit(1)}else core.info("0 blog posts fetched"),process.exit(jobFailFlag?1:0)}); },{"rss-parser":"BF6Y","@actions/core":"FTVr","dateformat":"FWyg","./exec":"z3en","random-seed":"KFkI"}]},{},["MHPq"], null) \ No newline at end of file diff --git a/package.json b/package.json index a52ac42..7c0588f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blog-post-workflow", - "version": "1.3.8", + "version": "1.3.9", "description": "Allows you to show your latest blog posts on your github profile or project readme", "main": "blog-post-workflow.js", "scripts": {