diff --git a/dist/blog-post-workflow.js b/dist/blog-post-workflow.js index bebfb31..c552b44 100644 --- a/dist/blog-post-workflow.js +++ b/dist/blog-post-workflow.js @@ -113,11 +113,11 @@ const t=module.exports={},e=require("entities"),n=require("xml2js");t.stripHtml= },{"./command":"Y3tv","./file-command":"JPy4","./utils":"ONtA"}],"FWyg":[function(require,module,exports) { !function(e){"use strict";var t,a,n,m=(t=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZWN]|"[^"]*"|'[^']*'/g,a=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,n=/[^-+\dA-Z]/g,function(e,s,r,d){if(1!==arguments.length||"string"!==(null===(y=e)?"null":void 0===y?"undefined":"object"!=typeof y?typeof y:Array.isArray(y)?"array":{}.toString.call(y).slice(8,-1).toLowerCase())||/\d/.test(e)||(s=e,e=void 0),(e=e||new Date)instanceof Date||(e=new Date(e)),isNaN(e))throw TypeError("Invalid date");var y,o=(s=String(m.masks[s]||s||m.masks.default)).slice(0,4);"UTC:"!==o&&"GMT:"!==o||(s=s.slice(4),r=!0,"GMT:"===o&&(d=!0));var u=r?"getUTC":"get",l=e[u+"Date"](),M=e[u+"Day"](),T=e[u+"Month"](),g=e[u+"FullYear"](),c=e[u+"Hours"](),f=e[u+"Minutes"](),h=e[u+"Seconds"](),D=e[u+"Milliseconds"](),N=r?0:e.getTimezoneOffset(),p=function(e){var t=new Date(e.getFullYear(),e.getMonth(),e.getDate());t.setDate(t.getDate()-(t.getDay()+6)%7+3);var a=new Date(t.getFullYear(),0,4);a.setDate(a.getDate()-(a.getDay()+6)%7+3);var n=t.getTimezoneOffset()-a.getTimezoneOffset();t.setHours(t.getHours()-n);var m=(t-a)/6048e5;return 1+Math.floor(m)}(e),H=function(e){var t=e.getDay();return 0===t&&(t=7),t}(e),S={d:l,dd:i(l),ddd:m.i18n.dayNames[M],dddd:m.i18n.dayNames[M+7],m:T+1,mm:i(T+1),mmm:m.i18n.monthNames[T],mmmm:m.i18n.monthNames[T+12],yy:String(g).slice(2),yyyy:g,h:c%12||12,hh:i(c%12||12),H:c,HH:i(c),M:f,MM:i(f),s:h,ss:i(h),l:i(D,3),L:i(Math.round(D/10)),t:c<12?m.i18n.timeNames[0]:m.i18n.timeNames[1],tt:c<12?m.i18n.timeNames[2]:m.i18n.timeNames[3],T:c<12?m.i18n.timeNames[4]:m.i18n.timeNames[5],TT:c<12?m.i18n.timeNames[6]:m.i18n.timeNames[7],Z:d?"GMT":r?"UTC":(String(e).match(a)||[""]).pop().replace(n,""),o:(N>0?"-":"+")+i(100*Math.floor(Math.abs(N)/60)+Math.abs(N)%60,4),S:["th","st","nd","rd"][l%10>3?0:(l%100-l%10!=10)*l%10],W:p,N:H};return s.replace(t,function(e){return e in S?S[e]:e.slice(1,e.length-1)})});function i(e,t){for(e=String(e),t=t||2;e.lengthnew Promise((c,i)=>{const s=r({},o);s.stdio||Object.assign(s,{stdio:["inherit","inherit","inherit"]});const u=n(e,t,s);u.on("close",r=>{if(0!==r){console.log(`Error on: ${e} ${t.join(" ")}`);const n=new Error(`Invalid status code: ${r}`);return n.code=r,i(n)}return c(r)}),u.on("error",i)});module.exports=o; +function t(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,o)}return r}function e(e){for(var o=1;onew Promise((c,i)=>{let u="";const s=e({},n);s.stdio||Object.assign(s,{stdio:["inherit","inherit","inherit"]});const a=o(t,r,s);a.stdout&&a.stdout.on("data",function(t){u+=t.toString()}),a.on("close",t=>0!==t?i({code:t,outputData:u}):c({code:t,outputData:u})),a.on("error",()=>i({code:1,outputData:u}))});module.exports=n; },{}],"yUp7":[function(require,module,exports) { function i(i,n,r,t){return JSON.stringify(i,e(n,t),r)}function e(i,e){var n=[],r=[];return null==e&&(e=function(i,e){return n[0]===e?"[Circular ~]":"[Circular ~."+r.slice(0,n.indexOf(e)).join(".")+"]"}),function(t,l){if(n.length>0){var u=n.indexOf(this);~u?n.splice(u+1):n.push(this),~u?r.splice(u,1/0,t):r.push(t),~n.indexOf(l)&&(l=e.call(this,t,l))}else n.push(l);return null==i?l:i.call(this,t,l)}}exports=module.exports=i,exports.getSerialize=e; },{}],"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"),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="false"!==core.getInput("output_only"),a=i?null:buildReadme(t,n);a!==t?(core.info("Writing to "+README_FILE_PATH),fs.writeFileSync(README_FILE_PATH,a),process.env.TEST_MODE||(i?(core.info("outputOnly mode: set `results` variable. Readme not updated."),core.setOutput("results",postsArray)):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"),i=e.indexOf(`${o}START`),a=e.indexOf("--\x3e",i),n=e.indexOf(`${o}END`,a);return-1!==i&&-1!==a&&-1!==n||(core.error(`Cannot find the comment tag on the readme:\n${o}:START --\x3e\n${o}:END --\x3e`),process.exit(1)),[e.slice(0,a+"--\x3e".length),s?"\n":"",t,s?"\n":"",e.slice(n)].join("")},commitReadme=async(e=!1)=>{const t=core.getInput("committer_username"),r=core.getInput("committer_email"),o=core.getInput("commit_message");await exec("git",["config","--global","user.email",r]),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",t]),e?await exec("git",["commit","--allow-empty","-m",'"dummy commit to keep the repository active, see blog-post-workflow/issues/53"']):(await exec("git",["add",README_FILE_PATH]),await exec("git",["commit","-m",o])),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"],{stdio:["pipe","pipe","pipe"]}),await exec("git",["pull"],{stdio:["pipe","pipe","pipe"]}));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 a=dateFormat(t.date,core.getInput("date_format"));let n=r.replace(/\$title\b/g,t.title).replace(/\$url\b/g,t.url).replace(/\$description\b/g,t.description).replace(/\$date\b/g,a).replace(/\$newline/g,"\n");if(Object.keys(CUSTOM_TAGS).forEach(e=>{const r=t[e]?t[e]:"";n=n.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)];n=n.replace(/\$randomEmoji\((\S)*\)/g,t)}return s&&(n=n.replace(/\$emojiKey\((\S)*\)/g,s[i%s.length])),e+n}},""),a="false"!==core.getInput("output_only"),n=a?null:buildReadme(t,i);if(n!==t)core.info("Writing to "+README_FILE_PATH),fs.writeFileSync(README_FILE_PATH,n),process.env.TEST_MODE||(a?(core.info("outputOnly mode: set `results` variable. Readme not updated."),core.setOutput("results",postsArray)):await commitReadme());else{const{outputData:e}=await exec("git",["--no-pager","log","-1","--format=%ct"],{encoding:"utf8",stdio:["pipe","pipe","pipe"]}),t=new Date(1e3*parseInt(e,10)),r=Math.round((new Date-t)/864e5);console.log(r),r>50&&!process.env.TEST_MODE?(core.info("Doing dummy commit to keep workflow active, see: https://git.io/Jtm4V"),await commitReadme(!0),process.exit(0)):(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 5d0649c..8731abd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blog-post-workflow", - "version": "1.4.5", + "version": "1.4.6", "description": "Allows you to show your latest blog posts on your github profile or project readme", "main": "blog-post-workflow.js", "scripts": {