From d8b12e7787cc117a417a57dea13b8aae5d118902 Mon Sep 17 00:00:00 2001 From: gkr-bot Date: Sat, 19 Mar 2022 14:37:20 +0000 Subject: [PATCH] [skip-ci] Published 1.7.0 --- dist/blog-post-workflow.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/blog-post-workflow.js b/dist/blog-post-workflow.js index 577fb78..34d3d52 100644 --- a/dist/blog-post-workflow.js +++ b/dist/blog-post-workflow.js @@ -133,7 +133,7 @@ const{execute:t}=require("./util"),e=async(e,i,o,a,r=50)=>new Promise(async(n,c) },{"./util":"Re45"}],"FOZT":[function(require,module,exports) { function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function t(t){for(var r=1;rnew Promise((o,a)=>{let c="";const s=t({},i);s.stdio||Object.assign(s,{stdio:["inherit","inherit","inherit"]});const u=r(e,n,s);u.stdout&&u.stdout.on("data",function(e){c+=e.toString()}),u.on("close",e=>0!==e?a({code:e,outputData:c}):o({code:e,outputData:c})),u.on("error",()=>a({code:1,outputData:c}))}),a=(e,t)=>{const n=i.getInput("comment_tag_name"),r=n?`\x3c!-- ${n}:`:"\x3c!-- BLOG-POST-LIST:",o="true"===i.getInput("tag_post_pre_newline"),a=e.indexOf(`${r}START`),c=e.indexOf("--\x3e",a),s=e.indexOf(`${r}END`,c);return-1!==a&&-1!==c&&-1!==s||(i.error(`Cannot find the comment tag on the readme:\n${r}START --\x3e\n${r}END --\x3e`),process.exit(1)),[e.slice(0,c+"--\x3e".length),o?"\n":"",t,o?"\n":"",e.slice(s)].join("")},c=(e,t)=>{const n=e.trim(),r=[...n].slice(0,t).join("");return r===n?n:r.trim()+"..."},s=async(e,t)=>{const n=i.getInput("committer_username"),r=i.getInput("committer_email"),a=i.getInput("commit_message");await o("git",["config","--global","user.email",r]),e&&await o("git",["remote","set-url","origin",`https://${e}@github.com/${process.env.GITHUB_REPOSITORY}.git`]),await o("git",["config","--global","user.name",n]),await o("git",["add",...t]),await o("git",["commit","-m",a]),await o("git",["push"]),i.info("Readme updated successfully in the upstream repository")},u=(e,t)=>{const n=e.split("/");return 3===n.length?(Object.assign(t,{[n[0]]:n[1]}),n[0]):e},p=(e,t)=>{const n="$"+t+"(";if(e.indexOf(n)>-1){const t=e.indexOf(n)+n.length,r=e.indexOf(")",t);return-1===r?null:e.slice(t,r).split(",").map(e=>e.trim())}return null},l=e=>e.replace(/[&<>')("]/g,e=>({"&":"&","<":"<",">":">","'":"'",'"':""",")":")","(":"("})[e]);module.exports={updateAndParseCompoundParams:u,commitReadme:s,truncateString:c,buildReadme:a,exec:o,getParameterisedTemplate:p,escapeHTML:l}; },{"@actions/core":"FTVr"}],"KSDV":[function(require,module,exports) { -const{updateAndParseCompoundParams:e}=require("./utils"),t=require("@actions/core"),o={stackoverflow:"Comment by $author",stackexchange:"Comment by $author"},a=t.getInput("filter_comments").trim().split(",").map(t=>(t=t.trim()).startsWith("stackoverflow")||t.startsWith("stackexchange")?e(t,o):t),i=e=>!(-1!==a.indexOf("medium")&&e.link&&e.link.includes("medium.com")&&void 0===e.categories),r=e=>!(-1!==a.indexOf("stackoverflow")&&e.link&&e.link.includes("stackoverflow.com")&&e.title.startsWith(o.stackoverflow.replace(/\$author/g,e.author))),s=e=>!(-1!==a.indexOf("stackexchange")&&e.link&&e.link.includes("stackexchange.com")&&e.title.startsWith(o.stackexchange.replace(/\$author/g,e.author)));module.exports={ignoreMediumComments:i,ignoreStackOverflowComments:r,ignoreStackExchangeComments:s}; +const{updateAndParseCompoundParams:e}=require("./utils"),t=require("@actions/core"),a={stackoverflow:"Comment by $author",stackexchange:"Comment by $author"},r=t.getInput("filter_comments").trim().split(",").map(t=>(t=t.trim()).startsWith("stackoverflow")||t.startsWith("stackexchange")?e(t,a):t),n=e=>!(-1!==r.indexOf("medium")&&e.link&&e.link.includes("medium.com")&&void 0===e.categories),o=e=>!(-1!==r.indexOf("stackoverflow")&&e.link&&e.link.includes("stackoverflow.com")&&e.title.startsWith(a.stackoverflow.replace(/\$author/g,e.author))),i=e=>!(-1!==r.indexOf("stackexchange")&&e.link&&e.link.includes("stackexchange.com")&&e.title.startsWith(a.stackexchange.replace(/\$author/g,e.author))),s=a=>{if(!a.pubDate)return!0;const r=new Date,n=new Date(a.pubDate.trim()),o=t.getInput("filter_dates").trim();if(-1!==o.indexOf("daysAgo")){const t={daysAgo:""};e(o,t);const a=864e5,r=Number(t.daysAgo);return n>=new Date(Date.now()-a*r)}return-1!==o.indexOf("currentMonth")?n.getMonth()===r.getMonth()&&n.getFullYear()===r.getFullYear():-1===o.indexOf("currentYear")||n.getFullYear()===r.getFullYear()};module.exports={ignoreMediumComments:n,ignoreStackOverflowComments:o,ignoreStackExchangeComments:i,dateFilter:s}; },{"./utils":"FOZT","@actions/core":"FTVr"}],"MHPq":[function(require,module,exports) { -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;te.trim()),GITHUB_TOKEN=core.getInput("gh_token"),CUSTOM_TAGS={},ENABLE_KEEPALIVE="true"===core.getInput("enable_keepalive"),retryConfig={retries:Number.parseInt(core.getInput("retry_count")),factor:1,minTimeout:1e3*Number.parseInt(core.getInput("retry_wait_time"))};core.setSecret(GITHUB_TOKEN),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 feedNames=core.getInput("feed_names").trim(),feedNamesList=feedNames.split(",").map(e=>e.trim()),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)=>{promiseRetry((e,t)=>(t>1&&core.info(`Previous try for ${siteUrl} failed, retrying: ${t-1}`),parser.parseURL(siteUrl).catch(e)),retryConfig).then(data=>{if(data.items){const responsePosts=data.items,posts=responsePosts.filter(ignoreMediumComments).filter(ignoreStackOverflowComments).filter(ignoreStackExchangeComments).map(item=>{ENABLE_SORT&&ENABLE_VALIDATION&&!item.pubDate&&reject("Cannot read response->item->pubDate"),ENABLE_VALIDATION&&!item.title&&reject("Cannot read response->item->title"),ENABLE_VALIDATION&&!item.link&&reject("Cannot read response->item->link");let customTags={};Object.keys(CUSTOM_TAGS).forEach(e=>{item[e]&&Object.assign(customTags,{[e]:item[e]})});const categories=item.categories?item.categories:[];let post=_objectSpread(_objectSpread({title:item.title.trim(),url:item.link.trim(),description:item.content?item.content:""},customTags),{},{categories:categories});if(ENABLE_SORT&&(post.date=new Date(item.pubDate.trim())),TITLE_MAX_LENGTH&&post&&post.title&&(post.title=truncateString(post.title,TITLE_MAX_LENGTH)),DESCRIPTION_MAX_LENGTH&&post&&post.description){const e=post.description.trim();post.description=truncateString(e,DESCRIPTION_MAX_LENGTH)}if(ITEM_EXEC)try{eval(ITEM_EXEC)}catch(e){core.error("Failure in executing `item_exec` parameter"),core.error(e),process.exit(1)}const disableHtmlEncoding="false"!==core.getInput("disable_html_encoding");return!disableHtmlEncoding&&post&&Object.keys(post).forEach(e=>{"string"==typeof post[e]&&"url"!==e&&(post[e]=escapeHTML(post[e]))}),post});resolve(posts)}else reject("Cannot read response->item")},e=>{reject(e)})}))}),Promise.allSettled(promiseArray).then(e=>{e.forEach((e,t)=>{"fulfilled"===e.status?(core.info(runnerNameArray[t]+" runner succeeded. Post count: "+e.value.length),void 0!==typeof feedNamesList[t]&&feedNamesList[t]&&(e.value=e.value.map(e=>(e.feedName=feedNamesList[t],e))),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),ENABLE_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"],{stdio:["pipe","pipe","pipe"]}),await exec("git",["pull"],{stdio:["pipe","pipe","pipe"]}));const t=core.getInput("template"),r=getParameterisedTemplate(t,"randomEmoji"),o=getParameterisedTemplate(t,"emojiKey"),s=postsArray.reduce((e,s,i)=>{if("default"===t)return e+`\n- [${s.title}](${s.url})`+(i+1===postsArray.length?"\n":"");{const a=core.getInput("categories_template"),n="default"===a?s.categories.join(", "):s.categories.reduce((e,t)=>e+a.replace(/\$category\b/g,t.toString()),""),c=dateFormat(s.date,core.getInput("date_format"));let p=t.replace(/\$title\b/g,s.title).replace(/\$url\b/g,s.url).replace(/\$description\b/g,s.description).replace(/\$date\b/g,c).replace(/\$counter\b/g,(i+1).toString()).replace(/\$feedName\b/g,s.feedName?s.feedName:"").replace(/\$categories\b/g,n.toString()).replace(/\$newline/g,"\n");if(Object.keys(CUSTOM_TAGS).forEach(e=>{const t=s[e]?s[e]:"";p=p.replace(new RegExp("\\$"+e+"\\b","g"),t)}),r){const e=(process.env.GITHUB_REPOSITORY&&!process.env.TEST_MODE?process.env.GITHUB_REPOSITORY:"example")+i,t=r[rand.create(e).range(r.length)];p=p.replace(/\$randomEmoji\((\S)*\)/g,t)}return o&&(p=p.replace(/\$emojiKey\((\S)*\)/g,o[i%o.length])),e+p}},"");if("false"!==core.getInput("output_only")){core.info("outputOnly mode: set `results` variable. Readme not committed."),core.setOutput("results",postsArray);const e=path.join("/","tmp","blog_post_workflow_output.json");fs.existsSync(e)&&fs.rmSync(e),fs.writeFileSync(e,JSON.stringify(postsArray),{encoding:"utf-8"}),process.exit(jobFailFlag?1:0)}let i=0;if(README_FILE_PATH_LIST.forEach(e=>{const t=fs.readFileSync(e,"utf8"),r=buildReadme(t,s);r!==t&&(core.info("Writing to "+e),fs.writeFileSync(e,r),i+=1)}),i>0)process.env.TEST_MODE||await commitReadme(GITHUB_TOKEN,README_FILE_PATH_LIST).then(()=>{process.exit(jobFailFlag?1:0)});else{if(!process.env.TEST_MODE&&ENABLE_KEEPALIVE){const e=core.getInput("committer_username"),t=core.getInput("committer_email"),r=await keepaliveWorkflow.KeepAliveWorkflow(GITHUB_TOKEN,e,t,"dummy commit to keep the repository active, see https://git.io/Jtm4V",50);core.info(r)}else core.info("No change detected, skipping");process.exit(jobFailFlag?1: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;te.trim()),GITHUB_TOKEN=core.getInput("gh_token"),CUSTOM_TAGS={},ENABLE_KEEPALIVE="true"===core.getInput("enable_keepalive"),retryConfig={retries:Number.parseInt(core.getInput("retry_count")),factor:1,minTimeout:1e3*Number.parseInt(core.getInput("retry_wait_time"))};core.setSecret(GITHUB_TOKEN),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 feedNames=core.getInput("feed_names").trim(),feedNamesList=feedNames.split(",").map(e=>e.trim()),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)=>{promiseRetry((e,t)=>(t>1&&core.info(`Previous try for ${siteUrl} failed, retrying: ${t-1}`),parser.parseURL(siteUrl).catch(e)),retryConfig).then(data=>{if(data.items){const responsePosts=data.items,posts=responsePosts.filter(ignoreMediumComments).filter(ignoreStackOverflowComments).filter(ignoreStackExchangeComments).filter(dateFilter).map(item=>{ENABLE_SORT&&ENABLE_VALIDATION&&!item.pubDate&&reject("Cannot read response->item->pubDate"),ENABLE_VALIDATION&&!item.title&&reject("Cannot read response->item->title"),ENABLE_VALIDATION&&!item.link&&reject("Cannot read response->item->link");let customTags={};Object.keys(CUSTOM_TAGS).forEach(e=>{item[e]&&Object.assign(customTags,{[e]:item[e]})});const categories=item.categories?item.categories:[];let post=_objectSpread(_objectSpread({title:item.title.trim(),url:item.link.trim(),description:item.content?item.content:""},customTags),{},{categories:categories});if(ENABLE_SORT&&(post.date=new Date(item.pubDate.trim())),TITLE_MAX_LENGTH&&post&&post.title&&(post.title=truncateString(post.title,TITLE_MAX_LENGTH)),DESCRIPTION_MAX_LENGTH&&post&&post.description){const e=post.description.trim();post.description=truncateString(e,DESCRIPTION_MAX_LENGTH)}if(ITEM_EXEC)try{eval(ITEM_EXEC)}catch(e){core.error("Failure in executing `item_exec` parameter"),core.error(e),process.exit(1)}const disableHtmlEncoding="false"!==core.getInput("disable_html_encoding");return!disableHtmlEncoding&&post&&Object.keys(post).forEach(e=>{"string"==typeof post[e]&&"url"!==e&&(post[e]=escapeHTML(post[e]))}),post});resolve(posts)}else reject("Cannot read response->item")},e=>{reject(e)})}))}),Promise.allSettled(promiseArray).then(e=>{e.forEach((e,t)=>{"fulfilled"===e.status?(core.info(runnerNameArray[t]+" runner succeeded. Post count: "+e.value.length),void 0!==typeof feedNamesList[t]&&feedNamesList[t]&&(e.value=e.value.map(e=>(e.feedName=feedNamesList[t],e))),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),ENABLE_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"],{stdio:["pipe","pipe","pipe"]}),await exec("git",["pull"],{stdio:["pipe","pipe","pipe"]}));const t=core.getInput("template"),r=getParameterisedTemplate(t,"randomEmoji"),o=getParameterisedTemplate(t,"emojiKey"),s=postsArray.reduce((e,s,i)=>{if("default"===t)return e+`\n- [${s.title}](${s.url})`+(i+1===postsArray.length?"\n":"");{const a=core.getInput("categories_template"),n="default"===a?s.categories.join(", "):s.categories.reduce((e,t)=>e+a.replace(/\$category\b/g,t.toString()),""),c=dateFormat(s.date,core.getInput("date_format"));let p=t.replace(/\$title\b/g,s.title).replace(/\$url\b/g,s.url).replace(/\$description\b/g,s.description).replace(/\$date\b/g,c).replace(/\$counter\b/g,(i+1).toString()).replace(/\$feedName\b/g,s.feedName?s.feedName:"").replace(/\$categories\b/g,n.toString()).replace(/\$newline/g,"\n");if(Object.keys(CUSTOM_TAGS).forEach(e=>{const t=s[e]?s[e]:"";p=p.replace(new RegExp("\\$"+e+"\\b","g"),t)}),r){const e=(process.env.GITHUB_REPOSITORY&&!process.env.TEST_MODE?process.env.GITHUB_REPOSITORY:"example")+i,t=r[rand.create(e).range(r.length)];p=p.replace(/\$randomEmoji\((\S)*\)/g,t)}return o&&(p=p.replace(/\$emojiKey\((\S)*\)/g,o[i%o.length])),e+p}},"");if("false"!==core.getInput("output_only")){core.info("outputOnly mode: set `results` variable. Readme not committed."),core.setOutput("results",postsArray);const e=path.join("/","tmp","blog_post_workflow_output.json");fs.existsSync(e)&&fs.rmSync(e),fs.writeFileSync(e,JSON.stringify(postsArray),{encoding:"utf-8"}),process.exit(jobFailFlag?1:0)}let i=0;if(README_FILE_PATH_LIST.forEach(e=>{const t=fs.readFileSync(e,"utf8"),r=buildReadme(t,s);r!==t&&(core.info("Writing to "+e),fs.writeFileSync(e,r),i+=1)}),i>0)process.env.TEST_MODE||await commitReadme(GITHUB_TOKEN,README_FILE_PATH_LIST).then(()=>{process.exit(jobFailFlag?1:0)});else{if(!process.env.TEST_MODE&&ENABLE_KEEPALIVE){const e=core.getInput("committer_username"),t=core.getInput("committer_email"),r=await keepaliveWorkflow.KeepAliveWorkflow(GITHUB_TOKEN,e,t,"dummy commit to keep the repository active, see https://git.io/Jtm4V",50);core.info(r)}else core.info("No change detected, skipping");process.exit(jobFailFlag?1: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","random-seed":"KFkI","promise-retry":"gnqO","keepalive-workflow":"EQNY","./utils":"FOZT","./filters":"KSDV"}]},{},["MHPq"], null) \ No newline at end of file diff --git a/package.json b/package.json index 213f69c..2a56946 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blog-post-workflow", - "version": "1.6.9", + "version": "1.7.0", "description": "Allows you to show your latest blog posts on your github profile or project readme", "main": "blog-post-workflow.js", "scripts": {