diff --git a/dist/blog-post-workflow.js b/dist/blog-post-workflow.js index 09886aa..b8396da 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=a.getInput("comment_tag_name"),i=r?`\x3c!-- ${r}:`:"\x3c!-- BLOG-POST-LIST:",o=a.getInput("tag_post_pre_newline"),c=e.indexOf(`${i}START`),s=e.indexOf("--\x3e",c),l=e.indexOf(`${i}END`,s);return-1!==c&&-1!==s&&-1!==l||(a.error(`Cannot find the comment tag on the readme:\n\x3c!-- ${i}:START --\x3e\n\x3c!-- ${i}:END --\x3e`),n.exit(1)),[e.slice(0,s+"--\x3e".length),o?"\n":"",t,o?"\n":"",e.slice(l)].join("")},m=async()=>{const e=a.getInput("committer_username"),t=a.getInput("committer_email"),r=a.getInput("commit_message");await s("git",["config","--global","user.email",t]),b&&await s("git",["remote","set-url","origin",`https://${b}@github.com/${n.env.GITHUB_REPOSITORY}.git`]),await s("git",["config","--global","user.name",e]),await s("git",["add",d]),await s("git",["commit","-m",r]),await s("git",["push"]),a.info("Readme updated successfully in the upstream repository"),n.exit(j?1:0)},p=a.getInput("user_agent"),g=a.getInput("accept_header"),f=Number.parseInt(a.getInput("max_post_count")),h=a.getInput("title_max_length")?Number.parseInt(a.getInput("title_max_length")):null,d=a.getInput("readme_path"),b=a.getInput("gh_token"),O={stackoverflow:"Comment by $author",stackexchange:"Comment by $author"},x={},_=(e,t)=>{const r=e.split("/");return 3===r.length?(Object.assign(t,{[r[0]]:r[1]}),r[0]):e},w=(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;a.setSecret(b);const y=a.getInput("filter_comments").trim().split(",").map(e=>(e=e.trim()).startsWith("stackoverflow")||e.startsWith("stackexchange")?_(e,O):e);a.getInput("custom_tags").trim().split(",").forEach(e=>{e=e.trim(),_(e,x)});const I=[],$=[];let k=[],j=!1;const E=a.getInput("feed_list").trim();let v=E.split(",").map(e=>e.trim());0===v.length&&(a.error("Please double check the value of feed_list"),n.exit(1));const P=e=>!(-1!==y.indexOf("medium")&&e.link.includes("medium.com")&&void 0===e.categories),T=e=>!(-1!==y.indexOf("stackoverflow")&&e.link.includes("stackoverflow.com")&&e.title.startsWith(O.stackoverflow.replace(/\$author/g,e.author))),S=e=>!(-1!==y.indexOf("stackexchange")&&e.link.includes("stackexchange.com")&&e.title.startsWith(O.stackexchange.replace(/\$author/g,e.author))),R=Object.keys(x).map(e=>[x[e],e]);let D=new i({headers:{"User-Agent":p,Accept:g},customFields:{item:[...R]}});v.forEach(e=>{$.push(e),I.push(new Promise((r,n)=>{D.parseURL(e).then(e=>{if(e.items){const i=e.items.filter(P).filter(T).filter(S).map(e=>{e.pubDate||n("Cannot read response->item->pubDate"),e.title||n("Cannot read response->item->title"),e.link||n("Cannot read response->item->link");let r={};return Object.keys(x).forEach(t=>{e[t]&&Object.assign(r,{[t]:e[t]})}),h&&(e.title=e.title.trim().slice(0,h)===e.title.trim()?e.title.trim():e.title.trim().slice(0,h)+"..."),t({title:e.title.trim(),url:e.link.trim(),date:new Date(e.pubDate.trim())},r)});r(i)}else n("Cannot read response->item")}).catch(n)}))}),Promise.allSettled(I).then(e=>{e.forEach((e,t)=>{"fulfilled"===e.status?(a.info($[t]+" runner succeeded. Post count: "+e.value.length),k.push(...e.value)):(j=!0,a.error($[t]+" runner failed, please verify the configuration. Error:"),a.error(e.reason))})}).finally(()=>{if("false"===a.getInput("disable_sort")&&k.sort(function(e,t){return t.date-e.date}),(k=k.slice(0,f)).length>0)try{const t=o.readFileSync(d,"utf8"),r=a.getInput("template"),i=w(r,"randomEmoji"),s=w(r,"emojiKey"),p=k.reduce((e,t,o)=>{if("default"===r)return e+`\n- [${t.title}](${t.url})`+(o+1===k.length?"\n":"");{const u=c(t.date,a.getInput("date_format"));let m=r.replace(/\$title\b/g,t.title).replace(/\$url\b/g,t.url).replace(/\$date\b/g,u).replace(/\$newline/g,"\n");if(Object.keys(x).forEach(e=>{const r=t[e]?t[e]:"";m=m.replace(new RegExp("\\$"+e+"\\b","g"),r)}),i){const e=(n.env.GITHUB_REPOSITORY&&!n.env.TEST_MODE?n.env.GITHUB_REPOSITORY:"example")+o,t=i[l.create(e).range(i.length)];m=m.replace(/\$randomEmoji\((.)*\)/g,t)}return s&&(m=m.replace(/\$emojiKey\((.)*\)/g,s[o%s.length])),e+m}},""),g=u(t,p);g!==t?(a.info("Writing to "+d),o.writeFileSync(d,g),n.env.TEST_MODE||m()):(a.info("No change detected, skipping"),n.exit(0))}catch(e){a.error(e),n.exit(1)}else a.info("0 blog posts fetched"),n.exit(j?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:",a=core.getInput("tag_post_pre_newline"),s=e.indexOf(`${o}START`),n=e.indexOf("--\x3e",s),i=e.indexOf(`${o}END`,n);return-1!==s&&-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),a?"\n":"",t,a?"\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.includes("medium.com")&&void 0===e.categories),ignoreStackOverflowComments=e=>!(-1!==COMMENT_FILTERS.indexOf("stackoverflow")&&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.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]})}),TITLE_MAX_LENGTH&&(item.title=item.title.trim().slice(0,TITLE_MAX_LENGTH)===item.title.trim()?item.title.trim():item.title.trim().slice(0,TITLE_MAX_LENGTH)+"...");const 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 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("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{const t=fs.readFileSync(README_FILE_PATH,"utf8"),r=core.getInput("template"),o=getParameterisedTemplate(r,"randomEmoji"),a=getParameterisedTemplate(r,"emojiKey"),s=postsArray.reduce((e,t,s)=>{if("default"===r)return e+`\n- [${t.title}](${t.url})`+(s+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")+s,t=o[rand.create(e).range(o.length)];i=i.replace(/\$randomEmoji\((.)*\)/g,t)}return a&&(i=i.replace(/\$emojiKey\((.)*\)/g,a[s%a.length])),e+i}},""),n=buildReadme(t,s);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 417a2c0..b258a36 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blog-post-workflow", - "version": "1.3.0", + "version": "1.3.1", "description": "Allows you to show your latest blog posts on your github profile or project readme", "main": "blog-post-workflow.js", "scripts": {