From 0e340dffc372cce4ec2e045033f4151bed302872 Mon Sep 17 00:00:00 2001 From: Simon Wicki Date: Sun, 4 Apr 2021 09:52:43 +0200 Subject: [PATCH] feat: add template --- README.md | 11 ++++++----- dist/index.js | 14 +++++++------- index.js | 20 +++++++++++++++++++- local-run.js | 3 ++- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b3c41e4..69111e8 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,12 @@ Here are all the inputs you can change in your goodreads-profile-workflow.yml fi | Option | Default Value | Description | Required | |--------|--------|--------|--------| | `goodreads_user_id` | "" | The Goodreads account ID to fetch the books from. | Yes | -| `shelf` | "currently-reading" | The Goodreads shelf/list the books are in (default shelves: currently-reading, read, to-read) | No | -| `max_books_count` | "10" | Max count of books that will be taken from the shelf/list | No | -| `readme_file_path` | "./README.md" | Path of the readme file you want to update | No | -| `output_only` | "false" | Usually used together with local-run.js. Sets the generated array as `books` [output variable](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idoutputs) so that it can be consumed in other actions | No | -| `comment_tag_name` | "GOODREADS-LIST" | Overrides the default comment tag name (``). In case you want to run multiple instances over the same README | No | +| `shelf` | "`currently-reading`" | The Goodreads shelf/list the books are in (default shelves: currently-reading, read, to-read) | No | +| `max_books_count` | "`10`" | Max count of books that will be taken from the shelf/list | No | +| `readme_file_path` | "`./README.md`" | Path of the readme file you want to update | No | +| `output_only` | "`false`" | Usually used together with local-run.js. Sets the generated array as `books` [output variable](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idoutputs) so that it can be consumed in other actions | No | +| `comment_tag_name` | "`GOODREADS-LIST`" | Overrides the default comment tag name (``). In case you want to run multiple instances over the same README | No | +| `template` | "`- [$title]($url) by $author (⭐️$average_rating)`" | The list template written in Markdown.

