From 6a6000d2e20571acb9211e656a547c014d97d944 Mon Sep 17 00:00:00 2001 From: gkr-bot Date: Mon, 11 Jan 2021 09:15:08 +0000 Subject: [PATCH] [skip-ci] Published 1.4.4 --- 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 a18babb..a126a44 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"),i=e.indexOf(`${o}START`),n=e.indexOf("--\x3e",i),a=e.indexOf(`${o}END`,n);return-1!==i&&-1!==n&&-1!==a||(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(a)].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,DESCRIPTION_MAX_LENGTH=core.getInput("description_max_length")?Number.parseInt(core.getInput("description_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(),description:item.content?item.content:"",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).trim()+"..."),DESCRIPTION_MAX_LENGTH&&post&&post.description&&(post.description=post.description.trim().slice(0,DESCRIPTION_MAX_LENGTH)===post.description.trim()?post.description.trim():post.description.trim().slice(0,DESCRIPTION_MAX_LENGTH).trim()+"..."),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(async()=>{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||(await exec("git",["config","pull.rebase","true"]),await exec("git",["pull"]));const t=fs.readFileSync(README_FILE_PATH,"utf8"),r=core.getInput("template"),o=getParameterisedTemplate(r,"randomEmoji"),s=getParameterisedTemplate(r,"emojiKey"),i=postsArray.reduce((e,t,i)=>{if("default"===r)return e+`\n- [${t.title}](${t.url})`+(i+1===postsArray.length?"\n":"");{const n=dateFormat(t.date,core.getInput("date_format"));let a=r.replace(/\$title\b/g,t.title).replace(/\$url\b/g,t.url).replace(/\$description\b/g,t.description).replace(/\$date\b/g,n).replace(/\$newline/g,"\n");if(Object.keys(CUSTOM_TAGS).forEach(e=>{const r=t[e]?t[e]:"";a=a.replace(new RegExp("\\$"+e+"\\b","g"),r)}),o){const e=(process.env.GITHUB_REPOSITORY&&!process.env.TEST_MODE?process.env.GITHUB_REPOSITORY:"example")+i,t=o[rand.create(e).range(o.length)];a=a.replace(/\$randomEmoji\((\S)*\)/g,t)}return s&&(a=a.replace(/\$emojiKey\((\S)*\)/g,s[i%s.length])),e+a}},""),n=buildReadme(t,i);n!==t?(core.info("Writing to "+README_FILE_PATH),fs.writeFileSync(README_FILE_PATH,n),process.env.TEST_MODE||await 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"),n=e.indexOf(`${o}START`),i=e.indexOf("--\x3e",n),a=e.indexOf(`${o}END`,i);return-1!==n&&-1!==i&&-1!==a||(core.error(`Cannot find the comment tag on the readme:\n${o}:START --\x3e\n${o}:END --\x3e`),process.exit(1)),[e.slice(0,i+"--\x3e".length),s?"\n":"",t,s?"\n":"",e.slice(a)].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,DESCRIPTION_MAX_LENGTH=core.getInput("description_max_length")?Number.parseInt(core.getInput("description_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(),description:item.content?item.content:"",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).trim()+"..."),DESCRIPTION_MAX_LENGTH&&post&&post.description&&(post.description=post.description.trim().slice(0,DESCRIPTION_MAX_LENGTH)===post.description.trim()?post.description.trim():post.description.trim().slice(0,DESCRIPTION_MAX_LENGTH).trim()+"..."),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(async()=>{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||(await exec("git",["config","pull.rebase","true"]),await exec("git",["pull"]));const t=fs.readFileSync(README_FILE_PATH,"utf8"),r=core.getInput("template"),o=getParameterisedTemplate(r,"randomEmoji"),s=getParameterisedTemplate(r,"emojiKey"),n=postsArray.reduce((e,t,n)=>{if("default"===r)return e+`\n- [${t.title}](${t.url})`+(n+1===postsArray.length?"\n":"");{const i=dateFormat(t.date,core.getInput("date_format"));let a=r.replace(/\$title\b/g,t.title).replace(/\$url\b/g,t.url).replace(/\$description\b/g,t.description).replace(/\$date\b/g,i).replace(/\$newline/g,"\n");if(Object.keys(CUSTOM_TAGS).forEach(e=>{const r=t[e]?t[e]:"";a=a.replace(new RegExp("\\$"+e+"\\b","g"),r)}),o){const e=(process.env.GITHUB_REPOSITORY&&!process.env.TEST_MODE?process.env.GITHUB_REPOSITORY:"example")+n,t=o[rand.create(e).range(o.length)];a=a.replace(/\$randomEmoji\((\S)*\)/g,t)}return s&&(a=a.replace(/\$emojiKey\((\S)*\)/g,s[n%s.length])),e+a}},""),i=buildReadme(t,n);if(i!==t){core.info("Writing to "+README_FILE_PATH),fs.writeFileSync(README_FILE_PATH,i);const e="false"!==core.getInput("output_only");process.env.TEST_MODE||(e?(core.info("outputOnly mode: set `results` variable. Readme not updated."),core.setOutput("results",postsArray)):await commitReadme())}else 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 446932c..e9e955f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blog-post-workflow", - "version": "1.4.3", + "version": "1.4.4", "description": "Allows you to show your latest blog posts on your github profile or project readme", "main": "blog-post-workflow.js", "scripts": {