// @bun
import{B as _,F as $}from"./chunk-hggcmr0j.js";import g from"process";function V(x){let q=x.replace(/\\/g,"/");return q.includes(".github/workflows/")&&(q.endsWith(".yml")||q.endsWith(".yaml"))}async function M(x,q){try{if(!V(x))return null;let E=[],j=q.split(`
`);for(let J=0;J<j.length;J++){let L=j[J].trim().match(/^-?\s*uses:\s*(.+)/);if(L){let Q=L[1].trim().replace(/['"`]/g,"");if(Q.startsWith("./")||Q.startsWith("docker://"))continue;let W=Q.split("@");if(W.length===2){let[S,Y]=W;if(!S||!S.trim())continue;let Z=Y.split("#")[0].trim(),T={name:S.trim(),currentVersion:Z,type:"github-actions",file:x};if(!E.find((X)=>X.name===T.name&&X.currentVersion===T.currentVersion))E.push(T)}}}return{path:x,type:"github-actions",content:q,dependencies:E}}catch(E){return console.warn(`Failed to parse GitHub Actions file ${x}:`,E),null}}async function O(x,q,E){try{if(!V(x))return q;let j=q;for(let J of E){let I=J.name.replace(/\s*\(.*\)$/,""),K=new RegExp(`((?:^\\s*-\\s*)?uses:\\s*["']?)(${I.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})@(${J.currentVersion.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})(["']?)`,"gm");j=j.replace(K,`$1$2@${J.newVersion}$4`)}return j}catch(j){return console.warn(`Failed to update GitHub Actions file ${x}:`,j),q}}async function v(x){let q=[],E=new Map;for(let j of x)if(V(j.file)){if(!E.has(j.file))E.set(j.file,[]);E.get(j.file).push(j)}for(let[j,J]of E)try{let I=await import("fs");if(I.existsSync(j)){let K=I.readFileSync(j,"utf-8"),L=await O(j,K,J);q.push({path:j,content:L,type:"update"})}}catch(I){console.warn(`Failed to generate updates for GitHub Actions file ${j}:`,I)}return q}async function z(x){try{if(!x.includes("/"))return null;let[q,E]=x.split("/"),j={Accept:"application/vnd.github.v3+json","User-Agent":"buddy-bot"},J=g.env.GITHUB_TOKEN;if(J)j.Authorization=`Bearer ${J}`;let I=await fetch(`https://api.github.com/repos/${q}/${E}/releases/latest`,{headers:j});if(!I.ok){if(I.status!==403)console.warn(`GitHub API error for ${x}: ${I.status} ${I.statusText}`);return null}return(await I.json()).tag_name||null}catch(q){return console.warn(`Failed to fetch latest version for ${x}:`,q),null}}export{O as updateGitHubActionsFile,M as parseGitHubActionsFile,V as isGitHubActionsFile,v as generateGitHubActionsUpdates,z as fetchLatestActionVersion};
export{V as z,M as A};