**Suported variables:**
| No | ### More resources - Check out gautamkrishnar's [blog-post-workflow](https://github.com/gautamkrishnar/blog-post-workflow) for another great update readme workflow diff --git a/dist/index.js b/dist/index.js index d2b646c..f438d85 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,9 +1,9 @@ -var b=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var M=b(B=>{"use strict";Object.defineProperty(B,"__esModule",{value:!0});function Ue(e){return e==null?"":typeof e=="string"||e instanceof String?e:JSON.stringify(e)}B.toCommandValue=Ue});var Z=b(w=>{"use strict";var je=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(w,"__esModule",{value:!0});var He=je(require("os")),K=M();function W(e,t,r){let n=new Q(e,t,r);process.stdout.write(n.toString()+He.EOL)}w.issueCommand=W;function Xe(e,t=""){W(e,{},t)}w.issue=Xe;var z="::",Q=class{constructor(t,r,n){t||(t="missing.command"),this.command=t,this.properties=r,this.message=n}toString(){let t=z+this.command;if(this.properties&&Object.keys(this.properties).length>0){t+=" ";let r=!0;for(let n in this.properties)if(this.properties.hasOwnProperty(n)){let i=this.properties[n];i&&(r?r=!1:t+=",",t+=`${n}=${Ke(i)}`)}}return t+=`${z}${Ye(this.message)}`,t}};function Ye(e){return K.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function Ke(e){return K.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/:/g,"%3A").replace(/,/g,"%2C")}});var te=b(P=>{"use strict";var D=P&&P.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(P,"__esModule",{value:!0});var ee=D(require("fs")),Qe=D(require("os")),We=M();function ze(e,t){let r=process.env[`GITHUB_${e}`];if(!r)throw new Error(`Unable to find environment variable for file command ${e}`);if(!ee.existsSync(r))throw new Error(`Missing file at path: ${r}`);ee.appendFileSync(r,`${We.toCommandValue(t)}${Qe.EOL}`,{encoding:"utf8"})}P.issueCommand=ze});var ae=b(f=>{"use strict";var Ze=f&&f.__awaiter||function(e,t,r,n){function i(s){return s instanceof r?s:new r(function(a){a(s)})}return new(r||(r=Promise))(function(s,a){function o(c){try{l(n.next(c))}catch(d){a(d)}}function u(c){try{l(n.throw(c))}catch(d){a(d)}}function l(c){c.done?s(c.value):i(c.value).then(o,u)}l((n=n.apply(e,t||[])).next())})},re=f&&f.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(f,"__esModule",{value:!0});var m=Z(),ne=te(),De=M(),G=re(require("os")),et=re(require("path")),se;(function(e){e[e.Success=0]="Success",e[e.Failure=1]="Failure"})(se=f.ExitCode||(f.ExitCode={}));function tt(e,t){let r=De.toCommandValue(t);if(process.env[e]=r,process.env.GITHUB_ENV||""){let i="_GitHubActionsFileCommandDelimeter_",s=`${e}<<${i}${G.EOL}${r}${G.EOL}${i}`;ne.issueCommand("ENV",s)}else m.issueCommand("set-env",{name:e},r)}f.exportVariable=tt;function rt(e){m.issueCommand("add-mask",{},e)}f.setSecret=rt;function nt(e){process.env.GITHUB_PATH||""?ne.issueCommand("PATH",e):m.issueCommand("add-path",{},e),process.env.PATH=`${e}${et.delimiter}${process.env.PATH}`}f.addPath=nt;function st(e,t){let r=process.env[`INPUT_${e.replace(/ /g,"_").toUpperCase()}`]||"";if(t&&t.required&&!r)throw new Error(`Input required and not supplied: ${e}`);return r.trim()}f.getInput=st;function it(e,t){m.issueCommand("set-output",{name:e},t)}f.setOutput=it;function ot(e){m.issue("echo",e?"on":"off")}f.setCommandEcho=ot;function ut(e){process.exitCode=se.Failure,ie(e)}f.setFailed=ut;function at(){return process.env.RUNNER_DEBUG==="1"}f.isDebug=at;function ct(e){m.issueCommand("debug",{},e)}f.debug=ct;function ie(e){m.issue("error",e instanceof Error?e.toString():e)}f.error=ie;function lt(e){m.issue("warning",e instanceof Error?e.toString():e)}f.warning=lt;function ft(e){process.stdout.write(e+G.EOL)}f.info=ft;function oe(e){m.issue("group",e)}f.startGroup=oe;function ue(){m.issue("endgroup")}f.endGroup=ue;function dt(e,t){return Ze(this,void 0,void 0,function*(){oe(e);let r;try{r=yield t()}finally{ue()}return r})}f.group=dt;function ht(e,t){m.issueCommand("save-state",{name:e},t)}f.saveState=ht;function gt(e){return process.env[`STATE_${e}`]||""}f.getState=gt});var T=b(A=>{"use strict";var ce=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",pt=ce+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",le="["+ce+"]["+pt+"]*",bt=new RegExp("^"+le+"$"),Nt=function(e,t){let r=[],n=t.exec(e);for(;n;){let i=[],s=n.length;for(let a=0;a{"use strict";var E=T(),J=function(e,t,r){let n={};if((!e.child||E.isEmptyObject(e.child))&&(!e.attrsMap||E.isEmptyObject(e.attrsMap)))return E.isExist(e.val)?e.val:"";if(E.isExist(e.val)&&!(typeof e.val=="string"&&(e.val===""||e.val===t.cdataPositionChar))){let s=E.isTagNameInArrayMode(e.tagname,t.arrayMode,r);n[t.textNodeName]=s?[e.val]:e.val}E.merge(n,e.attrsMap,t.arrayMode);let i=Object.keys(e.child);for(let s=0;s1){n[a]=[];for(let o in e.child[a])e.child[a].hasOwnProperty(o)&&n[a].push(J(e.child[a][o],t,a))}else{let o=J(e.child[a][0],t,a),u=t.arrayMode===!0&&typeof o=="object"||E.isTagNameInArrayMode(a,t.arrayMode,r);n[a]=u?[o]:o}}return n};fe.convertToJson=J});var ge=b((Cr,he)=>{"use strict";he.exports=function(e,t,r){this.tagname=e,this.parent=t,this.child={},this.attrsMap={},this.val=r,this.addChild=function(n){Array.isArray(this.child[n.tagname])?this.child[n.tagname].push(n):this.child[n.tagname]=[n]}}});var I=b(F=>{"use strict";var O=T(),At=T().buildOptions,q=ge(),yr="<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)".replace(/NAME/g,O.nameRegexp);!Number.parseInt&&window.parseInt&&(Number.parseInt=window.parseInt);!Number.parseFloat&&window.parseFloat&&(Number.parseFloat=window.parseFloat);var pe={attributeNamePrefix:"@_",attrNodeName:!1,textNodeName:"#text",ignoreAttributes:!0,ignoreNameSpace:!1,allowBooleanAttributes:!1,parseNodeValue:!0,parseAttributeValue:!1,arrayMode:!1,trimValues:!0,cdataTagName:!1,cdataPositionChar:"\\c",tagValueProcessor:function(e,t){return e},attrValueProcessor:function(e,t){return e},stopNodes:[]};F.defaultOptions=pe;var be=["attributeNamePrefix","attrNodeName","textNodeName","ignoreAttributes","ignoreNameSpace","allowBooleanAttributes","parseNodeValue","parseAttributeValue","arrayMode","trimValues","cdataTagName","cdataPositionChar","tagValueProcessor","attrValueProcessor","parseTrueNumberOnly","stopNodes"];F.props=be;function $(e,t,r){return t&&(r.trimValues&&(t=t.trim()),t=r.tagValueProcessor(t,e),t=Ne(t,r.parseNodeValue,r.parseTrueNumberOnly)),t}function Ct(e,t){if(t.ignoreNameSpace){let r=e.split(":"),n=e.charAt(0)==="/"?"/":"";if(r[0]==="xmlns")return"";r.length===2&&(e=n+r[1])}return e}function Ne(e,t,r){if(t&&typeof e=="string"){let n;return e.trim()===""||isNaN(e)?n=e==="true"?!0:e==="false"?!1:e:(e.indexOf("0x")!==-1?n=Number.parseInt(e,16):e.indexOf(".")!==-1?(n=Number.parseFloat(e),e=e.replace(/\.?0+$/,"")):n=Number.parseInt(e,10),r&&(n=String(n)===e?n:e)),n}else return O.isExist(e)?e:""}var yt=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])(.*?)\\3)?`,"g");function me(e,t){if(!t.ignoreAttributes&&typeof e=="string"){e=e.replace(/\r?\n/g," ");let r=O.getAllMatches(e,yt),n=r.length,i={};for(let s=0;s",s,"Closing Tag is not closed."),u=e.substring(s+2,o).trim();if(t.ignoreNameSpace){let l=u.indexOf(":");l!==-1&&(u=u.substr(l+1))}n&&(n.val?n.val=O.getValue(n.val)+""+$(u,i,t):n.val=$(u,i,t)),t.stopNodes.length&&t.stopNodes.includes(n.tagname)&&(n.child=[],n.attrsMap==null&&(n.attrsMap={}),n.val=e.substr(n.startIndex+1,s-n.startIndex-1)),n=n.parent,i="",s=o}else if(e[s+1]==="?")s=_(e,"?>",s,"Pi Tag is not closed.");else if(e.substr(s+1,3)==="!--")s=_(e,"-->",s,"Comment is not closed.");else if(e.substr(s+1,2)==="!D"){let o=_(e,">",s,"DOCTYPE is not closed.");e.substring(s,o).indexOf("[")>=0?s=e.indexOf("]>",s)+1:s=o}else if(e.substr(s+1,2)==="!["){let o=_(e,"]]>",s,"CDATA is not closed.")-2,u=e.substring(s+9,o);if(i&&(n.val=O.getValue(n.val)+""+$(n.tagname,i,t),i=""),t.cdataTagName){let l=new q(t.cdataTagName,n,u);n.addChild(l),n.val=O.getValue(n.val)+t.cdataPositionChar,u&&(l.val=u)}else n.val=(n.val||"")+(u||"");s=o+2}else{let o=Tt(e,s+1),u=o.data,l=o.index,c=u.indexOf(" "),d=u,Y=!0;if(c!==-1&&(d=u.substr(0,c).replace(/\s\s*$/,""),u=u.substr(c+1)),t.ignoreNameSpace){let N=d.indexOf(":");N!==-1&&(d=d.substr(N+1),Y=d!==o.data.substr(N+1))}if(n&&i&&n.tagname!=="!xml"&&(n.val=O.getValue(n.val)+""+$(n.tagname,i,t)),u.length>0&&u.lastIndexOf("/")===u.length-1){d[d.length-1]==="/"?(d=d.substr(0,d.length-1),u=d):u=u.substr(0,u.length-1);let N=new q(d,n,"");d!==u&&(N.attrsMap=me(u,t)),n.addChild(N)}else{let N=new q(d,n);t.stopNodes.length&&t.stopNodes.includes(N.tagname)&&(N.startIndex=l),d!==u&&Y&&(N.attrsMap=me(u,t)),n.addChild(N),n=N}i="",s=l}else i+=e[s];return r};function Tt(e,t){let r,n="";for(let i=t;i")return{data:n,index:i};s===" "&&(s=" ")}n+=s}}function _(e,t,r,n){let i=e.indexOf(t,r);if(i===-1)throw new Error(n);return i+t.length-1}F.getTraversalObj=vt});var ve=b(Ae=>{"use strict";var R=T(),Et={allowBooleanAttributes:!1},Ot=["allowBooleanAttributes"];Ae.validate=function(e,t){t=R.buildOptions(t,Et,Ot);let r=[],n=!1,i=!1;e[0]==="\uFEFF"&&(e=e.substr(1));for(let s=0;s"&&e[s]!==" "&&e[s]!==" "&&e[s]!==` -`&&e[s]!=="\r";s++)o+=e[s];if(o=o.trim(),o[o.length-1]==="/"&&(o=o.substring(0,o.length-1),s--),!_t(o)){let c;return o.trim().length===0?c="There is an unnecessary space between tag name and backward slash '0)return g("InvalidTag","Closing tag '"+o+"' can't have attributes or invalid starting.",C(e,s));{let c=r.pop();if(o!==c)return g("InvalidTag","Closing tag '"+c+"' is expected inplace of '"+o+"'.",C(e,s));r.length==0&&(i=!0)}}else return g("InvalidTag","Closing tag '"+o+"' doesn't have proper closing.",C(e,s));else{let c=Te(l,t);if(c!==!0)return g(c.err.code,c.err.msg,C(e,s-l.length+c.err.line));if(i===!0)return g("InvalidXml","Multiple possible root nodes found.",C(e,s));r.push(o),n=!0}for(s++;s0)return g("InvalidXml","Invalid '"+JSON.stringify(r,null,4).replace(/\r?\n/g,"")+"' found.",1)}else return g("InvalidXml","Start tag expected.",1);return!0};function Ce(e,t){for(var r=t;t5&&n==="xml")return g("InvalidXml","XML declaration allowed only at the start of the document.",C(e,t));if(e[t]=="?"&&e[t+1]==">"){t++;break}else continue}return t}function ye(e,t){if(e.length>t+5&&e[t+1]==="-"&&e[t+2]==="-"){for(t+=3;t"){t+=2;break}}else if(e.length>t+8&&e[t+1]==="D"&&e[t+2]==="O"&&e[t+3]==="C"&&e[t+4]==="T"&&e[t+5]==="Y"&&e[t+6]==="P"&&e[t+7]==="E"){let r=1;for(t+=8;t"&&(r--,r===0))break}else if(e.length>t+9&&e[t+1]==="["&&e[t+2]==="C"&&e[t+3]==="D"&&e[t+4]==="A"&&e[t+5]==="T"&&e[t+6]==="A"&&e[t+7]==="["){for(t+=8;t"){t+=2;break}}return t}var It='"',St="'";function wt(e,t){let r="",n="",i=!1;for(;t"&&n===""){i=!0;break}r+=e[t]}return n!==""?!1:{value:r,index:t,tagClosed:i}}var Vt=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function Te(e,t){let r=R.getAllMatches(e,Vt),n={};for(let i=0;i{"use strict";var v=function(e){return String.fromCharCode(e)},h={nilChar:v(176),missingChar:v(201),nilPremitive:v(175),missingPremitive:v(200),emptyChar:v(178),emptyValue:v(177),boundryChar:v(179),objStart:v(198),arrStart:v(204),arrayEnd:v(185)},qt=[h.nilChar,h.nilPremitive,h.missingChar,h.missingPremitive,h.boundryChar,h.emptyChar,h.emptyValue,h.arrayEnd,h.objStart,h.arrStart],S=function(e,t,r){if(typeof t=="string")return e&&e[0]&&e[0].val!==void 0?U(e[0].val,t):U(e,t);{let n=$t(e);if(n===!0){let i="";if(Array.isArray(t)){i+=h.arrStart;let s=t[0],a=e.length;if(typeof s=="string")for(let o=0;o{"use strict";var L=T(),Lt=T().buildOptions,Ie=I(),xt=function(e,t){return t=Lt(t,Ie.defaultOptions,Ie.props),t.indentBy=t.indentBy||"",H(e,t,0)},H=function(e,t,r){let n="{",i=Object.keys(e.child);for(let o=0;o1){n+='"'+s+'" : [ ';for(var a in e.child[s])n+=H(e.child[s][a],t)+" , ";n=n.substr(0,n.length-1)+" ] "}else n+='"'+s+'" : '+H(e.child[s][0],t)+" ,"}return L.merge(n,e.attrsMap),L.isEmptyObject(n)?L.isExist(e.val)?e.val:"":(L.isExist(e.val)&&(typeof e.val=="string"&&(e.val===""||e.val===t.cdataPositionChar)||(n+='"'+t.textNodeName+'" : '+Bt(e.val))),n[n.length-1]===","&&(n=n.substr(0,n.length-2)),n+"}")};function Bt(e){return e===!0||e===!1||!isNaN(e)?e:'"'+e+'"'}_e.convertToJsonString=xt});var qe=b((wr,Ve)=>{"use strict";var Gt=T().buildOptions,Jt={attributeNamePrefix:"@_",attrNodeName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataTagName:!1,cdataPositionChar:"\\c",format:!1,indentBy:" ",supressEmptyNode:!1,tagValueProcessor:function(e){return e},attrValueProcessor:function(e){return e}},Ut=["attributeNamePrefix","attrNodeName","textNodeName","ignoreAttributes","cdataTagName","cdataPositionChar","format","indentBy","supressEmptyNode","tagValueProcessor","attrValueProcessor"];function X(e){this.options=Gt(e,Jt,Ut),this.options.ignoreAttributes||this.options.attrNodeName?this.isAttribute=function(){return!1}:(this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=Qt),this.options.cdataTagName?this.isCDATA=Wt:this.isCDATA=function(){return!1},this.replaceCDATAstr=jt,this.replaceCDATAarr=Ht,this.options.format?(this.indentate=Kt,this.tagEndChar=`> +var b=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var M=b(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});function Ue(e){return e==null?"":typeof e=="string"||e instanceof String?e:JSON.stringify(e)}k.toCommandValue=Ue});var Z=b(_=>{"use strict";var je=_&&_.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(_,"__esModule",{value:!0});var He=je(require("os")),z=M();function Q(e,t,r){let n=new K(e,t,r);process.stdout.write(n.toString()+He.EOL)}_.issueCommand=Q;function Xe(e,t=""){Q(e,{},t)}_.issue=Xe;var W="::",K=class{constructor(t,r,n){t||(t="missing.command"),this.command=t,this.properties=r,this.message=n}toString(){let t=W+this.command;if(this.properties&&Object.keys(this.properties).length>0){t+=" ";let r=!0;for(let n in this.properties)if(this.properties.hasOwnProperty(n)){let i=this.properties[n];i&&(r?r=!1:t+=",",t+=`${n}=${ze(i)}`)}}return t+=`${W}${Ye(this.message)}`,t}};function Ye(e){return z.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function ze(e){return z.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/:/g,"%3A").replace(/,/g,"%2C")}});var te=b(w=>{"use strict";var D=w&&w.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(w,"__esModule",{value:!0});var ee=D(require("fs")),Ke=D(require("os")),Qe=M();function We(e,t){let r=process.env[`GITHUB_${e}`];if(!r)throw new Error(`Unable to find environment variable for file command ${e}`);if(!ee.existsSync(r))throw new Error(`Missing file at path: ${r}`);ee.appendFileSync(r,`${Qe.toCommandValue(t)}${Ke.EOL}`,{encoding:"utf8"})}w.issueCommand=We});var ae=b(f=>{"use strict";var Ze=f&&f.__awaiter||function(e,t,r,n){function i(s){return s instanceof r?s:new r(function(a){a(s)})}return new(r||(r=Promise))(function(s,a){function o(c){try{l(n.next(c))}catch(d){a(d)}}function u(c){try{l(n.throw(c))}catch(d){a(d)}}function l(c){c.done?s(c.value):i(c.value).then(o,u)}l((n=n.apply(e,t||[])).next())})},re=f&&f.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(f,"__esModule",{value:!0});var m=Z(),ne=te(),De=M(),G=re(require("os")),et=re(require("path")),se;(function(e){e[e.Success=0]="Success",e[e.Failure=1]="Failure"})(se=f.ExitCode||(f.ExitCode={}));function tt(e,t){let r=De.toCommandValue(t);if(process.env[e]=r,process.env.GITHUB_ENV||""){let i="_GitHubActionsFileCommandDelimeter_",s=`${e}<<${i}${G.EOL}${r}${G.EOL}${i}`;ne.issueCommand("ENV",s)}else m.issueCommand("set-env",{name:e},r)}f.exportVariable=tt;function rt(e){m.issueCommand("add-mask",{},e)}f.setSecret=rt;function nt(e){process.env.GITHUB_PATH||""?ne.issueCommand("PATH",e):m.issueCommand("add-path",{},e),process.env.PATH=`${e}${et.delimiter}${process.env.PATH}`}f.addPath=nt;function st(e,t){let r=process.env[`INPUT_${e.replace(/ /g,"_").toUpperCase()}`]||"";if(t&&t.required&&!r)throw new Error(`Input required and not supplied: ${e}`);return r.trim()}f.getInput=st;function it(e,t){m.issueCommand("set-output",{name:e},t)}f.setOutput=it;function ot(e){m.issue("echo",e?"on":"off")}f.setCommandEcho=ot;function ut(e){process.exitCode=se.Failure,ie(e)}f.setFailed=ut;function at(){return process.env.RUNNER_DEBUG==="1"}f.isDebug=at;function ct(e){m.issueCommand("debug",{},e)}f.debug=ct;function ie(e){m.issue("error",e instanceof Error?e.toString():e)}f.error=ie;function lt(e){m.issue("warning",e instanceof Error?e.toString():e)}f.warning=lt;function ft(e){process.stdout.write(e+G.EOL)}f.info=ft;function oe(e){m.issue("group",e)}f.startGroup=oe;function ue(){m.issue("endgroup")}f.endGroup=ue;function dt(e,t){return Ze(this,void 0,void 0,function*(){oe(e);let r;try{r=yield t()}finally{ue()}return r})}f.group=dt;function ht(e,t){m.issueCommand("save-state",{name:e},t)}f.saveState=ht;function gt(e){return process.env[`STATE_${e}`]||""}f.getState=gt});var T=b(A=>{"use strict";var ce=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",pt=ce+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",le="["+ce+"]["+pt+"]*",bt=new RegExp("^"+le+"$"),Nt=function(e,t){let r=[],n=t.exec(e);for(;n;){let i=[],s=n.length;for(let a=0;a{"use strict";var E=T(),J=function(e,t,r){let n={};if((!e.child||E.isEmptyObject(e.child))&&(!e.attrsMap||E.isEmptyObject(e.attrsMap)))return E.isExist(e.val)?e.val:"";if(E.isExist(e.val)&&!(typeof e.val=="string"&&(e.val===""||e.val===t.cdataPositionChar))){let s=E.isTagNameInArrayMode(e.tagname,t.arrayMode,r);n[t.textNodeName]=s?[e.val]:e.val}E.merge(n,e.attrsMap,t.arrayMode);let i=Object.keys(e.child);for(let s=0;s1){n[a]=[];for(let o in e.child[a])e.child[a].hasOwnProperty(o)&&n[a].push(J(e.child[a][o],t,a))}else{let o=J(e.child[a][0],t,a),u=t.arrayMode===!0&&typeof o=="object"||E.isTagNameInArrayMode(a,t.arrayMode,r);n[a]=u?[o]:o}}return n};fe.convertToJson=J});var ge=b((Tr,he)=>{"use strict";he.exports=function(e,t,r){this.tagname=e,this.parent=t,this.child={},this.attrsMap={},this.val=r,this.addChild=function(n){Array.isArray(this.child[n.tagname])?this.child[n.tagname].push(n):this.child[n.tagname]=[n]}}});var I=b(F=>{"use strict";var O=T(),At=T().buildOptions,q=ge(),vr="<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)".replace(/NAME/g,O.nameRegexp);!Number.parseInt&&window.parseInt&&(Number.parseInt=window.parseInt);!Number.parseFloat&&window.parseFloat&&(Number.parseFloat=window.parseFloat);var pe={attributeNamePrefix:"@_",attrNodeName:!1,textNodeName:"#text",ignoreAttributes:!0,ignoreNameSpace:!1,allowBooleanAttributes:!1,parseNodeValue:!0,parseAttributeValue:!1,arrayMode:!1,trimValues:!0,cdataTagName:!1,cdataPositionChar:"\\c",tagValueProcessor:function(e,t){return e},attrValueProcessor:function(e,t){return e},stopNodes:[]};F.defaultOptions=pe;var be=["attributeNamePrefix","attrNodeName","textNodeName","ignoreAttributes","ignoreNameSpace","allowBooleanAttributes","parseNodeValue","parseAttributeValue","arrayMode","trimValues","cdataTagName","cdataPositionChar","tagValueProcessor","attrValueProcessor","parseTrueNumberOnly","stopNodes"];F.props=be;function $(e,t,r){return t&&(r.trimValues&&(t=t.trim()),t=r.tagValueProcessor(t,e),t=Ne(t,r.parseNodeValue,r.parseTrueNumberOnly)),t}function Ct(e,t){if(t.ignoreNameSpace){let r=e.split(":"),n=e.charAt(0)==="/"?"/":"";if(r[0]==="xmlns")return"";r.length===2&&(e=n+r[1])}return e}function Ne(e,t,r){if(t&&typeof e=="string"){let n;return e.trim()===""||isNaN(e)?n=e==="true"?!0:e==="false"?!1:e:(e.indexOf("0x")!==-1?n=Number.parseInt(e,16):e.indexOf(".")!==-1?(n=Number.parseFloat(e),e=e.replace(/\.?0+$/,"")):n=Number.parseInt(e,10),r&&(n=String(n)===e?n:e)),n}else return O.isExist(e)?e:""}var yt=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])(.*?)\\3)?`,"g");function me(e,t){if(!t.ignoreAttributes&&typeof e=="string"){e=e.replace(/\r?\n/g," ");let r=O.getAllMatches(e,yt),n=r.length,i={};for(let s=0;s",s,"Closing Tag is not closed."),u=e.substring(s+2,o).trim();if(t.ignoreNameSpace){let l=u.indexOf(":");l!==-1&&(u=u.substr(l+1))}n&&(n.val?n.val=O.getValue(n.val)+""+$(u,i,t):n.val=$(u,i,t)),t.stopNodes.length&&t.stopNodes.includes(n.tagname)&&(n.child=[],n.attrsMap==null&&(n.attrsMap={}),n.val=e.substr(n.startIndex+1,s-n.startIndex-1)),n=n.parent,i="",s=o}else if(e[s+1]==="?")s=P(e,"?>",s,"Pi Tag is not closed.");else if(e.substr(s+1,3)==="!--")s=P(e,"-->",s,"Comment is not closed.");else if(e.substr(s+1,2)==="!D"){let o=P(e,">",s,"DOCTYPE is not closed.");e.substring(s,o).indexOf("[")>=0?s=e.indexOf("]>",s)+1:s=o}else if(e.substr(s+1,2)==="!["){let o=P(e,"]]>",s,"CDATA is not closed.")-2,u=e.substring(s+9,o);if(i&&(n.val=O.getValue(n.val)+""+$(n.tagname,i,t),i=""),t.cdataTagName){let l=new q(t.cdataTagName,n,u);n.addChild(l),n.val=O.getValue(n.val)+t.cdataPositionChar,u&&(l.val=u)}else n.val=(n.val||"")+(u||"");s=o+2}else{let o=Tt(e,s+1),u=o.data,l=o.index,c=u.indexOf(" "),d=u,Y=!0;if(c!==-1&&(d=u.substr(0,c).replace(/\s\s*$/,""),u=u.substr(c+1)),t.ignoreNameSpace){let N=d.indexOf(":");N!==-1&&(d=d.substr(N+1),Y=d!==o.data.substr(N+1))}if(n&&i&&n.tagname!=="!xml"&&(n.val=O.getValue(n.val)+""+$(n.tagname,i,t)),u.length>0&&u.lastIndexOf("/")===u.length-1){d[d.length-1]==="/"?(d=d.substr(0,d.length-1),u=d):u=u.substr(0,u.length-1);let N=new q(d,n,"");d!==u&&(N.attrsMap=me(u,t)),n.addChild(N)}else{let N=new q(d,n);t.stopNodes.length&&t.stopNodes.includes(N.tagname)&&(N.startIndex=l),d!==u&&Y&&(N.attrsMap=me(u,t)),n.addChild(N),n=N}i="",s=l}else i+=e[s];return r};function Tt(e,t){let r,n="";for(let i=t;i")return{data:n,index:i};s===" "&&(s=" ")}n+=s}}function P(e,t,r,n){let i=e.indexOf(t,r);if(i===-1)throw new Error(n);return i+t.length-1}F.getTraversalObj=vt});var ve=b(Ae=>{"use strict";var R=T(),Et={allowBooleanAttributes:!1},Ot=["allowBooleanAttributes"];Ae.validate=function(e,t){t=R.buildOptions(t,Et,Ot);let r=[],n=!1,i=!1;e[0]==="\uFEFF"&&(e=e.substr(1));for(let s=0;s"&&e[s]!==" "&&e[s]!==" "&&e[s]!==` +`&&e[s]!=="\r";s++)o+=e[s];if(o=o.trim(),o[o.length-1]==="/"&&(o=o.substring(0,o.length-1),s--),!Pt(o)){let c;return o.trim().length===0?c="There is an unnecessary space between tag name and backward slash '0)return g("InvalidTag","Closing tag '"+o+"' can't have attributes or invalid starting.",C(e,s));{let c=r.pop();if(o!==c)return g("InvalidTag","Closing tag '"+c+"' is expected inplace of '"+o+"'.",C(e,s));r.length==0&&(i=!0)}}else return g("InvalidTag","Closing tag '"+o+"' doesn't have proper closing.",C(e,s));else{let c=Te(l,t);if(c!==!0)return g(c.err.code,c.err.msg,C(e,s-l.length+c.err.line));if(i===!0)return g("InvalidXml","Multiple possible root nodes found.",C(e,s));r.push(o),n=!0}for(s++;s0)return g("InvalidXml","Invalid '"+JSON.stringify(r,null,4).replace(/\r?\n/g,"")+"' found.",1)}else return g("InvalidXml","Start tag expected.",1);return!0};function Ce(e,t){for(var r=t;t5&&n==="xml")return g("InvalidXml","XML declaration allowed only at the start of the document.",C(e,t));if(e[t]=="?"&&e[t+1]==">"){t++;break}else continue}return t}function ye(e,t){if(e.length>t+5&&e[t+1]==="-"&&e[t+2]==="-"){for(t+=3;t"){t+=2;break}}else if(e.length>t+8&&e[t+1]==="D"&&e[t+2]==="O"&&e[t+3]==="C"&&e[t+4]==="T"&&e[t+5]==="Y"&&e[t+6]==="P"&&e[t+7]==="E"){let r=1;for(t+=8;t"&&(r--,r===0))break}else if(e.length>t+9&&e[t+1]==="["&&e[t+2]==="C"&&e[t+3]==="D"&&e[t+4]==="A"&&e[t+5]==="T"&&e[t+6]==="A"&&e[t+7]==="["){for(t+=8;t"){t+=2;break}}return t}var It='"',St="'";function _t(e,t){let r="",n="",i=!1;for(;t"&&n===""){i=!0;break}r+=e[t]}return n!==""?!1:{value:r,index:t,tagClosed:i}}var Vt=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function Te(e,t){let r=R.getAllMatches(e,Vt),n={};for(let i=0;i{"use strict";var v=function(e){return String.fromCharCode(e)},h={nilChar:v(176),missingChar:v(201),nilPremitive:v(175),missingPremitive:v(200),emptyChar:v(178),emptyValue:v(177),boundryChar:v(179),objStart:v(198),arrStart:v(204),arrayEnd:v(185)},qt=[h.nilChar,h.nilPremitive,h.missingChar,h.missingPremitive,h.boundryChar,h.emptyChar,h.emptyValue,h.arrayEnd,h.objStart,h.arrStart],S=function(e,t,r){if(typeof t=="string")return e&&e[0]&&e[0].val!==void 0?U(e[0].val,t):U(e,t);{let n=$t(e);if(n===!0){let i="";if(Array.isArray(t)){i+=h.arrStart;let s=t[0],a=e.length;if(typeof s=="string")for(let o=0;o{"use strict";var x=T(),xt=T().buildOptions,Ie=I(),Bt=function(e,t){return t=xt(t,Ie.defaultOptions,Ie.props),t.indentBy=t.indentBy||"",H(e,t,0)},H=function(e,t,r){let n="{",i=Object.keys(e.child);for(let o=0;o1){n+='"'+s+'" : [ ';for(var a in e.child[s])n+=H(e.child[s][a],t)+" , ";n=n.substr(0,n.length-1)+" ] "}else n+='"'+s+'" : '+H(e.child[s][0],t)+" ,"}return x.merge(n,e.attrsMap),x.isEmptyObject(n)?x.isExist(e.val)?e.val:"":(x.isExist(e.val)&&(typeof e.val=="string"&&(e.val===""||e.val===t.cdataPositionChar)||(n+='"'+t.textNodeName+'" : '+kt(e.val))),n[n.length-1]===","&&(n=n.substr(0,n.length-2)),n+"}")};function kt(e){return e===!0||e===!1||!isNaN(e)?e:'"'+e+'"'}Pe.convertToJsonString=Bt});var qe=b((Pr,Ve)=>{"use strict";var Gt=T().buildOptions,Jt={attributeNamePrefix:"@_",attrNodeName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataTagName:!1,cdataPositionChar:"\\c",format:!1,indentBy:" ",supressEmptyNode:!1,tagValueProcessor:function(e){return e},attrValueProcessor:function(e){return e}},Ut=["attributeNamePrefix","attrNodeName","textNodeName","ignoreAttributes","cdataTagName","cdataPositionChar","format","indentBy","supressEmptyNode","tagValueProcessor","attrValueProcessor"];function X(e){this.options=Gt(e,Jt,Ut),this.options.ignoreAttributes||this.options.attrNodeName?this.isAttribute=function(){return!1}:(this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=Kt),this.options.cdataTagName?this.isCDATA=Qt:this.isCDATA=function(){return!1},this.replaceCDATAstr=jt,this.replaceCDATAarr=Ht,this.options.format?(this.indentate=zt,this.tagEndChar=`> `,this.newLine=` -`):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine=""),this.options.supressEmptyNode?(this.buildTextNode=Yt,this.buildObjNode=Xt):(this.buildTextNode=Fe,this.buildObjNode=Me),this.buildTextValNode=Fe,this.buildObjectNode=Me}X.prototype.parse=function(e){return this.j2x(e,0).val};X.prototype.j2x=function(e,t){let r="",n="",i=Object.keys(e),s=i.length;for(let a=0;a");return e+this.newLine}function Me(e,t,r,n){return r&&!e.includes("<")?this.indentate(n)+"<"+t+r+">"+e+""+this.options.tagValueProcessor(e)+"{"use strict";var $e=de(),Re=I(),ke=I(),zt=T().buildOptions,Le=ve();y.parse=function(e,t,r){if(r){r===!0&&(r={});let i=Le.validate(e,r);if(i!==!0)throw Error(i.err.msg)}t=zt(t,ke.defaultOptions,ke.props);let n=Re.getTraversalObj(e,t);return $e.convertToJson(n,t)};y.convertTonimn=Pe().convert2nimn;y.getTraversalObj=Re.getTraversalObj;y.convertToJson=$e.convertToJson;y.convertToJsonString=Se().convertToJsonString;y.validate=Le.validate;y.j2xParser=qe();y.parseToNimn=function(e,t,r){return y.convertTonimn(y.getTraversalObj(e,r),t,r)}});var Ge=b((_r,Be)=>{var{spawn:Zt}=require("child_process"),Dt=(e,t=[],r={})=>new Promise((n,i)=>{let s="",a={...r};a.stdio||Object.assign(a,{stdio:["inherit","inherit","inherit"]});let o=Zt(e,t,a);o.stdout&&o.stdout.on("data",function(u){s+=u.toString()}),o.on("close",u=>u!==0?i({code:u,outputData:s}):n({code:u,outputData:s})),o.on("error",()=>i({code:1,outputData:s}))});Be.exports=Dt});var er=require("https"),Je=require("fs"),p=ae(),tr=xe(),V=Ge(),rr=p.getInput("goodreads_user_id"),nr=p.getInput("shelf"),sr=Number.parseInt(p.getInput("max_books_count")),x=p.getInput("readme_file_path"),ir=p.getInput("output_only").toLowerCase()==="true",or="Synced and updated with user's goodreads book lists",ur="goodreads-books-bot",ar="goodreads-books-bot@example.com";cr(rr,nr).then(async e=>{try{let t=e.rss.channel.item.slice(0,sr),r=Je.readFileSync(x,"utf8"),n=lr(r,t);r!==n&&(p.info(`Writing to ${x}`),p.startGroup("New books found for update"),t.forEach(i=>p.info(JSON.stringify(i))),p.endGroup(),Je.writeFileSync(x,n),ir?(p.setOutput("books",t),p.info("OUTPUT_ONLY: set `results` variable. Readme not committed.")):await fr())}catch(t){p.error(t),process.exit(1)}}).then(()=>{process.exit(0)}).catch(e=>{p.error(e),process.exit(1)});function cr(e,t){return new Promise((r,n)=>{er.request({host:"www.goodreads.com",path:`/review/list_rss/${e}?shelf=${t}`},i=>{let s="";i.on("data",a=>s+=a),i.on("end",()=>r(tr.parse(s))),i.on("error",a=>n(a))}).end()})}function lr(e,t){let r=p.getInput("comment_tag_name")||"GOODREADS-LIST",n=``,i=``;if(![n,i].every(a=>e.match(new RegExp(a,"gm"))))p.error(`Cannot find the required comment tags (${n} and ${i}) to inject book titles.`),process.exit(1);else{let a=e.indexOf(n),o=e.indexOf(i),u=dr(t);return[e.substring(0,a+n.length),` +`):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine=""),this.options.supressEmptyNode?(this.buildTextNode=Yt,this.buildObjNode=Xt):(this.buildTextNode=Fe,this.buildObjNode=Me),this.buildTextValNode=Fe,this.buildObjectNode=Me}X.prototype.parse=function(e){return this.j2x(e,0).val};X.prototype.j2x=function(e,t){let r="",n="",i=Object.keys(e),s=i.length;for(let a=0;a");return e+this.newLine}function Me(e,t,r,n){return r&&!e.includes("<")?this.indentate(n)+"<"+t+r+">"+e+""+this.options.tagValueProcessor(e)+"{"use strict";var $e=de(),Re=I(),Le=I(),Wt=T().buildOptions,xe=ve();y.parse=function(e,t,r){if(r){r===!0&&(r={});let i=xe.validate(e,r);if(i!==!0)throw Error(i.err.msg)}t=Wt(t,Le.defaultOptions,Le.props);let n=Re.getTraversalObj(e,t);return $e.convertToJson(n,t)};y.convertTonimn=we().convert2nimn;y.getTraversalObj=Re.getTraversalObj;y.convertToJson=$e.convertToJson;y.convertToJsonString=Se().convertToJsonString;y.validate=xe.validate;y.j2xParser=qe();y.parseToNimn=function(e,t,r){return y.convertTonimn(y.getTraversalObj(e,r),t,r)}});var Ge=b((Sr,ke)=>{var{spawn:Zt}=require("child_process"),Dt=(e,t=[],r={})=>new Promise((n,i)=>{let s="",a={...r};a.stdio||Object.assign(a,{stdio:["inherit","inherit","inherit"]});let o=Zt(e,t,a);o.stdout&&o.stdout.on("data",function(u){s+=u.toString()}),o.on("close",u=>u!==0?i({code:u,outputData:s}):n({code:u,outputData:s})),o.on("error",()=>i({code:1,outputData:s}))});ke.exports=Dt});var er=require("https"),Je=require("fs"),p=ae(),tr=Be(),V=Ge(),rr=p.getInput("goodreads_user_id"),nr=p.getInput("shelf"),sr=Number.parseInt(p.getInput("max_books_count")),B=p.getInput("readme_file_path"),ir=p.getInput("output_only").toLowerCase()==="true",or=p.getInput("template")||"- [$title]($url) by $author (\u2B50\uFE0F$average_rating)",ur="Synced and updated with user's goodreads book lists",ar="goodreads-books-bot",cr="goodreads-books-bot@example.com";lr(rr,nr).then(async e=>{try{let t=e.rss.channel.item.slice(0,sr),r=Je.readFileSync(B,"utf8"),n=fr(r,t);r!==n&&(p.info(`Writing to ${B}`),p.startGroup("New books found for update"),t.forEach(i=>p.info(JSON.stringify(i))),p.endGroup(),Je.writeFileSync(B,n),ir?(p.setOutput("books",t),p.info("OUTPUT_ONLY: set `results` variable. Readme not committed.")):await dr())}catch(t){p.error(t),process.exit(1)}}).then(()=>{process.exit(0)}).catch(e=>{p.error(e),process.exit(1)});function lr(e,t){return new Promise((r,n)=>{er.request({host:"www.goodreads.com",path:`/review/list_rss/${e}?shelf=${t}`},i=>{let s="";i.on("data",a=>s+=a),i.on("end",()=>r(tr.parse(s))),i.on("error",a=>n(a))}).end()})}function fr(e,t){let r=p.getInput("comment_tag_name")||"GOODREADS-LIST",n=``,i=``;if(![n,i].every(a=>e.match(new RegExp(a,"gm"))))p.error(`Cannot find the required comment tags (${n} and ${i}) to inject book titles.`),process.exit(1);else{let a=e.indexOf(n),o=e.indexOf(i),u=hr(t);return[e.substring(0,a+n.length),` `,u,` -`,e.substring(o)].join("")}}function dr(e){return e.map(t=>`- [${t.title}](${t.link}) by ${t.author_name}`).join(` -`)}async function fr(){await V("git",["config","--global","user.email",ar]),await V("git",["config","--global","user.name",ur]),await V("git",["add",x]),await V("git",["commit","-m",or]),await V("git",["push"]),p.info("Readme updated successfully in the upstream repository"),process.exit(0)} +`,e.substring(o)].join("")}}function hr(e){return e.map(t=>gr(or,{title:t.title,url:t.link,author:t.author_name,published_year:t.book_published,average_rating:t.average_rating,my_rating:t.user_rating,my_rating_stars:t.user_rating?"\u2B50".repeat(Number.parseInt(t.user_rating||"0")):"unrated"})).join(` +`)}function gr(e,t){let r=/\$([a-zA-Z_]*)/g;return e.replace(r,(n,i)=>t[i]||"")}async function dr(){await V("git",["config","--global","user.email",cr]),await V("git",["config","--global","user.name",ar]),await V("git",["add",B]),await V("git",["commit","-m",ur]),await V("git",["push"]),p.info("Readme updated successfully in the upstream repository"),process.exit(0)} diff --git a/index.js b/index.js index 5573fb3..b024300 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,7 @@ const SHELF = core.getInput("shelf"); const MAX_BOOKS_COUNT = Number.parseInt(core.getInput("max_books_count")); const README_FILE_PATH = core.getInput("readme_file_path"); const OUTPUT_ONLY = core.getInput("output_only").toLowerCase() === "true"; +const TEMPLATE = core.getInput("template") || "- [$title]($url) by $author (⭐️$average_rating)"; const COMMIT_MESSAGE = "Synced and updated with user's goodreads book lists"; const COMMITTER_USERNAME = "goodreads-books-bot"; const COMMITTER_EMAIL = "goodreads-books-bot@example.com"; @@ -102,10 +103,27 @@ function buildReadme(template, books) { function buildBookList(books) { return books - .map((book) => `- [${book.title}](${book.link}) by ${book.author_name}`) + .map((book) => { + return template(TEMPLATE, { + title: book.title, + url: book.link, + author: book.author_name, + published_year: book.book_published, + average_rating: book.average_rating, + my_rating: book.user_rating, + my_rating_stars: book.user_rating + ? "⭐".repeat(Number.parseInt(book.user_rating || "0")) + : "unrated", + }); + }) .join(`\n`); } +function template(template, variables) { + const regex = /\$([a-zA-Z_]*)/g; + return template.replace(regex, (match, content) => variables[content] || ""); +} + async function commitReadme() { // Doing commit and push await exec("git", ["config", "--global", "user.email", COMMITTER_EMAIL]); diff --git a/local-run.js b/local-run.js index 4c43b24..cf36dcc 100644 --- a/local-run.js +++ b/local-run.js @@ -19,8 +19,9 @@ fs.writeFile(path.join(__dirname, "test", "README.md"), template, () => { process.env.INPUT_MAX_BOOKS_COUNT = "10"; process.env.INPUT_README_FILE_PATH = "./test/README.md";; process.env.INPUT_OUTPUT_ONLY = "true"; + process.env.INPUT_TEMPLATE = "- [$title]($url) by $author (⭐️$average_rating)"; const testFile = process.env.DIST ? "./dist/index.js" : "./index.js"; - console.log("Testing: ", testFile); + // console.log("Testing: ", testFile); require(testFile); });