diff --git a/dist/blog-post-workflow.js b/dist/blog-post-workflow.js index 18add62..193e371 100644 --- a/dist/blog-post-workflow.js +++ b/dist/blog-post-workflow.js @@ -106,8 +106,10 @@ const t=module.exports={},e=require("entities"),n=require("xml2js");t.stripHtml= "use strict";var e=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(exports,"__esModule",{value:!0});const t=e(require("os"));function r(e,r,s){const n=new i(e,r,s);process.stdout.write(n.toString()+t.EOL)}function s(e,t=""){r(e,{},t)}exports.issueCommand=r,exports.issue=s;const n="::";class i{constructor(e,t,r){e||(e="missing.command"),this.command=e,this.properties=t,this.message=r}toString(){let e=n+this.command;if(this.properties&&Object.keys(this.properties).length>0){e+=" ";let t=!0;for(const r in this.properties)if(this.properties.hasOwnProperty(r)){const s=this.properties[r];s&&(t?t=!1:e+=",",e+=`${r}=${p(s)}`)}}return e+=`${n}${c(this.message)}`}}function o(e){return null==e?"":"string"==typeof e||e instanceof String?e:JSON.stringify(e)}function c(e){return o(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function p(e){return o(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/:/g,"%3A").replace(/,/g,"%2C")}exports.toCommandValue=o; },{}],"FTVr":[function(require,module,exports) { "use strict";var e=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,s){function i(e){try{a(r.next(e))}catch(t){s(t)}}function u(e){try{a(r.throw(e))}catch(t){s(t)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(i,u)}a((r=r.apply(e,t||[])).next())})},t=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t};Object.defineProperty(exports,"__esModule",{value:!0});const n=require("./command"),r=t(require("os")),o=t(require("path"));var s;function i(e,t){const r=n.toCommandValue(t);process.env[e]=r,n.issueCommand("set-env",{name:e},r)}function u(e){n.issueCommand("add-mask",{},e)}function a(e){n.issueCommand("add-path",{},e),process.env.PATH=`${e}${o.delimiter}${process.env.PATH}`}function c(e,t){const n=process.env[`INPUT_${e.replace(/ /g,"_").toUpperCase()}`]||"";if(t&&t.required&&!n)throw new Error(`Input required and not supplied: ${e}`);return n.trim()}function p(e,t){n.issueCommand("set-output",{name:e},t)}function f(e){n.issue("echo",e?"on":"off")}function d(e){process.exitCode=s.Failure,l(e)}function m(){return"1"===process.env.RUNNER_DEBUG}function x(e){n.issueCommand("debug",{},e)}function l(e){n.issue("error",e instanceof Error?e.toString():e)}function v(e){n.issue("warning",e instanceof Error?e.toString():e)}function h(e){process.stdout.write(e+r.EOL)}function g(e){n.issue("group",e)}function C(){n.issue("endgroup")}function _(t,n){return e(this,void 0,void 0,function*(){let e;g(t);try{e=yield n()}finally{C()}return e})}function w(e,t){n.issueCommand("save-state",{name:e},t)}function E(e){return process.env[`STATE_${e}`]||""}!function(e){e[e.Success=0]="Success",e[e.Failure=1]="Failure"}(s=exports.ExitCode||(exports.ExitCode={})),exports.exportVariable=i,exports.setSecret=u,exports.addPath=a,exports.getInput=c,exports.setOutput=p,exports.setCommandEcho=f,exports.setFailed=d,exports.isDebug=m,exports.debug=x,exports.error=l,exports.warning=v,exports.info=h,exports.startGroup=g,exports.endGroup=C,exports.group=_,exports.saveState=w,exports.getState=E; -},{"./command":"Y3tv"}],"z3en":[function(require,module,exports) { +},{"./command":"Y3tv"}],"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)=>{console.log(`Started: ${e} ${t.join(" ")}`);const s=r({},o);s.stdio||Object.assign(s,{stdio:["inherit","inherit","inherit"]});const u=n(e,t,s);u.on("close",e=>{if(0!==e){const r=new Error(`Invalid status code: ${e}`);return r.code=e,i(r)}return c(e)}),u.on("error",i)});module.exports=o; },{}],"MHPq":[function(require,module,exports) { -const e=require("process");let t=require("rss-parser");const n=require("@actions/core"),r=require("fs"),i=require("./exec"),a=(t,r)=>{const i=n.getInput("comment_tag_name"),a=i?`\x3c!-- ${i}:`:"\x3c!-- BLOG-POST-LIST:",s=n.getInput("tag_post_pre_newline"),o=t.indexOf(`${a}START`),c=t.indexOf("--\x3e",o),l=t.indexOf(`${a}END`,c);return-1!==o&&-1!==c&&-1!==l||(n.error(`Cannot find the comment tag on the readme:\n\x3c!-- ${a}:START --\x3e\n\x3c!-- ${a}:END --\x3e`),e.exit(1)),[t.slice(0,c+"--\x3e".length),s?"\n":"",r,s?"\n":"",t.slice(l)].join("")},s=async()=>{const t=n.getInput("committer_username"),r=n.getInput("committer_email"),a=n.getInput("commit_message");await i("git",["config","--global","user.email",r]),g&&await i("git",["remote","set-url","origin",`https://${g}@github.com/${e.env.GITHUB_REPOSITORY}.git`]),await i("git",["config","--global","user.name",t]),await i("git",["add",m]),await i("git",["commit","-m",a]),await i("git",["push"]),n.info("Readme updated successfully in the upstream repository"),e.exit(k?1:0)},o=n.getInput("user_agent"),c=n.getInput("accept_header");let l=new t({headers:{"User-Agent":o,Accept:c}});const u=Number.parseInt(n.getInput("max_post_count")),m=n.getInput("readme_path"),g=n.getInput("gh_token"),p={stackoverflow:"Comment by $author",stackexchange:"Comment by $author"},h=e=>{const t=e.split("/");return 3===t.length?(Object.assign(p,{[t[0]]:t[1]}),t[0]):e};n.setSecret(g);const d=n.getInput("filter_comments").trim().split(",").map(e=>{const t=e.trim();return t.startsWith("stackoverflow")||t.startsWith("stackexchange")?h(e):t}),f=[],x=[];let _=[],k=!1;const I=n.getInput("feed_list").trim();let w=I.split(",").map(e=>e.trim());0===w.length&&(n.error("Please double check the value of feed_list"),e.exit(1));const $=e=>!(-1!==d.indexOf("medium")&&e.link.includes("medium.com")&&void 0===e.categories),b=e=>!(-1!==d.indexOf("stackoverflow")&&e.link.includes("stackoverflow.com")&&e.title.startsWith(p.stackoverflow.replace(/\$author/g,e.author))),v=e=>!(-1!==d.indexOf("stackexchange")&&e.link.includes("stackexchange.com")&&e.title.startsWith(p.stackexchange.replace(/\$author/g,e.author)));w.forEach(e=>{x.push(e),f.push(new Promise((t,n)=>{l.parseURL(e).then(e=>{if(e.items){const r=e.items.filter($).filter(b).filter(v).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"),{title:e.title.trim(),url:e.link.trim(),date:new Date(e.pubDate.trim())}));t(r)}else n("Cannot read response->item")}).catch(n)}))}),Promise.allSettled(f).then(e=>{e.forEach((e,t)=>{"fulfilled"===e.status?(n.info(x[t]+" runner succeeded. Post count: "+e.value.length),_.push(...e.value)):(k=!0,n.error(x[t]+" runner failed, please verify the configuration. Error:"),n.error(e.reason))})}).finally(()=>{if("false"===n.getInput("disable_sort")&&_.sort(function(e,t){return t.date-e.date}),(_=_.slice(0,u)).length>0)try{const i=r.readFileSync(m,"utf8"),o=n.getInput("template"),c=_.reduce((e,t,n)=>"default"===o?e+`\n- [${t.title}](${t.url})`+(n+1===_.length?"\n":""):e+o.replace(/\$title/g,t.title).replace(/\$url/g,t.url).replace(/\$newline/g,"\n"),""),l=a(i,c);l!==i?(n.info("Writing to "+m),r.writeFileSync(m,l),e.env.TEST_MODE||s()):(n.info("No change detected, skipping"),e.exit(0))}catch(t){n.error(t),e.exit(1)}else n.info("0 blog posts fetched"),e.exit(k?1:0)}); -},{"rss-parser":"BF6Y","@actions/core":"FTVr","./exec":"z3en"}]},{},["MHPq"], null) \ No newline at end of file +const e=require("process");let t=require("rss-parser");const n=require("@actions/core"),r=require("fs"),i=require("dateformat"),a=require("./exec"),s=(t,r)=>{const i=n.getInput("comment_tag_name"),a=i?`\x3c!-- ${i}:`:"\x3c!-- BLOG-POST-LIST:",s=n.getInput("tag_post_pre_newline"),o=t.indexOf(`${a}START`),c=t.indexOf("--\x3e",o),l=t.indexOf(`${a}END`,c);return-1!==o&&-1!==c&&-1!==l||(n.error(`Cannot find the comment tag on the readme:\n\x3c!-- ${a}:START --\x3e\n\x3c!-- ${a}:END --\x3e`),e.exit(1)),[t.slice(0,c+"--\x3e".length),s?"\n":"",r,s?"\n":"",t.slice(l)].join("")},o=async()=>{const t=n.getInput("committer_username"),r=n.getInput("committer_email"),i=n.getInput("commit_message");await a("git",["config","--global","user.email",r]),p&&await a("git",["remote","set-url","origin",`https://${p}@github.com/${e.env.GITHUB_REPOSITORY}.git`]),await a("git",["config","--global","user.name",t]),await a("git",["add",g]),await a("git",["commit","-m",i]),await a("git",["push"]),n.info("Readme updated successfully in the upstream repository"),e.exit(I?1:0)},c=n.getInput("user_agent"),l=n.getInput("accept_header");let u=new t({headers:{"User-Agent":c,Accept:l}});const m=Number.parseInt(n.getInput("max_post_count")),g=n.getInput("readme_path"),p=n.getInput("gh_token"),d={stackoverflow:"Comment by $author",stackexchange:"Comment by $author"},f=e=>{const t=e.split("/");return 3===t.length?(Object.assign(d,{[t[0]]:t[1]}),t[0]):e};n.setSecret(p);const h=n.getInput("filter_comments").trim().split(",").map(e=>{const t=e.trim();return t.startsWith("stackoverflow")||t.startsWith("stackexchange")?f(e):t}),x=[],_=[];let k=[],I=!1;const w=n.getInput("feed_list").trim();let $=w.split(",").map(e=>e.trim());0===$.length&&(n.error("Please double check the value of feed_list"),e.exit(1));const b=e=>!(-1!==h.indexOf("medium")&&e.link.includes("medium.com")&&void 0===e.categories),v=e=>!(-1!==h.indexOf("stackoverflow")&&e.link.includes("stackoverflow.com")&&e.title.startsWith(d.stackoverflow.replace(/\$author/g,e.author))),O=e=>!(-1!==h.indexOf("stackexchange")&&e.link.includes("stackexchange.com")&&e.title.startsWith(d.stackexchange.replace(/\$author/g,e.author)));$.forEach(e=>{_.push(e),x.push(new Promise((t,n)=>{u.parseURL(e).then(e=>{if(e.items){const r=e.items.filter(b).filter(v).filter(O).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"),{title:e.title.trim(),url:e.link.trim(),date:new Date(e.pubDate.trim())}));t(r)}else n("Cannot read response->item")}).catch(n)}))}),Promise.allSettled(x).then(e=>{e.forEach((e,t)=>{"fulfilled"===e.status?(n.info(_[t]+" runner succeeded. Post count: "+e.value.length),k.push(...e.value)):(I=!0,n.error(_[t]+" runner failed, please verify the configuration. Error:"),n.error(e.reason))})}).finally(()=>{if("false"===n.getInput("disable_sort")&&k.sort(function(e,t){return t.date-e.date}),(k=k.slice(0,m)).length>0)try{const a=r.readFileSync(g,"utf8"),c=n.getInput("template"),l=k.reduce((e,t,r)=>{if("default"===c)return e+`\n- [${t.title}](${t.url})`+(r+1===k.length?"\n":"");{const r=i(t.date,n.getInput("date_format"));return e+c.replace(/\$title/g,t.title).replace(/\$url/g,t.url).replace(/\$date/g,r).replace(/\$newline/g,"\n")}},""),u=s(a,l);u!==a?(n.info("Writing to "+g),r.writeFileSync(g,u),e.env.TEST_MODE||o()):(n.info("No change detected, skipping"),e.exit(0))}catch(t){n.error(t),e.exit(1)}else n.info("0 blog posts fetched"),e.exit(I?1:0)}); +},{"rss-parser":"BF6Y","@actions/core":"FTVr","dateformat":"FWyg","./exec":"z3en"}]},{},["MHPq"], null) \ No newline at end of file diff --git a/package.json b/package.json index 81c8332..97bfeda 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blog-post-workflow", - "version": "1.2.4", + "version": "1.2.5", "description": "Allows you to show your latest blog posts on your github profile or project readme", "main": "blog-post-workflow.js", "scripts": {