UNPKG

buddy-bot

Version:

Automated & optimized dependency updates for JavaScript & TypeScript projects. Like Renovate & Dependabot.

7 lines (5 loc) 3.96 kB
// @bun import{D as z,H as D}from"./chunk-cmr43ay2.js";import T from"process";function S(I){let q=I.replace(/\\/g,"/");return q.includes(".github/workflows/")&&(q.endsWith(".yml")||q.endsWith(".yaml"))}async function y(I,q){try{if(!S(I))return null;let E=[],j=q.split(` `);for(let L=0;L<j.length;L++){let W=j[L].trim().match(/^-?\s*uses:\s*(.+)/);if(W){let K=W[1].trim().replace(/['"`]/g,"");if(K.startsWith("./")||K.startsWith("docker://"))continue;let Q=K.split("@");if(Q.length===2){let[J,X]=Q;if(!J||!J.trim())continue;let Z=X.split("#")[0].trim(),Y={name:J.trim(),currentVersion:Z,type:"github-actions",file:I};if(!E.find((_)=>_.name===Y.name&&_.currentVersion===Y.currentVersion))E.push(Y)}}}return{path:I,type:"github-actions",content:q,dependencies:E}}catch(E){return console.warn(`Failed to parse GitHub Actions file ${I}:`,E),null}}async function U(I,q,E){try{if(!S(I))return q;let j=q;for(let L of E){let O=L.name.replace(/\s*\(.*\)$/,""),V=new RegExp(`((?:^\\s*-\\s*)?uses:\\s*["']?)(${O.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})@(${L.currentVersion.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})(["']?)`,"gm");j=j.replace(V,`$1$2@${L.newVersion}$4`)}return j}catch(j){return console.warn(`Failed to update GitHub Actions file ${I}:`,j),q}}async function B(I){let q=[],E=new Map;for(let j of I)if(S(j.file)){if(!E.has(j.file))E.set(j.file,[]);E.get(j.file).push(j)}for(let[j,L]of E)try{let O=await import("fs");if(O.existsSync(j)){let V=O.readFileSync(j,"utf-8"),W=await U(j,V,L);q.push({path:j,content:W,type:"update"})}}catch(O){console.warn(`Failed to generate updates for GitHub Actions file ${j}:`,O)}return q}async function G(I){try{if(!I.includes("/"))return console.log(`\u26A0\uFE0F Invalid action name format: ${I}`),null;let[q,E]=I.split("/");console.log(`\uD83D\uDD0D Fetching latest version for ${q}/${E}`);let j={Accept:"application/vnd.github.v3+json","User-Agent":"buddy-bot"},L=T.env.GITHUB_TOKEN;if(L)j.Authorization=`Bearer ${L}`;console.log(`\uD83D\uDCE1 Trying latest release for ${q}/${E}`);let O=await fetch(`https://api.github.com/repos/${q}/${E}/releases/latest`,{headers:j});if(O.ok){let K=await O.json();if(K.tag_name)return console.log(`\u2705 Found latest release: ${K.tag_name}`),K.tag_name}else console.log(`\u26A0\uFE0F Latest release not found: ${O.status} ${O.statusText}`);console.log(`\uD83D\uDCE1 Trying all releases for ${q}/${E}`);let V=await fetch(`https://api.github.com/repos/${q}/${E}/releases?per_page=10`,{headers:j});if(V.ok){let K=await V.json();console.log(`\uD83D\uDCCB Found ${K.length} releases`);let Q=K.filter((J)=>J.tag_name&&!J.tag_name.includes("-")).sort((J,X)=>{let Z=J.published_at?new Date(J.published_at).getTime():0;return(X.published_at?new Date(X.published_at).getTime():0)-Z});if(Q.length>0)return console.log(`\u2705 Found latest stable release: ${Q[0].tag_name}`),Q[0].tag_name||null}else console.log(`\u26A0\uFE0F Releases not found: ${V.status} ${V.statusText}`);console.log(`\uD83D\uDCE1 Trying tags for ${q}/${E}`);let W=await fetch(`https://api.github.com/repos/${q}/${E}/tags?per_page=10`,{headers:j});if(W.ok){let K=await W.json();console.log(`\uD83D\uDCCB Found ${K.length} tags`);let Q=K.filter((J)=>J.name&&!J.name.includes("-")).map((J)=>J.name).sort((J,X)=>{let Z=J.replace(/^v/,""),Y=X.replace(/^v/,""),x=Z.split(".").map(Number),_=Y.split(".").map(Number);for(let $=0;$<Math.max(x.length,_.length);$++){let k=x[$]||0,M=_[$]||0;if(k!==M)return M-k}return 0});if(Q.length>0)return console.log(`\u2705 Found latest stable tag: ${Q[0]}`),Q[0]}else console.log(`\u26A0\uFE0F Tags not found: ${W.status} ${W.statusText}`);return console.log(`\u274C No version found for ${I}`),null}catch(q){return console.warn(`Failed to fetch latest version for ${I}:`,q),null}}export{U as updateGitHubActionsFile,y as parseGitHubActionsFile,S as isGitHubActionsFile,B as generateGitHubActionsUpdates,G as fetchLatestActionVersion}; export{S as f,y as g}; //# debugId=DBAE493643505A6364756E2164756E21