// @bun
import{N as B,O as R}from"./chunk-nmj3neqg.js";import{Zb as q}from"./chunk-bqh4yh6g.js";async function k(J,K){try{let E=K.split("/").pop()||"";if(E==="package.json"){let O=JSON.parse(J),Q=[];return H(O.dependencies,"dependencies",K,Q),H(O.devDependencies,"devDependencies",K,Q),H(O.peerDependencies,"peerDependencies",K,Q),H(O.optionalDependencies,"optionalDependencies",K,Q),{path:K,type:"package.json",content:J,dependencies:Q}}if(B(K))return await R(K,J);if(E==="composer.json"||E==="composer.lock"){let{parseComposerFile:O}=await import("./chunk-qerc8z7c.js");return await O(K,J)}return null}catch{return null}}function H(J,K,E,O){if(!J)return;for(let[Q,X]of Object.entries(J))O.push({name:Q,currentVersion:X,type:K,file:E})}function m(J){let{existsSync:K}=q("fs"),{join:E}=q("path");if(K(E(J,"bun.lockb"))||K(E(J,"bun.lock")))return"bun";if(K(E(J,"pnpm-lock.yaml")))return"pnpm";if(K(E(J,"yarn.lock")))return"yarn";if(K(E(J,"package-lock.json")))return"npm";return"bun"}function y(J,K){if(K)return K;if(J.length===1){let X=J[0];return`chore(deps): update dependency ${X.name} to ${X.newVersion}`}let E=J.filter((X)=>X.updateType==="major"),O=J.filter((X)=>X.updateType==="minor"),Q=J.filter((X)=>X.updateType==="patch");if(E.length>0)return`chore(deps): update ${E.length} major dependencies`;else if(O.length>0)return`chore(deps): update ${O.length} minor dependencies`;else return`chore(deps): update ${Q.length} patch dependencies`}function f(J,K){if(K)return K;if(J.length===1){let O=J[0];return`chore(deps): update dependency ${O.name} to v${O.newVersion}`}let E=J.filter((O)=>O.updateType==="major");if(E.length>0)return`chore(deps): update ${E.length} major dependencies`;else return"chore(deps): update all non-major dependencies"}function L(J,K){if(K)return K;let E=`This PR contains the following updates:

`;E+=`| Package | Change | Age | Adoption | Passing | Confidence |
`,E+=`|---|---|---|---|---|---|
`;for(let Q of J){let X=`\`${Q.currentVersion}\` -> \`${Q.newVersion}\``,_=Q.metadata?.homepage?`[${Q.name}](${Q.metadata.homepage})`:Q.name;E+=`| ${_} | ${X} | [![age](https://developer.mend.io/api/mc/badges/age/npm/${Q.name}/${Q.newVersion}?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/${Q.name}/${Q.newVersion}?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/${Q.name}/${Q.currentVersion}/${Q.newVersion}?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/${Q.name}/${Q.currentVersion}/${Q.newVersion}?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
`}E+=`
---

`;let O=J.filter((Q)=>Q.releaseNotesUrl);if(O.length>0){E+=`### Release Notes

`;for(let Q of O)if(Q.releaseNotesUrl)E+=`<details>
<summary>${Q.name}</summary>

`,E+=`[Release Notes](${Q.releaseNotesUrl})

`,E+=`</details>

`}return E+=`### Configuration

`,E+=`\uD83D\uDCC5 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

`,E+=`\uD83D\uDEA6 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

`,E+=`\u267B **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

`,E+=`\uD83D\uDD15 **Ignore**: Close this PR and you won't be reminded about this update again.

`,E+=`---

`,E+=` - [ ] <!-- rebase-check -->If you want to update/retry this PR, check this box

`,E+=`---

`,E+="This PR was generated by [Buddy](https://github.com/stacksjs/buddy-bot).",E}function P(J,K="buddy"){if(J.length===1){let O=J[0],Q=O.name.replace(/[^a-z0-9-]/gi,"-");return`${K}/update-${Q}-to-${O.newVersion}`}if(J.filter((O)=>O.updateType==="major").length>0)return`${K}/update-major-dependencies`;return`${K}/update-dependencies`}function w(J){let K=new Map;for(let E of J){let O=`${E.name}:${E.currentVersion}:${E.newVersion}`,Q=K.get(O);if(!Q)K.set(O,E);else{let X=F(E.file),_=F(Q.file);if(X>_)K.set(O,E)}}return Array.from(K.values())}function F(J){if(J==="package.json")return 3;if(J.endsWith("composer.json"))return 2;if(J.includes(".github/workflows/"))return 1;return 0}function h(J){let K=[],E=w(J),O=E.filter((Y)=>Y.dependencyType==="github-actions"),Q=E.filter((Y)=>Y.dependencyType==="docker-image"),X=E.filter((Y)=>Y.dependencyType!=="github-actions"&&Y.dependencyType!=="docker-image");if(O.length>0)K.push({name:"GitHub Actions",updates:O,updateType:N(O),title:"chore(deps): update github actions",body:L(O)});if(Q.length>0)K.push({name:"Docker Images",updates:Q,updateType:N(Q),title:"chore(deps): update docker images",body:L(Q)});let _=X.filter((Y)=>Y.updateType==="major"),Z=X.filter((Y)=>Y.updateType==="minor"),G=X.filter((Y)=>Y.updateType==="patch");if(Z.length>0||G.length>0){let Y=[...Z,...G];K.push({name:"Non-Major Updates",updates:Y,updateType:Z.length>0?"minor":"patch",title:"chore(deps): update all non-major dependencies",body:L(Y)})}for(let Y of _)K.push({name:`Major Update - ${Y.name}`,updates:[Y],updateType:"major",title:`chore(deps): update dependency ${Y.name} to ${Y.newVersion}`,body:L([Y])});return K}function N(J){if(J.some((K)=>K.updateType==="major"))return"major";if(J.some((K)=>K.updateType==="minor"))return"minor";return"patch"}function g(J){let K={major:3,minor:2,patch:1};return J.sort((E,O)=>{let Q=K[E.updateType],X=K[O.updateType];if(Q!==X)return X-Q;return E.name.localeCompare(O.name)})}function u(J,K){let E=J.replace(/^[v^~>=<@]+/,""),O=K.replace(/^[v^~>=<@]+/,"");try{if(Bun.semver.order(O,E)<=0)return"patch"}catch{return"patch"}try{let Q=E.split(".").map((z)=>Number.parseInt(z,10)),X=O.split(".").map((z)=>Number.parseInt(z,10));while(Q.length<3)Q.push(0);while(X.length<3)X.push(0);let[_,Z,G]=Q,[Y,$,I]=X;if(Y>_)return"major";if(Y===_&&$>Z)return"minor";if(Y===_&&$===Z&&I>G)return"patch"}catch{try{if(Bun.semver.satisfies(O,`~${E}`))return"patch"}catch{}try{if(Bun.semver.satisfies(O,`^${E}`))return"minor"}catch{}}return"major"}function c(J,K){try{return Bun.semver.satisfies(J,K)}catch{return!1}}async function l(J,K,E){if(!J)throw Error("GitHub token is required");try{let O=await fetch(`https://api.github.com/repos/${K}/${E}/pulls?state=open`,{headers:{Authorization:`Bearer ${J}`,Accept:"application/vnd.github+json","User-Agent":"buddy-bot"}});if(!O.ok)throw Error(`GitHub API error: ${O.status} ${O.statusText}`);return(await O.json()).filter((_)=>{if(!_.body)return!1;return/\s*-\s*\[x\]\s*<!--\s*rebase-check\s*-->.*(?:rebase|update)\/retry/i.test(_.body)}).map((_)=>({number:_.number,branchName:_.head.ref}))}catch(O){throw Error(`Failed to check for rebase requests: ${O}`)}}function M(J){let K=[],E=J.match(/\|[^|]*\|[^|]*\|[^|]*\|[^|]*\|/g);if(E)for(let O of E){let Q=O.match(/\[([^\]]+)\]\([^)]*\)/);if(Q)K.push(Q[1])}return K}async function n(J,K,E){if(await x(J,K,E))return!0;if(await j(J,K,E))return!0;return!1}async function x(J,K,E){if(!(K.packages?.respectLatest??!0))return E.debug(`\uD83D\uDD0D PR #${J.number}: respectLatest is false, skipping auto-close`),!1;let Q=["latest","*","main","master","develop","dev"],X=J.body.toLowerCase();if(!Q.some(($)=>X.includes($)))return E.debug(`\uD83D\uDD0D PR #${J.number}: No dynamic versions found in PR body`),!1;E.debug(`\uD83D\uDD0D PR #${J.number}: Found dynamic versions in PR body`);let Z=M(J.body);E.debug(`\uD83D\uDD0D PR #${J.number}: Extracted packages: ${Z.join(", ")}`);let G=Z.filter(($)=>{let I=new RegExp(`\\|\\s*\\[${$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\]\\([^)]+\\)\\s*\\|\\s*([^|]+)\\s*\\|`,"i"),z=J.body.match(I);if(!z){let D=new RegExp(`${$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}[^\\w]*[:=]\\s*["']?([^"'
]+)["']?`,"i"),v=J.body.match(D);if(!v)return E.debug(`\uD83D\uDD0D PR #${J.number}: No version pattern found for package ${$}`),!1;let V=v[1].toLowerCase().trim().replace(/`/g,""),C=Q.includes(V);return E.debug(`\uD83D\uDD0D PR #${J.number}: Package ${$} has version ${V}, isDynamic: ${C}`),C}let T=z[1].trim(),W=T.match(/^([^\u2192]+)\u2192/);if(!W)return E.debug(`\uD83D\uDD0D PR #${J.number}: Could not parse version change for package ${$}: ${T}`),!1;let S=W[1].trim().toLowerCase().replace(/`/g,""),A=Q.includes(S);return E.debug(`\uD83D\uDD0D PR #${J.number}: Package ${$} has current version ${S}, isDynamic: ${A}`),A}),Y=G.length>0;return E.debug(`\uD83D\uDD0D PR #${J.number}: Packages with dynamic versions: ${G.join(", ")}`),E.debug(`\uD83D\uDD0D PR #${J.number}: Should auto-close: ${Y}`),Y}async function j(J,K,E){let O=K.packages?.ignorePaths;if(!O||O.length===0)return E.debug(`\uD83D\uDD0D PR #${J.number}: No ignorePaths configured, skipping auto-close`),!1;let Q=b(J.body);if(Q.length===0)return E.debug(`\uD83D\uDD0D PR #${J.number}: No file paths found in PR body`),!1;E.debug(`\uD83D\uDD0D PR #${J.number}: Found file paths: ${Q.join(", ")}`);let{Glob:X}=globalThis.Bun,_=Q.filter((Z)=>{let G=Z.replace(/^\.\//,"");return O.some((Y)=>{try{return new X(Y).match(G)}catch($){return E.debug(`Failed to match path ${G} against pattern ${Y}: ${$}`),!1}})});if(_.length>0)return E.debug(`\uD83D\uDD0D PR #${J.number}: Contains files now in ignorePaths: ${_.join(", ")}`),!0;return E.debug(`\uD83D\uDD0D PR #${J.number}: No files match ignorePaths patterns`),!1}function b(J){let K=[],E=/\|\s*\[[^\]]+\]\([^)]*\)\s*\|[^|]*\|\s*\*\*([^*]+)\*\*\s*\|/g,O;while((O=E.exec(J))!==null){let Z=O[1].trim();if(Z&&!K.includes(Z))K.push(Z)}let Q=/\*\*([^*]+\.(?:json|yaml|yml|lock))\*\*/g;while((O=Q.exec(J))!==null){let Z=O[1].trim();if(Z&&!K.includes(Z))K.push(Z)}let X=/\|[^|]+\|[^|]+\|([^|]+)\|[^|]*\|/g;while((O=X.exec(J))!==null){let Z=O[1].trim();if(Z&&(Z.includes("/")||/\.(?:json|yaml|yml|lock)$/.test(Z))&&!K.includes(Z))K.push(Z)}let _=/(?:^|\s)([\w-]+(?:\/[\w.-]+)*\/[\w.-]+\.(?:json|yaml|yml|lock))(?:\s|$)/gm;while((O=_.exec(J))!==null){let Z=O[1].trim();if(Z&&!K.includes(Z))K.push(Z)}return K}
export{k as A,m as B,y as C,f as D,L as E,P as F,h as G,g as H,u as I,c as J,l as K,M as L,n as M};

//# debugId=088D51917EE32A6264756E2164756E21
