diff --git a/README.md b/README.md index 5e3a6f7..865f3a2 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Creates a comment inside Pull Request with the human-readable summary of the cha | Input | Required | Default | Description | | --- | :---: | :---: | --- | +| `collapsibleThreshold` | No | `'25'` | Number of lock changes, which will result in collapsed comment content an addition of summary table. | | `path` | No | `'yarn.lock'` | Path to the `yarn.lock` file in the repository. Default value points to the file at project root. | | `token` | **Yes** | - | GitHub token for the bot, so it can publish a comment in the pull request. | | `updateComment` | No | `'true'` | Should the bot update the summary comment. If value is other than default, bot will post new comment on each new commit. | diff --git a/action.js b/action.js index cce4314..5e2b776 100644 --- a/action.js +++ b/action.js @@ -14,7 +14,7 @@ const COMMENT_HEADER = '## `yarn.lock` changes'; const getStatusLabel = (status) => `[${status.toUpperCase()}](#)`; -const formatNameAndVersion = (obj) => +const formatEntry = (obj) => Object.fromEntries( Object.keys(obj.object).map((key) => { const nameParts = key.split('@'); @@ -25,14 +25,14 @@ const formatNameAndVersion = (obj) => const diffLocks = (previous, current) => { const changes = {}; - const previousPackages = formatNameAndVersion(previous); - const currentPackages = formatNameAndVersion(current); + const previousPackages = formatEntry(previous); + const currentPackages = formatEntry(current); Object.keys(previousPackages).forEach((key) => { changes[key] = { previous: previousPackages[key].version, current: '-', - status: getStatusLabel('removed') + status: 'removed' }; }); @@ -41,7 +41,7 @@ const diffLocks = (previous, current) => { changes[key] = { previous: '-', current: currentPackages[key].version, - status: getStatusLabel('added') + status: 'added' }; } else { if (changes[key].previous === currentPackages[key].version) { @@ -49,9 +49,9 @@ const diffLocks = (previous, current) => { } else { changes[key].current = currentPackages[key].version; if (compareVersions(changes[key].previous, changes[key].current) === 1) { - changes[key].status = getStatusLabel('downgraded'); + changes[key].status = 'downgraded'; } else { - changes[key].status = getStatusLabel('updated'); + changes[key].status = 'updated'; } } } @@ -65,17 +65,43 @@ const createTable = (lockChanges) => [ ['Name', 'Status', 'Previous', 'Current'], ...Object.entries(lockChanges) - .map(([key, { status, previous, current }]) => ['`' + key + '`', status, previous, current]) + .map(([key, { status, previous, current }]) => [ + '`' + key + '`', + getStatusLabel(status), + previous, + current + ]) .sort((a, b) => a[0].localeCompare(b[0])) ], { align: ['l', 'c', 'c', 'c'], alignDelimiters: false } ); +const countStatuses = (lockChanges, statusToCount) => + Object.values(lockChanges).filter(({ status }) => status === statusToCount).length; + +const createSummaryRow = (lockChanges, status) => { + const statusCount = countStatuses(lockChanges, status); + return statusCount ? [getStatusLabel(status), statusCount] : undefined; +}; + +const createSummary = (lockChanges) => + markdownTable( + [ + ['Status', 'Count'], + createSummaryRow(lockChanges, 'added'), + createSummaryRow(lockChanges, 'updated'), + createSummaryRow(lockChanges, 'downgraded'), + createSummaryRow(lockChanges, 'removed') + ].filter(Boolean), + { align: ['l', 'c'], alignDelimiters: false } + ); + const run = async () => { try { const octokit = github.getOctokit(core.getInput('token')); const inputPath = core.getInput('path'); const updateComment = core.getInput('updateComment'); + const collapsibleThreshold = parseInt(core.getInput('collapsibleThreshold')); const { owner, repo, number } = github.context.issue; @@ -104,10 +130,26 @@ const run = async () => { const masterLock = lockfile.parse(Base64.decode(masterLockResponse.data.content)); const lockChanges = diffLocks(masterLock, updatedLock); + const lockChangesCount = Object.keys(lockChanges).length; - if (Object.keys(lockChanges).length) { + if (lockChangesCount) { const diffsTable = createTable(lockChanges); - const commentBody = COMMENT_HEADER + '\n' + diffsTable; + const collapsed = lockChangesCount >= collapsibleThreshold; + + const changesSummary = collapsed ? '### Summary\n' + createSummary(lockChanges) : ''; + + const commentBody = + COMMENT_HEADER + + '\n' + + changesSummary + + '\n' + + '\n' + + 'Click to toggle table visibility\n
\n\n' + + diffsTable + + '\n\n' + + ''; if (updateComment === 'true') { const currentComments = await octokit.issues.listComments({ diff --git a/action.yml b/action.yml index 50fbd45..182d3e9 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,10 @@ branding: icon: 'copy' color: 'purple' inputs: + collapsibleThreshold: + description: 'Number of lock changes, which will result in collapsed comment content an addition of summary table.' + required: false + default: '25' path: description: 'Path to the `yarn.lock` file in the repository. Default value points to the file at project root.' required: false diff --git a/dist/index.js b/dist/index.js index 2fcc310..8c30102 100644 --- a/dist/index.js +++ b/dist/index.js @@ -10,4 +10,4 @@ * * Copyright (c) 2014-2015, Jon Schlinkert. * Licensed under the MIT License. - */var t="";var r;e.exports=repeat;function repeat(e,n){if(typeof e!=="string"){throw new TypeError("expected a string")}if(n===1)return e;if(n===2)return e+e;var o=e.length*n;if(r!==e||typeof r==="undefined"){r=e;t=""}else if(t.length>=o){return t.substr(0,o)}while(o>t.length&&n>1){if(n&1){t+=e}n>>=1;e+=e}t+=e;t=t.substr(0,o);return t}},2083:(e,t,r)=>{e.exports=r(8203)},8203:(e,t,r)=>{"use strict";var n=r(1631);var o=r(4016);var s=r(8605);var i=r(7211);var a=r(8614);var c=r(2357);var u=r(1669);t.httpOverHttp=httpOverHttp;t.httpsOverHttp=httpsOverHttp;t.httpOverHttps=httpOverHttps;t.httpsOverHttps=httpsOverHttps;function httpOverHttp(e){var t=new TunnelingAgent(e);t.request=s.request;return t}function httpsOverHttp(e){var t=new TunnelingAgent(e);t.request=s.request;t.createSocket=createSecureSocket;t.defaultPort=443;return t}function httpOverHttps(e){var t=new TunnelingAgent(e);t.request=i.request;return t}function httpsOverHttps(e){var t=new TunnelingAgent(e);t.request=i.request;t.createSocket=createSecureSocket;t.defaultPort=443;return t}function TunnelingAgent(e){var t=this;t.options=e||{};t.proxyOptions=t.options.proxy||{};t.maxSockets=t.options.maxSockets||s.Agent.defaultMaxSockets;t.requests=[];t.sockets=[];t.on("free",(function onFree(e,r,n,o){var s=toOptions(r,n,o);for(var i=0,a=t.requests.length;i=this.maxSockets){o.requests.push(s);return}o.createSocket(s,(function(t){t.on("free",onFree);t.on("close",onCloseOrRemove);t.on("agentRemove",onCloseOrRemove);e.onSocket(t);function onFree(){o.emit("free",t,s)}function onCloseOrRemove(e){o.removeSocket(t);t.removeListener("free",onFree);t.removeListener("close",onCloseOrRemove);t.removeListener("agentRemove",onCloseOrRemove)}}))};TunnelingAgent.prototype.createSocket=function createSocket(e,t){var r=this;var n={};r.sockets.push(n);var o=mergeOptions({},r.proxyOptions,{method:"CONNECT",path:e.host+":"+e.port,agent:false,headers:{host:e.host+":"+e.port}});if(e.localAddress){o.localAddress=e.localAddress}if(o.proxyAuth){o.headers=o.headers||{};o.headers["Proxy-Authorization"]="Basic "+new Buffer(o.proxyAuth).toString("base64")}l("making CONNECT request");var s=r.request(o);s.useChunkedEncodingByDefault=false;s.once("response",onResponse);s.once("upgrade",onUpgrade);s.once("connect",onConnect);s.once("error",onError);s.end();function onResponse(e){e.upgrade=true}function onUpgrade(e,t,r){process.nextTick((function(){onConnect(e,t,r)}))}function onConnect(o,i,a){s.removeAllListeners();i.removeAllListeners();if(o.statusCode!==200){l("tunneling socket could not be established, statusCode=%d",o.statusCode);i.destroy();var c=new Error("tunneling socket could not be established, "+"statusCode="+o.statusCode);c.code="ECONNRESET";e.request.emit("error",c);r.removeSocket(n);return}if(a.length>0){l("got illegal response body from proxy");i.destroy();var c=new Error("got illegal response body from proxy");c.code="ECONNRESET";e.request.emit("error",c);r.removeSocket(n);return}l("tunneling connection has established");r.sockets[r.sockets.indexOf(n)]=i;return t(i)}function onError(t){s.removeAllListeners();l("tunneling socket could not be established, cause=%s\n",t.message,t.stack);var o=new Error("tunneling socket could not be established, "+"cause="+t.message);o.code="ECONNRESET";e.request.emit("error",o);r.removeSocket(n)}};TunnelingAgent.prototype.removeSocket=function removeSocket(e){var t=this.sockets.indexOf(e);if(t===-1){return}this.sockets.splice(t,1);var r=this.requests.shift();if(r){this.createSocket(r,(function(e){r.request.onSocket(e)}))}};function createSecureSocket(e,t){var r=this;TunnelingAgent.prototype.createSocket.call(r,e,(function(n){var s=e.request.getHeader("host");var i=mergeOptions({},r.options,{socket:n,servername:s?s.replace(/:.*$/,""):e.host});var a=o.connect(0,i);r.sockets[r.sockets.indexOf(n)]=a;t(a)}))}function toOptions(e,t,r){if(typeof e==="string"){return{host:e,port:t,localAddress:r}}return e}function mergeOptions(e){for(var t=1,r=arguments.length;t{"use strict";Object.defineProperty(t,"__esModule",{value:true});function getUserAgent(){if(typeof navigator==="object"&&"userAgent"in navigator){return navigator.userAgent}if(typeof process==="object"&&"version"in process){return`Node.js/${process.version.substr(1)} (${process.platform}; ${process.arch})`}return""}t.getUserAgent=getUserAgent},5488:e=>{e.exports=wrappy;function wrappy(e,t){if(e&&t)return wrappy(e)(t);if(typeof e!=="function")throw new TypeError("need wrapper function");Object.keys(e).forEach((function(t){wrapper[t]=e[t]}));return wrapper;function wrapper(){var t=new Array(arguments.length);for(var r=0;r{module.exports=eval("require")("encoding")},2357:e=>{"use strict";e.exports=require("assert")},4293:e=>{"use strict";e.exports=require("buffer")},6417:e=>{"use strict";e.exports=require("crypto")},8614:e=>{"use strict";e.exports=require("events")},5747:e=>{"use strict";e.exports=require("fs")},8605:e=>{"use strict";e.exports=require("http")},7211:e=>{"use strict";e.exports=require("https")},1631:e=>{"use strict";e.exports=require("net")},2087:e=>{"use strict";e.exports=require("os")},5622:e=>{"use strict";e.exports=require("path")},2413:e=>{"use strict";e.exports=require("stream")},4016:e=>{"use strict";e.exports=require("tls")},3867:e=>{"use strict";e.exports=require("tty")},8835:e=>{"use strict";e.exports=require("url")},1669:e=>{"use strict";e.exports=require("util")},8761:e=>{"use strict";e.exports=require("zlib")}};var __webpack_module_cache__={};function __nccwpck_require__(e){var t=__webpack_module_cache__[e];if(t!==undefined){return t.exports}var r=__webpack_module_cache__[e]={exports:{}};var n=true;try{__webpack_modules__[e].call(r.exports,r,r.exports,__nccwpck_require__);n=false}finally{if(n)delete __webpack_module_cache__[e]}return r.exports}(()=>{__nccwpck_require__.d=(e,t)=>{for(var r in t){if(__nccwpck_require__.o(t,r)&&!__nccwpck_require__.o(e,r)){Object.defineProperty(e,r,{enumerable:true,get:t[r]})}}}})();(()=>{__nccwpck_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})();(()=>{__nccwpck_require__.r=e=>{if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(e,"__esModule",{value:true})}})();if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var __webpack_exports__={};(()=>{const e=__nccwpck_require__(7090);const t=__nccwpck_require__(6993);const r=__nccwpck_require__(4705);const n=__nccwpck_require__(9035);const o=__nccwpck_require__(5747);const{Base64:s}=__nccwpck_require__(9990);const{markdownTable:i}=__nccwpck_require__(3852);const a=__nccwpck_require__(5622);const c="https://raw.githubusercontent.com";const u=`${c}/Simek/yarn-lock-changes/main/assets`;const l="## `yarn.lock` changes";const getStatusLabel=e=>`[${e.toUpperCase()}](#)`;const formatNameAndVersion=e=>Object.fromEntries(Object.keys(e.object).map((t=>{const r=t.split("@");const n=r[0]===""?"@"+r[1]:r[0];return[n,{name:n,version:e.object[t].version}]})));const diffLocks=(e,t)=>{const r={};const o=formatNameAndVersion(e);const s=formatNameAndVersion(t);Object.keys(o).forEach((e=>{r[e]={previous:o[e].version,current:"-",status:getStatusLabel("removed")}}));Object.keys(s).forEach((e=>{if(!r[e]){r[e]={previous:"-",current:s[e].version,status:getStatusLabel("added")}}else{if(r[e].previous===s[e].version){delete r[e]}else{r[e].current=s[e].version;if(n(r[e].previous,r[e].current)===1){r[e].status=getStatusLabel("downgraded")}else{r[e].status=getStatusLabel("updated")}}}}));return r};const createTable=e=>i([["Name","Status","Previous","Current"],...Object.entries(e).map((([e,{status:t,previous:r,current:n}])=>["`"+e+"`",t,r,n])).sort(((e,t)=>e[0].localeCompare(t[0])))],{align:["l","c","c","c"],alignDelimiters:false});const run=async()=>{try{const n=t.getOctokit(e.getInput("token"));const i=e.getInput("path");const c=e.getInput("updateComment");const{owner:u,repo:p,number:d}=t.context.issue;if(!d){throw new Error("💥 Cannot find the PR, aborting!")}const h=a.resolve(process.cwd(),i);if(!o.existsSync(h)){throw new Error("💥 It looks like lock does not exist in this PR, aborting!")}const m=await o.readFileSync(h,{encoding:"utf8"});const g=r.parse(m);const v=await n.request("GET /repos/{owner}/{repo}/contents/{path}",{owner:u,repo:p,path:i});if(!v||!v.data||!v.data.content){throw new Error("💥 Cannot fetch base lock, aborting!")}const y=r.parse(s.decode(v.data.content));const b=diffLocks(y,g);if(Object.keys(b).length){const e=createTable(b);const t=l+"\n"+e;if(c==="true"){const e=await n.issues.listComments({owner:u,repo:p,issue_number:d,per_page:100});if(!e||!e.data){throw new Error("💥 Cannot fetch PR comments, aborting!")}const r=e.data.filter((e=>e.user.login==="github-actions[bot]"&&e.body.startsWith(l))).map((e=>e.id))[0];if(r){await n.issues.updateComment({owner:u,repo:p,comment_id:r,body:t})}else{await n.issues.createComment({owner:u,repo:p,issue_number:d,body:t})}}else{await n.issues.createComment({owner:u,repo:p,issue_number:d,body:t})}}}catch(t){e.setFailed(t.message)}};run()})();module.exports=__webpack_exports__})(); \ No newline at end of file + */var t="";var r;e.exports=repeat;function repeat(e,n){if(typeof e!=="string"){throw new TypeError("expected a string")}if(n===1)return e;if(n===2)return e+e;var o=e.length*n;if(r!==e||typeof r==="undefined"){r=e;t=""}else if(t.length>=o){return t.substr(0,o)}while(o>t.length&&n>1){if(n&1){t+=e}n>>=1;e+=e}t+=e;t=t.substr(0,o);return t}},2083:(e,t,r)=>{e.exports=r(8203)},8203:(e,t,r)=>{"use strict";var n=r(1631);var o=r(4016);var s=r(8605);var i=r(7211);var a=r(8614);var c=r(2357);var u=r(1669);t.httpOverHttp=httpOverHttp;t.httpsOverHttp=httpsOverHttp;t.httpOverHttps=httpOverHttps;t.httpsOverHttps=httpsOverHttps;function httpOverHttp(e){var t=new TunnelingAgent(e);t.request=s.request;return t}function httpsOverHttp(e){var t=new TunnelingAgent(e);t.request=s.request;t.createSocket=createSecureSocket;t.defaultPort=443;return t}function httpOverHttps(e){var t=new TunnelingAgent(e);t.request=i.request;return t}function httpsOverHttps(e){var t=new TunnelingAgent(e);t.request=i.request;t.createSocket=createSecureSocket;t.defaultPort=443;return t}function TunnelingAgent(e){var t=this;t.options=e||{};t.proxyOptions=t.options.proxy||{};t.maxSockets=t.options.maxSockets||s.Agent.defaultMaxSockets;t.requests=[];t.sockets=[];t.on("free",(function onFree(e,r,n,o){var s=toOptions(r,n,o);for(var i=0,a=t.requests.length;i=this.maxSockets){o.requests.push(s);return}o.createSocket(s,(function(t){t.on("free",onFree);t.on("close",onCloseOrRemove);t.on("agentRemove",onCloseOrRemove);e.onSocket(t);function onFree(){o.emit("free",t,s)}function onCloseOrRemove(e){o.removeSocket(t);t.removeListener("free",onFree);t.removeListener("close",onCloseOrRemove);t.removeListener("agentRemove",onCloseOrRemove)}}))};TunnelingAgent.prototype.createSocket=function createSocket(e,t){var r=this;var n={};r.sockets.push(n);var o=mergeOptions({},r.proxyOptions,{method:"CONNECT",path:e.host+":"+e.port,agent:false,headers:{host:e.host+":"+e.port}});if(e.localAddress){o.localAddress=e.localAddress}if(o.proxyAuth){o.headers=o.headers||{};o.headers["Proxy-Authorization"]="Basic "+new Buffer(o.proxyAuth).toString("base64")}l("making CONNECT request");var s=r.request(o);s.useChunkedEncodingByDefault=false;s.once("response",onResponse);s.once("upgrade",onUpgrade);s.once("connect",onConnect);s.once("error",onError);s.end();function onResponse(e){e.upgrade=true}function onUpgrade(e,t,r){process.nextTick((function(){onConnect(e,t,r)}))}function onConnect(o,i,a){s.removeAllListeners();i.removeAllListeners();if(o.statusCode!==200){l("tunneling socket could not be established, statusCode=%d",o.statusCode);i.destroy();var c=new Error("tunneling socket could not be established, "+"statusCode="+o.statusCode);c.code="ECONNRESET";e.request.emit("error",c);r.removeSocket(n);return}if(a.length>0){l("got illegal response body from proxy");i.destroy();var c=new Error("got illegal response body from proxy");c.code="ECONNRESET";e.request.emit("error",c);r.removeSocket(n);return}l("tunneling connection has established");r.sockets[r.sockets.indexOf(n)]=i;return t(i)}function onError(t){s.removeAllListeners();l("tunneling socket could not be established, cause=%s\n",t.message,t.stack);var o=new Error("tunneling socket could not be established, "+"cause="+t.message);o.code="ECONNRESET";e.request.emit("error",o);r.removeSocket(n)}};TunnelingAgent.prototype.removeSocket=function removeSocket(e){var t=this.sockets.indexOf(e);if(t===-1){return}this.sockets.splice(t,1);var r=this.requests.shift();if(r){this.createSocket(r,(function(e){r.request.onSocket(e)}))}};function createSecureSocket(e,t){var r=this;TunnelingAgent.prototype.createSocket.call(r,e,(function(n){var s=e.request.getHeader("host");var i=mergeOptions({},r.options,{socket:n,servername:s?s.replace(/:.*$/,""):e.host});var a=o.connect(0,i);r.sockets[r.sockets.indexOf(n)]=a;t(a)}))}function toOptions(e,t,r){if(typeof e==="string"){return{host:e,port:t,localAddress:r}}return e}function mergeOptions(e){for(var t=1,r=arguments.length;t{"use strict";Object.defineProperty(t,"__esModule",{value:true});function getUserAgent(){if(typeof navigator==="object"&&"userAgent"in navigator){return navigator.userAgent}if(typeof process==="object"&&"version"in process){return`Node.js/${process.version.substr(1)} (${process.platform}; ${process.arch})`}return""}t.getUserAgent=getUserAgent},5488:e=>{e.exports=wrappy;function wrappy(e,t){if(e&&t)return wrappy(e)(t);if(typeof e!=="function")throw new TypeError("need wrapper function");Object.keys(e).forEach((function(t){wrapper[t]=e[t]}));return wrapper;function wrapper(){var t=new Array(arguments.length);for(var r=0;r{module.exports=eval("require")("encoding")},2357:e=>{"use strict";e.exports=require("assert")},4293:e=>{"use strict";e.exports=require("buffer")},6417:e=>{"use strict";e.exports=require("crypto")},8614:e=>{"use strict";e.exports=require("events")},5747:e=>{"use strict";e.exports=require("fs")},8605:e=>{"use strict";e.exports=require("http")},7211:e=>{"use strict";e.exports=require("https")},1631:e=>{"use strict";e.exports=require("net")},2087:e=>{"use strict";e.exports=require("os")},5622:e=>{"use strict";e.exports=require("path")},2413:e=>{"use strict";e.exports=require("stream")},4016:e=>{"use strict";e.exports=require("tls")},3867:e=>{"use strict";e.exports=require("tty")},8835:e=>{"use strict";e.exports=require("url")},1669:e=>{"use strict";e.exports=require("util")},8761:e=>{"use strict";e.exports=require("zlib")}};var __webpack_module_cache__={};function __nccwpck_require__(e){var t=__webpack_module_cache__[e];if(t!==undefined){return t.exports}var r=__webpack_module_cache__[e]={exports:{}};var n=true;try{__webpack_modules__[e].call(r.exports,r,r.exports,__nccwpck_require__);n=false}finally{if(n)delete __webpack_module_cache__[e]}return r.exports}(()=>{__nccwpck_require__.d=(e,t)=>{for(var r in t){if(__nccwpck_require__.o(t,r)&&!__nccwpck_require__.o(e,r)){Object.defineProperty(e,r,{enumerable:true,get:t[r]})}}}})();(()=>{__nccwpck_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})();(()=>{__nccwpck_require__.r=e=>{if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(e,"__esModule",{value:true})}})();if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var __webpack_exports__={};(()=>{const e=__nccwpck_require__(7090);const t=__nccwpck_require__(6993);const r=__nccwpck_require__(4705);const n=__nccwpck_require__(9035);const o=__nccwpck_require__(5747);const{Base64:s}=__nccwpck_require__(9990);const{markdownTable:i}=__nccwpck_require__(3852);const a=__nccwpck_require__(5622);const c="https://raw.githubusercontent.com";const u=`${c}/Simek/yarn-lock-changes/main/assets`;const l="## `yarn.lock` changes";const getStatusLabel=e=>`[${e.toUpperCase()}](#)`;const formatEntry=e=>Object.fromEntries(Object.keys(e.object).map((t=>{const r=t.split("@");const n=r[0]===""?"@"+r[1]:r[0];return[n,{name:n,version:e.object[t].version}]})));const diffLocks=(e,t)=>{const r={};const o=formatEntry(e);const s=formatEntry(t);Object.keys(o).forEach((e=>{r[e]={previous:o[e].version,current:"-",status:"removed"}}));Object.keys(s).forEach((e=>{if(!r[e]){r[e]={previous:"-",current:s[e].version,status:"added"}}else{if(r[e].previous===s[e].version){delete r[e]}else{r[e].current=s[e].version;if(n(r[e].previous,r[e].current)===1){r[e].status="downgraded"}else{r[e].status="updated"}}}}));return r};const createTable=e=>i([["Name","Status","Previous","Current"],...Object.entries(e).map((([e,{status:t,previous:r,current:n}])=>["`"+e+"`",getStatusLabel(t),r,n])).sort(((e,t)=>e[0].localeCompare(t[0])))],{align:["l","c","c","c"],alignDelimiters:false});const countStatuses=(e,t)=>Object.values(e).filter((({status:e})=>e===t)).length;const createSummaryRow=(e,t)=>{const r=countStatuses(e,t);return r?[getStatusLabel(t),r]:undefined};const createSummary=e=>i([["Status","Count"],createSummaryRow(e,"added"),createSummaryRow(e,"updated"),createSummaryRow(e,"downgraded"),createSummaryRow(e,"removed")].filter(Boolean),{align:["l","c"],alignDelimiters:false});const run=async()=>{try{const n=t.getOctokit(e.getInput("token"));const i=e.getInput("path");const c=e.getInput("updateComment");const u=parseInt(e.getInput("collapsibleThreshold"));const{owner:p,repo:d,number:h}=t.context.issue;if(!h){throw new Error("💥 Cannot find the PR, aborting!")}const m=a.resolve(process.cwd(),i);if(!o.existsSync(m)){throw new Error("💥 It looks like lock does not exist in this PR, aborting!")}const g=await o.readFileSync(m,{encoding:"utf8"});const v=r.parse(g);const y=await n.request("GET /repos/{owner}/{repo}/contents/{path}",{owner:p,repo:d,path:i});if(!y||!y.data||!y.data.content){throw new Error("💥 Cannot fetch base lock, aborting!")}const b=r.parse(s.decode(y.data.content));const _=diffLocks(b,v);const E=Object.keys(_).length;if(E){const e=createTable(_);const t=E>=u;const r=t?"### Summary\n"+createSummary(_):"";const o=l+"\n"+r+"\n"+"\n"+"Click to toggle table visibility\n
\n\n"+e+"\n\n"+"";if(c==="true"){const e=await n.issues.listComments({owner:p,repo:d,issue_number:h,per_page:100});if(!e||!e.data){throw new Error("💥 Cannot fetch PR comments, aborting!")}const t=e.data.filter((e=>e.user.login==="github-actions[bot]"&&e.body.startsWith(l))).map((e=>e.id))[0];if(t){await n.issues.updateComment({owner:p,repo:d,comment_id:t,body:o})}else{await n.issues.createComment({owner:p,repo:d,issue_number:h,body:o})}}else{await n.issues.createComment({owner:p,repo:d,issue_number:h,body:o})}}}catch(t){e.setFailed(t.message)}};run()})();module.exports=__webpack_exports__})(); \ No newline at end of file