infra-kit 0.1.55 → 0.1.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,20 +1,20 @@
1
- import{Command as Rr}from"commander";import Re from"@inquirer/checkbox";import ke from"@inquirer/confirm";import xe from"node:process";import{z as x}from"zod";import{$ as h}from"zx";import ie from"node:process";import{$ as ae}from"zx";import we from"node:process";import ve from"pino";import ye from"pino-pretty";var be=()=>{let e=we.argv.includes("--debug")?"debug":"info",t=["time","pid","hostname"];return e==="debug"&&t.push("level"),ve({level:e},ye({ignore:t.join(","),colorize:!0}))},r=be();var J=async()=>{try{await ae`gh --version`}catch(e){r.error({error:e},"Error: GitHub CLI (gh) is not installed."),r.error("Please install it from: https://cli.github.com/"),ie.exit(1)}try{await ae`gh auth status`}catch(e){r.error({error:e},"Error: GitHub CLI (gh) is not authenticated."),r.error('Please authenticate it from: https://cli.github.com/manual/gh_auth_login or type "gh auth login"'),ie.exit(1)}};import ce from"node:process";import{$ as b}from"zx";var F=e=>e.replace("release/","").slice(1).split(".").map(Number),G=e=>[...e].sort((t,o)=>{let[n,s,i]=F(t),[c,a,l]=F(o);return n!==c?(n??0)-(c??0):s!==a?(s??0)-(a??0):(i??0)-(l??0)});var g=async()=>{try{let e=await b`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`,t=JSON.parse(e.stdout);t.length===0&&(r.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),ce.exit(1));let o=t.map(n=>n.headRefName);return G(o)}catch(e){r.error({error:e},"\u274C Error fetching release PRs"),ce.exit(1)}},T=async e=>{let t=`release/v${e}`;try{await b`git switch dev`,await b`git pull origin dev`,await b`git checkout -b ${t}`,await b`git push -u origin ${t}`,await b`git commit --allow-empty-message --allow-empty --message ''`,await b`git push origin ${t}`;let n=(await b`gh pr create --title "Release v${e}" --body "Release v${e}" --base dev --head ${t}`).stdout.trim();return await b`git switch dev`,{branchName:t,prUrl:n}}catch(o){throw r.error({error:o,branchName:t},`Error creating release branch ${t}`),o}};var S=async e=>{let{all:t,confirmedCommand:o}=e,n=await g(),s=[];t?s=n:s=await Re({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(l=>({name:l.replace("release/v",""),value:l}))}),o||await ke({message:`Are you sure you want to merge dev into these branches: ${s.join(", ")}?`})||(r.info("Operation cancelled. Exiting..."),xe.exit(0)),h.quiet=!0,await h`git fetch origin`,await h`git switch dev`,await h`git pull origin dev`;let c=[];for(let l of s)await $e(l)||c.push(l);if(h.quiet=!1,c.length>0){r.info(`
2
- \u26A0\uFE0F ${c.length} branch(es) failed to merge automatically.
1
+ import{Command as Pr}from"commander";import ke from"@inquirer/checkbox";import xe from"@inquirer/confirm";import Ce from"node:process";import{z as x}from"zod";import{$ as h}from"zx";import ce from"node:process";import{$ as le}from"zx";import we from"node:process";import ye from"pino";import be from"pino-pretty";var Re=()=>{let e=we.argv.includes("--debug")?"debug":"info",t=["time","pid","hostname"];return e==="debug"&&t.push("level"),ye({level:e},be({ignore:t.join(","),colorize:!0}))},r=Re();var N=async()=>{try{await le`gh --version`}catch(e){r.error({error:e},"Error: GitHub CLI (gh) is not installed."),r.error("Please install it from: https://cli.github.com/"),ce.exit(1)}try{await le`gh auth status`}catch(e){r.error({error:e},"Error: GitHub CLI (gh) is not authenticated."),r.error('Please authenticate it from: https://cli.github.com/manual/gh_auth_login or type "gh auth login"'),ce.exit(1)}};import me from"node:process";import{$ as f}from"zx";var H=e=>e.replace("release/","").slice(1).split(".").map(Number),K=e=>[...e].sort((t,i)=>{let[s,o,n]=H(t),[a,c,l]=H(i);return s!==a?(s??0)-(a??0):o!==c?(o??0)-(c??0):(n??0)-(l??0)});var u=async()=>{try{let e=await f`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`,t=JSON.parse(e.stdout);t.length===0&&(r.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),me.exit(1));let i=t.map(s=>s.headRefName);return K(i)}catch(e){r.error({error:e},"\u274C Error fetching release PRs"),me.exit(1)}},j=async e=>{let{version:t,jiraVersionUrl:i}=e,s=`release/v${t}`;try{f.quiet=!0,await f`git switch dev`,await f`git pull origin dev`,await f`git checkout -b ${s}`,await f`git push -u origin ${s}`,await f`git commit --allow-empty-message --allow-empty --message ''`,await f`git push origin ${s}`;let n=(await f`gh pr create --title "Release v${t}" --body "${i} \n" --base dev --head ${s}`).stdout.trim();return await f`git switch dev`,f.quiet=!1,{branchName:s,prUrl:n}}catch(o){throw r.error({error:o,branchName:s},`Error creating release branch ${s}`),o}};var W=async e=>{let{all:t,confirmedCommand:i}=e,s=await u(),o=[];t?o=s:o=await ke({required:!0,message:"\u{1F33F} Select release branches",choices:s.map(l=>({name:l.replace("release/v",""),value:l}))}),i||await xe({message:`Are you sure you want to merge dev into these branches: ${o.join(", ")}?`})||(r.info("Operation cancelled. Exiting..."),Ce.exit(0)),h.quiet=!0,await h`git fetch origin`,await h`git switch dev`,await h`git pull origin dev`;let a=[];for(let l of o)await $e(l)||a.push(l);if(h.quiet=!1,a.length>0){r.info(`
2
+ \u26A0\uFE0F ${a.length} branch(es) failed to merge automatically.
3
3
  `),r.info(`\u{1F4CB} Manual merge script for failed branches:
4
- `),r.info("```bash");for(let l of c)r.info(`# Phase #1: Merge dev into ${l}`),r.info(`git switch ${l} && git pull origin ${l} && git merge origin/dev`),r.info("# Phase #2:Resolve conflicts if any, then:"),r.info(`git push origin ${l} && git switch dev`);r.info(`\u2705 ${s.length-c.length}/${s.length} merges completed successfully.`)}else r.info("\u2705 All merges completed successfully!");let a={successfulMerges:s.length-c.length,failedMerges:c.length,failedBranches:c,totalBranches:s.length};return{content:[{type:"text",text:JSON.stringify(a,null,2)}],structuredContent:a}},$e=async e=>{try{return await h`git switch ${e}`,await h`git pull origin ${e}`,await h`git merge origin/dev --no-edit`,await h`git push origin ${e}`,await h`git switch dev`,r.info(`Successfully merged dev into ${e}`),!0}catch(t){return r.error({error:t,branch:e},`Error merging dev into ${e}`),await h`git reset --merge HEAD~1`,!1}},Ce={name:"gh-merge-dev",description:"Merge dev branch into selected release branches",inputSchema:{all:x.boolean().describe("Merge dev into all release branches without prompting")},outputSchema:{successfulMerges:x.number().describe("Number of successful merges"),failedMerges:x.number().describe("Number of failed merges"),failedBranches:x.array(x.string()).describe("List of branches that failed to merge"),totalBranches:x.number().describe("Total number of branches processed")},handler:S};import le from"@inquirer/confirm";import me from"node:process";import{z as f}from"zod";import{$,question as Je}from"zx";import E from"node:process";var z=async(e,t)=>{try{let{baseUrl:o,token:n,email:s,projectId:i}=t,c={name:e.name,projectId:e.projectId||i,description:e.description||"",released:e.released??!0,archived:e.archived??!1},a=`${o}/rest/api/3/version`,l=btoa(`${s}:${n}`),m=await fetch(a,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${l}`},body:JSON.stringify(c)});if(!m.ok){let w=await m.text();throw r.error({status:m.status,statusText:m.statusText,error:w},"Failed to create Jira version"),new Error(`HTTP ${m.status}: ${m.statusText}`)}return{success:!0,version:await m.json()}}catch(o){throw r.error({error:o},"Error creating Jira version"),o}},Pe=async e=>{try{let{baseUrl:t,token:o,email:n,projectId:s}=e,i=`${t}/rest/api/3/project/${s}/versions`,c=btoa(`${n}:${o}`),a=await fetch(i,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${c}`}});if(!a.ok){let m=await a.text();throw r.error({status:a.status,statusText:a.statusText,error:m},"Failed to get Jira project versions"),new Error(`HTTP ${a.status}: ${a.statusText}`)}return await a.json()}catch(t){throw r.error({error:t},"Error getting Jira project versions"),t}},Ee=async(e,t)=>{try{return(await Pe(t)).find(s=>s.name===e)||null}catch(o){throw r.error({error:o,versionName:e},"Error finding Jira version by name"),o}},Ae=async(e,t)=>{try{let{baseUrl:o,token:n,email:s}=t,i={released:e.released??!0,archived:e.archived??!1};e.releaseDate?i.releaseDate=e.releaseDate:e.released!==!1&&(i.releaseDate=new Date().toISOString().split("T")[0]),e.description!==void 0&&(i.description=e.description);let c=`${o}/rest/api/3/version/${e.versionId}`,a=btoa(`${s}:${n}`),l=await fetch(c,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${a}`},body:JSON.stringify(i)});if(!l.ok){let p=await l.text();throw r.error({status:l.status,statusText:l.statusText,error:p},"Failed to update Jira version"),new Error(`HTTP ${l.status}: ${l.statusText}`)}return{success:!0,version:await l.json()}}catch(o){throw r.error({error:o},"Error updating Jira version"),o}},H=async(e,t)=>{try{let{versionName:o}=e,n=await Ee(o,t);if(!n)throw r.error({versionName:o},"Jira version not found"),new Error(`Version "${o}" not found in Jira project`);return await Ae({versionId:n.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},t)}catch(o){throw r.error({error:o},"Error delivering Jira release"),o}},I=async()=>{let e=E.env.JIRA_BASE_URL,t=E.env.JIRA_TOKEN||E.env.JIRA_API_TOKEN,o=E.env.JIRA_PROJECT_ID,n=E.env.JIRA_EMAIL,s=[];if(e||s.push("JIRA_BASE_URL (e.g., https://your-domain.atlassian.net)"),t||s.push("JIRA_TOKEN or JIRA_API_TOKEN (your Jira API token)"),o||s.push("JIRA_PROJECT_ID (numeric project ID)"),n||s.push("JIRA_EMAIL (your Jira email address)"),s.length>0){let c=["Jira configuration is required but incomplete.","Please configure the following environment variables:",...s.map(a=>` - ${a}`),"","You can set these in your .env file or as environment variables."].join(`
5
- `);throw new Error(c)}let i=Number.parseInt(o,10);if(Number.isNaN(i))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${o}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:t,projectId:i,email:n}},K=async()=>{try{return await I()}catch(e){return r.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var W=async e=>{let{versions:t,confirmedCommand:o,checkout:n}=e,s="",i=n,c=await I();t?s=t:s=await Je("Enter versions by comma (e.g. 1.2.5, 1.2.6): ");let a=s.split(",").map(u=>u.trim());a.length===0&&(r.error("No versions provided. Exiting..."),me.exit(1)),i&&a.length>1&&r.warn("\u26A0\uFE0F Checkout option is ignored when creating multiple branches. Only works with single branch creation."),a.length===1&&!i&&(i=await le({message:"Checkout to the created branch?"})),o||await le({message:`Are you sure you want to create release branches for these versions: ${a.join(", ")}?`})||(r.info("Operation cancelled. Exiting..."),me.exit(0)),$.quiet=!0,await $`git fetch origin`,await $`git switch dev`,await $`git pull origin dev`;let m=[];for(let u of a){let oe=`v${u}`,se=await z({name:oe,projectId:c.projectId,description:"",released:!1,archived:!1},c),U=await T(u),ne=`${c.baseUrl}/projects/${se.version.projectId}/versions/${se.version.id}/tab/release-report-all-issues`;m.push({version:u,branchName:U.branchName,prUrl:U.prUrl,jiraVersionUrl:ne}),r.info(`\u2705 Successfully created release: ${oe}`),r.info(`\u{1F517} GitHub PR: ${U.prUrl}`),r.info(`\u{1F517} Jira Version: ${ne}
6
- `)}let p=i&&a.length===1;if(p){let u=`release/v${a[0]}`;await $`git switch ${u}`,r.info(`\u{1F504} Switched to branch ${u}`)}r.info(`${a.length} release branches were created successfully.`),$.quiet=!1;let w={createdBranches:a.map(u=>`release/v${u}`),branchCount:a.length,isCheckedOut:p,releases:m};return{content:[{type:"text",text:JSON.stringify(w,null,2)}],structuredContent:w}},Te={name:"gh-release-create",description:"Create new release branches for specified versions and optionally create Jira versions",inputSchema:{versions:f.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6")'),checkout:f.boolean().optional().describe("Checkout to the created branch (only works with single version)")},outputSchema:{createdBranches:f.array(f.string()).describe("List of created release branches"),branchCount:f.number().describe("Number of branches created"),isCheckedOut:f.boolean().describe("Whether the branch was checked out"),releases:f.array(f.object({version:f.string().describe("Version number"),branchName:f.string().describe("Release branch name"),prUrl:f.string().describe("GitHub PR URL"),jiraVersionUrl:f.string().describe("Jira version URL")})).describe("Detailed information for each created release with URLs only")},handler:W};import Se from"@inquirer/confirm";import Ie from"@inquirer/select";import X from"node:process";import{z as N}from"zod";import{$ as R}from"zx";var j=async e=>{let{version:t,confirmedCommand:o}=e,n=await g(),s="";t?s=`release/v${t}`:s=await Ie({message:"\u{1F33F} Select release branch",choices:n.map(c=>({name:c.replace("release/v",""),value:c}))}),n.includes(s)||(r.error(`\u274C Release branch ${s} not found in open PRs. Exiting...`),X.exit(1)),o||await Se({message:`Are you sure you want to deliver version ${s} to production?`})||(r.info("Operation cancelled. Exiting..."),X.exit(0));try{R.quiet=!0,await R`gh pr merge ${s} --squash --admin --delete-branch`,await R`gh pr create --base main --head dev --title "Release v${s.replace("release/v","")} (RC)" --body ""`,await R`gh pr merge dev --squash --admin`,R.quiet=!1,await R`gh workflow run deploy-all.yml --ref main -f environment=prod`,R.quiet=!0,await R`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`,R.quiet=!1;let c=await K();if(c)try{let l=s.replace("release/","");await H({versionName:l},c)}catch(l){r.error({error:l},"Failed to deliver Jira release (non-blocking)")}else r.info("\u{1F514} Jira is not configured, skipping Jira release delivery");r.info(`Successfully delivered ${s} to production!`);let a={releaseBranch:s,version:s.replace("release/v",""),success:!0};return{content:[{type:"text",text:JSON.stringify(a,null,2)}],structuredContent:a}}catch(c){r.error({error:c},"\u274C Error merging release branch into dev"),X.exit(1)}},We={name:"gh-release-deliver",description:"Deliver a release branch to production",inputSchema:{version:N.string().describe('Version to deliver to production (e.g., "1.2.5")')},outputSchema:{releaseBranch:N.string().describe("The release branch that was delivered"),version:N.string().describe("The version that was delivered"),success:N.boolean().describe("Whether the delivery was successful")},handler:j};import ue from"@inquirer/select";import Q from"node:process";import{z as P}from"zod";import{$ as Z}from"zx";var Y=["dev","arthur","renana","roman","eliran","oriana"],C="-worktrees";var D=async e=>{let{version:t,env:o}=e,n=["dev"],s=await g();n.push(...s);let i="";t?i=`release/v${t}`:i=await ue({message:"\u{1F33F} Select release branch",choices:n.map(a=>({name:a.replace("release/v",""),value:a}))}),n.includes(i)||(r.error(`\u274C Release branch ${i} not found in open PRs. Exiting...`),Q.exit(1));let c="";o?c=o:c=await ue({message:"\u{1F9EA} Select environment",choices:Y.map(a=>({name:a,value:a}))}),Y.includes(c)||(r.error(`\u274C Invalid environment: ${c}. Exiting...`),Q.exit(1));try{Z.quiet=!0,await Z`gh workflow run deploy-all.yml --ref ${i} -f environment=${c}`,Z.quiet=!1,r.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${i} and environment: ${c}`);let a={releaseBranch:i,version:i.replace("release/v",""),environment:c,success:!0};return{content:[{type:"text",text:JSON.stringify(a,null,2)}],structuredContent:a}}catch(a){r.error({error:a},"\u274C Error launching workflow"),Q.exit(1)}},Ne={name:"gh-release-deploy",description:"Deploy a release branch to a specified environment",inputSchema:{version:P.string().describe('Version to deploy (e.g., "1.2.5")'),env:P.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")')},outputSchema:{releaseBranch:P.string().describe("The release branch that was deployed"),version:P.string().describe("The version that was deployed"),environment:P.string().describe("The environment deployed to"),success:P.boolean().describe("Whether the deployment was successful")},handler:D};import{z as ee}from"zod";var L=async()=>{let t=(await g()).map(n=>n.replace("release/",""));r.info(`All release branches:
4
+ `),r.info("```bash");for(let l of a)r.info(`# Phase #1: Merge dev into ${l}`),r.info(`git switch ${l} && git pull origin ${l} && git merge origin/dev`),r.info("# Phase #2:Resolve conflicts if any, then:"),r.info(`git push origin ${l} && git switch dev`);r.info(`\u2705 ${o.length-a.length}/${o.length} merges completed successfully.`)}else r.info("\u2705 All merges completed successfully!");let c={successfulMerges:o.length-a.length,failedMerges:a.length,failedBranches:a,totalBranches:o.length};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}},$e=async e=>{try{return await h`git switch ${e}`,await h`git pull origin ${e}`,await h`git merge origin/dev --no-edit`,await h`git push origin ${e}`,await h`git switch dev`,r.info(`Successfully merged dev into ${e}`),!0}catch(t){return r.error({error:t,branch:e},`Error merging dev into ${e}`),await h`git reset --merge HEAD~1`,!1}},Pe={name:"gh-merge-dev",description:"Merge dev branch into selected release branches",inputSchema:{all:x.boolean().describe("Merge dev into all release branches without prompting")},outputSchema:{successfulMerges:x.number().describe("Number of successful merges"),failedMerges:x.number().describe("Number of failed merges"),failedBranches:x.array(x.string()).describe("List of branches that failed to merge"),totalBranches:x.number().describe("Total number of branches processed")},handler:W};import Se from"@inquirer/confirm";import Te from"@inquirer/select";import Z from"node:process";import{z as O}from"zod";import{$ as b}from"zx";import J from"node:process";var X=async(e,t)=>{try{let{baseUrl:i,token:s,email:o,projectId:n}=t,a={name:e.name,projectId:e.projectId||n,description:e.description||"",released:e.released||!1,archived:e.archived||!1},c=`${i}/rest/api/3/version`,l=btoa(`${o}:${s}`),m=await fetch(c,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${l}`},body:JSON.stringify(a)});if(!m.ok){let d=await m.text();throw r.error({status:m.status,statusText:m.statusText,error:d},"Failed to create Jira version"),new Error(`HTTP ${m.status}: ${m.statusText}`)}return{success:!0,version:await m.json()}}catch(i){throw r.error({error:i},"Error creating Jira version"),i}},Je=async e=>{try{let{baseUrl:t,token:i,email:s,projectId:o}=e,n=`${t}/rest/api/3/project/${o}/versions`,a=btoa(`${s}:${i}`),c=await fetch(n,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${a}`}});if(!c.ok){let m=await c.text();throw r.error({status:c.status,statusText:c.statusText,error:m},"Failed to get Jira project versions"),new Error(`HTTP ${c.status}: ${c.statusText}`)}return await c.json()}catch(t){throw r.error({error:t},"Error getting Jira project versions"),t}},Ee=async(e,t)=>{try{return(await Je(t)).find(o=>o.name===e)||null}catch(i){throw r.error({error:i,versionName:e},"Error finding Jira version by name"),i}},Ae=async(e,t)=>{try{let{baseUrl:i,token:s,email:o}=t,n={released:e.released??!0,archived:e.archived??!1};e.releaseDate?n.releaseDate=e.releaseDate:e.released!==!1&&(n.releaseDate=new Date().toISOString().split("T")[0]),e.description!==void 0&&(n.description=e.description);let a=`${i}/rest/api/3/version/${e.versionId}`,c=btoa(`${o}:${s}`),l=await fetch(a,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${c}`},body:JSON.stringify(n)});if(!l.ok){let p=await l.text();throw r.error({status:l.status,statusText:l.statusText,error:p},"Failed to update Jira version"),new Error(`HTTP ${l.status}: ${l.statusText}`)}return{success:!0,version:await l.json()}}catch(i){throw r.error({error:i},"Error updating Jira version"),i}},Y=async(e,t)=>{try{let{versionName:i}=e,s=await Ee(i,t);if(!s)throw r.error({versionName:i},"Jira version not found"),new Error(`Version "${i}" not found in Jira project`);return await Ae({versionId:s.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},t)}catch(i){throw r.error({error:i},"Error delivering Jira release"),i}},C=async()=>{let e=J.env.JIRA_BASE_URL,t=J.env.JIRA_TOKEN||J.env.JIRA_API_TOKEN,i=J.env.JIRA_PROJECT_ID,s=J.env.JIRA_EMAIL,o=[];if(e||o.push("JIRA_BASE_URL (e.g., https://your-domain.atlassian.net)"),t||o.push("JIRA_TOKEN or JIRA_API_TOKEN (your Jira API token)"),i||o.push("JIRA_PROJECT_ID (numeric project ID)"),s||o.push("JIRA_EMAIL (your Jira email address)"),o.length>0){let a=["Jira configuration is required but incomplete.","Please configure the following environment variables:",...o.map(c=>` - ${c}`),"","You can set these in your .env file or as environment variables."].join(`
5
+ `);throw new Error(a)}let n=Number.parseInt(i,10);if(Number.isNaN(n))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${i}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:t,projectId:n,email:s}},Q=async()=>{try{return await C()}catch(e){return r.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var L=async e=>{let{version:t,confirmedCommand:i}=e,s=await u(),o="";t?o=`release/v${t}`:o=await Te({message:"\u{1F33F} Select release branch",choices:s.map(a=>({name:a.replace("release/v",""),value:a}))}),s.includes(o)||(r.error(`\u274C Release branch ${o} not found in open PRs. Exiting...`),Z.exit(1)),i||await Se({message:`Are you sure you want to deliver version ${o} to production?`})||(r.info("Operation cancelled. Exiting..."),Z.exit(0));try{b.quiet=!0,await b`gh pr merge ${o} --squash --admin --delete-branch`,await b`gh pr create --base main --head dev --title "Release v${o.replace("release/v","")} (RC)" --body ""`,await b`gh pr merge dev --squash --admin`,b.quiet=!1,await b`gh workflow run deploy-all.yml --ref main -f environment=prod`,b.quiet=!0,await b`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`,b.quiet=!1;let a=await Q();if(a)try{let l=o.replace("release/","");await Y({versionName:l},a)}catch(l){r.error({error:l},"Failed to deliver Jira release (non-blocking)")}else r.info("\u{1F514} Jira is not configured, skipping Jira release delivery");r.info(`Successfully delivered ${o} to production!`);let c={releaseBranch:o,version:o.replace("release/v",""),success:!0};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}}catch(a){r.error({error:a},"\u274C Error merging release branch into dev"),Z.exit(1)}},Ie={name:"gh-release-deliver",description:"Deliver a release branch to production",inputSchema:{version:O.string().describe('Version to deliver to production (e.g., "1.2.5")')},outputSchema:{releaseBranch:O.string().describe("The release branch that was delivered"),version:O.string().describe("The version that was delivered"),success:O.boolean().describe("Whether the delivery was successful")},handler:L};import pe from"@inquirer/select";import re from"node:process";import{z as P}from"zod";import{$ as te}from"zx";var ee=["dev","arthur","renana","roman","eliran","oriana"],$="-worktrees";var B=async e=>{let{version:t,env:i}=e,s=["dev"],o=await u();s.push(...o);let n="";t?n=`release/v${t}`:n=await pe({message:"\u{1F33F} Select release branch",choices:s.map(c=>({name:c.replace("release/v",""),value:c}))}),s.includes(n)||(r.error(`\u274C Release branch ${n} not found in open PRs. Exiting...`),re.exit(1));let a="";i?a=i:a=await pe({message:"\u{1F9EA} Select environment",choices:ee.map(c=>({name:c,value:c}))}),ee.includes(a)||(r.error(`\u274C Invalid environment: ${a}. Exiting...`),re.exit(1));try{te.quiet=!0,await te`gh workflow run deploy-all.yml --ref ${n} -f environment=${a}`,te.quiet=!1,r.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${n} and environment: ${a}`);let c={releaseBranch:n,version:n.replace("release/v",""),environment:a,success:!0};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}}catch(c){r.error({error:c},"\u274C Error launching workflow"),re.exit(1)}},Ne={name:"gh-release-deploy",description:"Deploy a release branch to a specified environment",inputSchema:{version:P.string().describe('Version to deploy (e.g., "1.2.5")'),env:P.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")')},outputSchema:{releaseBranch:P.string().describe("The release branch that was deployed"),version:P.string().describe("The version that was deployed"),environment:P.string().describe("The environment deployed to"),success:P.boolean().describe("Whether the deployment was successful")},handler:B};import{z as oe}from"zod";var D=async()=>{let t=(await u()).map(s=>s.replace("release/",""));r.info(`All release branches:
7
6
  `),r.info(`
8
7
  ${t.join(`
9
- `)}`);let o={releases:t,count:t.length};return{content:[{type:"text",text:JSON.stringify(o,null,2)}],structuredContent:o}},je={name:"gh-release-list",description:"List all open release branches",inputSchema:{},outputSchema:{releases:ee.array(ee.string()).describe("List of all release branches"),count:ee.number().describe("Number of release branches")},handler:L};import Oe from"@inquirer/checkbox";import Be from"@inquirer/confirm";import Me from"node:process";import{z as O}from"zod";import{$ as de}from"zx";import{$ as pe}from"zx";var v=async e=>{let o=(await pe`git worktree list`).stdout.split(`
10
- `).filter(Boolean),n={release:De,feature:Le};return o.map(n[e]).filter(s=>s!==null)},De=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("release/v")?null:`release/${t[0]?.split("/").pop()||""}`},Le=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("feature/")?null:`feature/${t[0]?.split("/").pop()||""}`},k=async()=>(await pe`git rev-parse --show-toplevel`).stdout.trim();var Ve="feature",_e="release",qe="release/v",B=async e=>{let{confirmedCommand:t,all:o}=e;try{let n=await v("release"),i=`${await k()}${C}`;await ge(`${i}/${_e}`),await ge(`${i}/${Ve}`);let c=await g(),a=[];o?a=c:a=await Oe({required:!0,message:"\u{1F33F} Select release branches",choices:c.map(u=>({name:u.replace("release/v",""),value:u}))}),t||await Be({message:"Are you sure you want to proceed with these worktree changes?"})||(r.info("Operation cancelled. Exiting..."),Me.exit(0));let{branchesToCreate:m}=Ue({selectedReleaseBranches:a,currentWorktrees:n}),p=await Fe(m,i);Ge(p);let w={createdWorktrees:p,count:p.length};return{content:[{type:"text",text:JSON.stringify(w,null,2)}],structuredContent:w}}catch(n){throw r.error({error:n},"\u274C Error managing worktrees"),n}},ge=async e=>{await de`mkdir -p ${e}`},Ue=e=>{let{selectedReleaseBranches:t,currentWorktrees:o}=e,n=o.filter(i=>i.startsWith(qe));return{branchesToCreate:t.filter(i=>!n.includes(i))}},Fe=async(e,t)=>{let o=[];for(let n of e)try{let s=`${t}/${n}`;await de`git worktree add ${s} ${n}`,o.push(n)}catch(s){r.error({error:s,branch:n},`\u274C Failed to create worktree for ${n}`)}return o},Ge=e=>{e.length>0?(r.info(`
8
+ `)}`);let i={releases:t,count:t.length};return{content:[{type:"text",text:JSON.stringify(i,null,2)}],structuredContent:i}},je={name:"gh-release-list",description:"List all open release branches",inputSchema:{},outputSchema:{releases:oe.array(oe.string()).describe("List of all release branches"),count:oe.number().describe("Number of release branches")},handler:D};import We from"@inquirer/confirm";import ue from"node:process";import{z as k}from"zod";import{$ as se,question as Oe}from"zx";import{$ as E}from"zx";var A=async()=>{E.quiet=!0,await E`git fetch origin`,await E`git switch dev`,await E`git pull origin dev`,E.quiet=!1},S=async(e,t,i)=>{let s=`v${e}`,o=await X({name:s,projectId:t.projectId,description:i||"",released:!1,archived:!1},t),n=`${t.baseUrl}/projects/${o.version.projectId}/versions/${o.version.id}/tab/release-report-all-issues`,a=await j({version:e,jiraVersionUrl:n});return{version:e,branchName:a.branchName,prUrl:a.prUrl,jiraVersionUrl:n}};var V=async e=>{let{version:t,description:i,confirmedCommand:s,checkout:o=!0}=e,n=t,a=await C();n||(n=await Oe("Enter version (e.g. 1.2.5): ")),(!n||n.trim()==="")&&(r.error("No version provided. Exiting..."),ue.exit(1));let c=n.trim();s||await We({message:`Are you sure you want to create release branch for version ${c}?`})||(r.info("Operation cancelled. Exiting..."),ue.exit(0)),await A();let m=await S(c,a,i);r.info(`\u2705 Successfully created release: v${c}`),r.info(`\u{1F517} GitHub PR: ${m.prUrl}`),r.info(`\u{1F517} Jira Version: ${m.jiraVersionUrl}`),o&&(se.quiet=!0,await se`git switch ${m.branchName}`,se.quiet=!1,r.info(`\u{1F504} Switched to branch ${m.branchName}`));let p={version:c,branchName:m.branchName,prUrl:m.prUrl,jiraVersionUrl:m.jiraVersionUrl,isCheckedOut:o};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}},Le={name:"release-create",description:"Create a single release branch for specified version with Jira version creation",inputSchema:{version:k.string().describe('Version to create (e.g., "1.2.5")'),description:k.string().optional().describe("Optional description for the Jira version"),checkout:k.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:k.string().describe("Version number"),branchName:k.string().describe("Release branch name"),prUrl:k.string().describe("GitHub PR URL"),jiraVersionUrl:k.string().describe("Jira version URL"),isCheckedOut:k.boolean().describe("Whether the branch was checked out")},handler:V};import Be from"@inquirer/confirm";import ge from"node:process";import{z as v}from"zod";import{question as De}from"zx";var M=async e=>{let{versions:t,description:i,confirmedCommand:s}=e,o=t,n=await C();o||(o=await De("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let a=o.split(",").map(p=>p.trim());a.length===0&&(r.error("No versions provided. Exiting..."),ge.exit(1)),a.length===1&&r.warn('\u{1F4A1} You are creating only one release. Consider using "create-release" command for single releases.'),s||await Be({message:`Are you sure you want to create release branches for these versions: ${a.join(", ")}?`})||(r.info("Operation cancelled. Exiting..."),ge.exit(0)),await A();let l=[];for(let p of a){let d=await S(p,n,i);l.push(d),r.info(`\u2705 Successfully created release: v${p}`),r.info(`\u{1F517} GitHub PR: ${d.prUrl}`),r.info(`\u{1F517} Jira Version: ${d.jiraVersionUrl}
9
+ `)}r.info(`${a.length} release branches were created successfully.`);let m={createdBranches:a.map(p=>`release/v${p}`),branchCount:a.length,releases:l};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},Ve={name:"release-create-batch",description:"Create multiple release branches for specified versions with Jira version creation (batch operation)",inputSchema:{versions:v.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6")'),description:v.string().optional().describe("Optional description for the Jira versions")},outputSchema:{createdBranches:v.array(v.string()).describe("List of created release branches"),branchCount:v.number().describe("Number of branches created"),releases:v.array(v.object({version:v.string().describe("Version number"),branchName:v.string().describe("Release branch name"),prUrl:v.string().describe("GitHub PR URL"),jiraVersionUrl:v.string().describe("Jira version URL")})).describe("Detailed information for each created release with URLs")},handler:M};import qe from"@inquirer/checkbox";import _e from"@inquirer/confirm";import Fe from"node:process";import{z as U}from"zod";import{$ as he}from"zx";import{$ as de}from"zx";var y=async e=>{let i=(await de`git worktree list`).stdout.split(`
10
+ `).filter(Boolean),s={release:Me,feature:Ue};return i.map(s[e]).filter(o=>o!==null)},Me=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("release/v")?null:`release/${t[0]?.split("/").pop()||""}`},Ue=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("feature/")?null:`feature/${t[0]?.split("/").pop()||""}`},R=async()=>(await de`git rev-parse --show-toplevel`).stdout.trim();var Ge="feature",ze="release",He="release/v",q=async e=>{let{confirmedCommand:t,all:i}=e;try{let s=await y("release"),n=`${await R()}${$}`;await fe(`${n}/${ze}`),await fe(`${n}/${Ge}`);let a=await u(),c=[];i?c=a:c=await qe({required:!0,message:"\u{1F33F} Select release branches",choices:a.map(I=>({name:I.replace("release/v",""),value:I}))}),t||await _e({message:"Are you sure you want to proceed with these worktree changes?"})||(r.info("Operation cancelled. Exiting..."),Fe.exit(0));let{branchesToCreate:m}=Ke({selectedReleaseBranches:c,currentWorktrees:s}),p=await Xe(m,n);Ye(p);let d={createdWorktrees:p,count:p.length};return{content:[{type:"text",text:JSON.stringify(d,null,2)}],structuredContent:d}}catch(s){throw r.error({error:s},"\u274C Error managing worktrees"),s}},fe=async e=>{await he`mkdir -p ${e}`},Ke=e=>{let{selectedReleaseBranches:t,currentWorktrees:i}=e,s=i.filter(n=>n.startsWith(He));return{branchesToCreate:t.filter(n=>!s.includes(n))}},Xe=async(e,t)=>{let i=[];for(let s of e)try{let o=`${t}/${s}`;await he`git worktree add ${o} ${s}`,i.push(s)}catch(o){r.error({error:o,branch:s},`\u274C Failed to create worktree for ${s}`)}return i},Ye=e=>{e.length>0?(r.info(`
11
11
  `),r.info("\u2705 Created worktrees:"),r.info(e.join(`
12
- `)),r.info("")):r.info("\u2139\uFE0F No new worktrees to create")},ze={name:"worktrees-add",description:"Create worktrees for selected release branches",inputSchema:{all:O.boolean().describe("Add worktrees for all release branches without prompting")},outputSchema:{createdWorktrees:O.array(O.string()).describe("List of created worktree branches"),count:O.number().describe("Number of worktrees created")},handler:B};import{z as d}from"zod";import{$ as A}from"zx";var M=async()=>{try{let[e,t]=await Promise.all([v("release"),v("feature")]),o=await k(),n=await He(e,t,o);er(n);let s={worktrees:n,totalCount:n.length,releaseCount:e.length,featureCount:t.length};return{content:[{type:"text",text:JSON.stringify(s,null,2)}],structuredContent:s}}catch(e){throw r.error({error:e},"\u274C Error listing worktrees"),e}},He=async(e,t,o)=>{let n=[...e.map(i=>({branch:i,type:"release"})),...t.map(i=>({branch:i,type:"feature"}))],s=[];for(let{branch:i,type:c}of n)try{let a=`${o}/${i}`,l=await Ke(i),m=await Xe(a),p=await Ye(a),w=await Qe(a),u=await Ze(a);s.push({branch:i,path:a,commit:m.substring(0,8),isCurrent:l,type:c,status:p,lastCommitMessage:w.substring(0,60)+(w.length>60?"...":""),aheadBehind:u})}catch(a){r.warn({error:a,branch:i},`\u26A0\uFE0F Could not process worktree ${i}`)}return s.sort((i,c)=>i.type!==c.type?i.type==="release"?-1:1:i.branch.localeCompare(c.branch))},Ke=async e=>{try{return(await A`git branch --show-current`).stdout.trim()===e}catch{return!1}},Xe=async e=>{try{return(await A`cd ${e} && git rev-parse HEAD`).stdout.trim()}catch{return"unknown"}},Ye=async e=>{try{let o=(await A`cd ${e} && git status --porcelain`).stdout.trim().split(`
13
- `).filter(Boolean);return o.length===0?"clean":o.length<=3?"modified":"dirty"}catch{return"unknown"}},Qe=async e=>{try{return(await A`cd ${e} && git log -1 --pretty=format:"%s"`).stdout.trim()}catch{return"No commit message available"}},Ze=async e=>{try{let o=(await A`cd ${e} && git rev-list --count --left-right @{u}...HEAD 2>/dev/null || echo "0 0"`).stdout.trim().split(" ").map(Number),n=o[0]||0,s=o[1]||0;return s===0&&n===0?"up to date":s>0&&n===0?`\u2191${s} ahead`:n>0&&s===0?`\u2193${n} behind`:`\u2191${s} \u2193${n}`}catch{return"unknown"}},er=e=>{if(e.length===0){r.info(`
12
+ `)),r.info("")):r.info("\u2139\uFE0F No new worktrees to create")},Qe={name:"worktrees-add",description:"Create worktrees for selected release branches",inputSchema:{all:U.boolean().describe("Add worktrees for all release branches without prompting")},outputSchema:{createdWorktrees:U.array(U.string()).describe("List of created worktree branches"),count:U.number().describe("Number of worktrees created")},handler:q};import{z as g}from"zod";import{$ as T}from"zx";var _=async()=>{try{let[e,t]=await Promise.all([y("release"),y("feature")]),i=await R(),s=await Ze(e,t,i);ir(s);let o={worktrees:s,totalCount:s.length,releaseCount:e.length,featureCount:t.length};return{content:[{type:"text",text:JSON.stringify(o,null,2)}],structuredContent:o}}catch(e){throw r.error({error:e},"\u274C Error listing worktrees"),e}},Ze=async(e,t,i)=>{let s=[...e.map(n=>({branch:n,type:"release"})),...t.map(n=>({branch:n,type:"feature"}))],o=[];for(let{branch:n,type:a}of s)try{let c=`${i}/${n}`,l=await er(n),m=await rr(c),p=await tr(c),d=await or(c),I=await sr(c);o.push({branch:n,path:c,commit:m.substring(0,8),isCurrent:l,type:a,status:p,lastCommitMessage:d.substring(0,60)+(d.length>60?"...":""),aheadBehind:I})}catch(c){r.warn({error:c,branch:n},`\u26A0\uFE0F Could not process worktree ${n}`)}return o.sort((n,a)=>n.type!==a.type?n.type==="release"?-1:1:n.branch.localeCompare(a.branch))},er=async e=>{try{return(await T`git branch --show-current`).stdout.trim()===e}catch{return!1}},rr=async e=>{try{return(await T`cd ${e} && git rev-parse HEAD`).stdout.trim()}catch{return"unknown"}},tr=async e=>{try{let i=(await T`cd ${e} && git status --porcelain`).stdout.trim().split(`
13
+ `).filter(Boolean);return i.length===0?"clean":i.length<=3?"modified":"dirty"}catch{return"unknown"}},or=async e=>{try{return(await T`cd ${e} && git log -1 --pretty=format:"%s"`).stdout.trim()}catch{return"No commit message available"}},sr=async e=>{try{let i=(await T`cd ${e} && git rev-list --count --left-right @{u}...HEAD 2>/dev/null || echo "0 0"`).stdout.trim().split(" ").map(Number),s=i[0]||0,o=i[1]||0;return o===0&&s===0?"up to date":o>0&&s===0?`\u2191${o} ahead`:s>0&&o===0?`\u2193${s} behind`:`\u2191${o} \u2193${s}`}catch{return"unknown"}},ir=e=>{if(e.length===0){r.info(`
14
14
  \u{1F33F} Git Worktrees`),r.info("\u2500".repeat(80)),r.info("\u2139\uFE0F No worktrees found"),r.info("\u2500".repeat(80));return}r.info(`
15
- \u{1F33F} Git Worktrees`),r.info("\u2550".repeat(100));let t=e.filter(s=>s.type==="release"),o=e.filter(s=>s.type==="feature");fe("\u{1F680} Releases",t),o.length>0&&t.length>0&&r.info(""),fe("\u2728 Features",o);let n=e.find(s=>s.isCurrent);r.info(`
16
- ${"\u2550".repeat(100)}`),r.info(`\u{1F4CA} Summary: ${e.length} total worktrees (${t.length} releases, ${o.length} features)`),n&&r.info(`\u{1F4CD} Currently on: ${n.branch}`),r.info("")},fe=(e,t)=>{if(t.length!==0){r.info(`
17
- ${e}`),r.info("\u2500".repeat(50));for(let[o,n]of t.entries())rr(n),o<t.length-1&&r.info("")}},rr=e=>{let t=e.isCurrent?"\u{1F4CD}":" ",o=tr(e.status),s=`${e.type==="release"?"\u{1F680}":"\u2728"} ${e.branch}`;r.info(`${t} ${o} ${s}`);let i=e.aheadBehind!=="unknown"?` | ${e.aheadBehind}`:"";r.info(` \u{1F4DD} ${e.commit}${i}`),r.info(` \u{1F4AC} ${e.lastCommitMessage}`);let c=e.path.split("/").slice(-2).join("/");r.info(` \u{1F4C1} ${c}`)},tr=e=>{switch(e){case"clean":return"\u2705";case"modified":return"\u26A0\uFE0F ";case"dirty":return"\u{1F534}";default:return"\u2753"}},or={name:"worktrees-list",description:"List all git worktrees with detailed information",inputSchema:{},outputSchema:{worktrees:d.array(d.object({branch:d.string(),path:d.string(),commit:d.string(),isCurrent:d.boolean(),type:d.enum(["release","feature"]),status:d.string(),lastCommitMessage:d.string(),aheadBehind:d.string()})).describe("List of all worktrees with details"),totalCount:d.number().describe("Total number of worktrees"),releaseCount:d.number().describe("Number of release worktrees"),featureCount:d.number().describe("Number of feature worktrees")},handler:M};import sr from"@inquirer/checkbox";import nr from"@inquirer/confirm";import ir from"node:process";import{z as V}from"zod";import{$ as ar}from"zx";var _=async e=>{let{confirmedCommand:t,all:o}=e;try{let n=await v("release"),i=`${await k()}${C}`,c=[];o?c=n:c=await sr({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(p=>({name:p.replace("release/v",""),value:p}))}),t||await nr({message:"Are you sure you want to proceed with these worktree changes?"})||(r.info("Operation cancelled. Exiting..."),ir.exit(0));let l=await cr(c,i);lr(l);let m={removedWorktrees:l,count:l.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(n){throw r.error({error:n},"\u274C Error managing worktrees"),n}},cr=async(e,t)=>{let o=[];for(let n of e)try{let s=`${t}/${n}`;await ar`git worktree remove ${s}`,o.push(n)}catch(s){r.error({error:s,branch:n},`\u274C Failed to remove worktree for ${n}`)}return o},lr=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
18
- `)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},mr={name:"worktrees-remove",description:"Remove selected worktrees",inputSchema:{all:V.boolean().describe("Remove all worktrees without prompting")},outputSchema:{removedWorktrees:V.array(V.string()).describe("List of removed worktree branches"),count:V.number().describe("Number of worktrees removed")},handler:_};import ur from"@inquirer/confirm";import pr from"node:process";import{z as re}from"zod";import{$ as gr}from"zx";var dr="release/v",q=async e=>{let{confirmedCommand:t}=e;try{let o=await v("release"),s=`${await k()}${C}`,i=await g();t||await ur({message:"Are you sure you want to proceed with these worktree changes?"})||(r.info("Operation cancelled. Exiting..."),pr.exit(0));let{branchesToRemove:a}=fr({releasePRsList:i,currentWorktrees:o}),l=await hr(a,s);wr(l);let m={removedWorktrees:l,count:l.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(o){throw r.error({error:o},"\u274C Error managing worktrees"),o}},fr=e=>{let{releasePRsList:t,currentWorktrees:o}=e;return{branchesToRemove:o.filter(i=>i.startsWith(dr)).filter(i=>!t.includes(i))}},hr=async(e,t)=>{let o=[];for(let n of e)try{let s=`${t}/${n}`;await gr`git worktree remove ${s}`,o.push(n)}catch(s){r.error({error:s,branch:n},`\u274C Failed to remove worktree for ${n}`)}return o},wr=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
19
- `)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},vr={name:"worktrees-sync",description:"Synchronize worktrees with active release branches",inputSchema:{},outputSchema:{removedWorktrees:re.array(re.string()).describe("List of removed worktree branches"),count:re.number().describe("Number of worktrees removed during sync")},handler:q};import{config as yr}from"dotenv";import{resolve as br}from"node:path";import{$ as te}from"zx";async function he(){try{te.quiet=!0;let t=(await te`git rev-parse --show-toplevel`).stdout.trim();yr({path:br(t,".env"),quiet:!0}),r.info("Loaded .env file from git repository root")}catch{}finally{te.quiet=!1}}await he();var y=new Rr;y.command("merge-dev").description("Merge dev branch into every release branch").option("-a, --all","Select all active release branches").option("-y, --yes","Skip confirmation prompt").action(async e=>{await S({all:e.all,confirmedCommand:e.yes})});y.command("release-list").description("List all release branches").action(async()=>{await L()});y.command("release-create").description("Create new release branches").option("-v, --versions <versions>","Specify the versions to create by comma, e.g. 1.2.5, 1.2.6").option("-y, --yes","Skip confirmation prompt").option("-c, --checkout","Checkout the created branch after creation (only works when creating a single branch)").action(async e=>{await W({versions:e.versions,confirmedCommand:e.yes,checkout:e.checkout})});y.command("release-deploy").description("Deploy any release branch to any environment").option("-v, --version <version>","Specify the version to deploy, e.g. 1.2.5").option("-e, --env <env>","Specify the environment to deploy to, e.g. dev").action(async e=>{await D({version:e.version,env:e.env})});y.command("release-deliver").description("Release a new version to production").option("-v, --version <version>","Specify the version to release, e.g. 1.2.5").option("-y, --yes","Skip confirmation prompt").action(async e=>{await j({version:e.version,confirmedCommand:e.yes})});y.command("worktrees-sync").description("Sync git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").action(async e=>{await q({confirmedCommand:e.yes})});y.command("worktrees-add").description("Add git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").option("-a, --all","Select all active release branches").action(async e=>{await B({confirmedCommand:e.yes,all:e.all})});y.command("worktrees-list").description("List all git worktrees with detailed information").action(async()=>{await M()});y.command("worktrees-remove").description("Remove git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").option("-a, --all","Select all active release branches").action(async e=>{await _({confirmedCommand:e.yes,all:e.all})});await J();y.parse();
15
+ \u{1F33F} Git Worktrees`),r.info("\u2550".repeat(100));let t=e.filter(o=>o.type==="release"),i=e.filter(o=>o.type==="feature");ve("\u{1F680} Releases",t),i.length>0&&t.length>0&&r.info(""),ve("\u2728 Features",i);let s=e.find(o=>o.isCurrent);r.info(`
16
+ ${"\u2550".repeat(100)}`),r.info(`\u{1F4CA} Summary: ${e.length} total worktrees (${t.length} releases, ${i.length} features)`),s&&r.info(`\u{1F4CD} Currently on: ${s.branch}`),r.info("")},ve=(e,t)=>{if(t.length!==0){r.info(`
17
+ ${e}`),r.info("\u2500".repeat(50));for(let[i,s]of t.entries())nr(s),i<t.length-1&&r.info("")}},nr=e=>{let t=e.isCurrent?"\u{1F4CD}":" ",i=ar(e.status),o=`${e.type==="release"?"\u{1F680}":"\u2728"} ${e.branch}`;r.info(`${t} ${i} ${o}`);let n=e.aheadBehind!=="unknown"?` | ${e.aheadBehind}`:"";r.info(` \u{1F4DD} ${e.commit}${n}`),r.info(` \u{1F4AC} ${e.lastCommitMessage}`);let a=e.path.split("/").slice(-2).join("/");r.info(` \u{1F4C1} ${a}`)},ar=e=>{switch(e){case"clean":return"\u2705";case"modified":return"\u26A0\uFE0F ";case"dirty":return"\u{1F534}";default:return"\u2753"}},cr={name:"worktrees-list",description:"List all git worktrees with detailed information",inputSchema:{},outputSchema:{worktrees:g.array(g.object({branch:g.string(),path:g.string(),commit:g.string(),isCurrent:g.boolean(),type:g.enum(["release","feature"]),status:g.string(),lastCommitMessage:g.string(),aheadBehind:g.string()})).describe("List of all worktrees with details"),totalCount:g.number().describe("Total number of worktrees"),releaseCount:g.number().describe("Number of release worktrees"),featureCount:g.number().describe("Number of feature worktrees")},handler:_};import lr from"@inquirer/checkbox";import mr from"@inquirer/confirm";import pr from"node:process";import{z as F}from"zod";import{$ as ur}from"zx";var G=async e=>{let{confirmedCommand:t,all:i}=e;try{let s=await y("release"),n=`${await R()}${$}`,a=[];i?a=s:a=await lr({required:!0,message:"\u{1F33F} Select release branches",choices:s.map(p=>({name:p.replace("release/v",""),value:p}))}),t||await mr({message:"Are you sure you want to proceed with these worktree changes?"})||(r.info("Operation cancelled. Exiting..."),pr.exit(0));let l=await gr(a,n);dr(l);let m={removedWorktrees:l,count:l.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(s){throw r.error({error:s},"\u274C Error managing worktrees"),s}},gr=async(e,t)=>{let i=[];for(let s of e)try{let o=`${t}/${s}`;await ur`git worktree remove ${o}`,i.push(s)}catch(o){r.error({error:o,branch:s},`\u274C Failed to remove worktree for ${s}`)}return i},dr=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
18
+ `)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},fr={name:"worktrees-remove",description:"Remove selected worktrees",inputSchema:{all:F.boolean().describe("Remove all worktrees without prompting")},outputSchema:{removedWorktrees:F.array(F.string()).describe("List of removed worktree branches"),count:F.number().describe("Number of worktrees removed")},handler:G};import hr from"@inquirer/confirm";import vr from"node:process";import{z as ie}from"zod";import{$ as wr}from"zx";var yr="release/v",z=async e=>{let{confirmedCommand:t}=e;try{let i=await y("release"),o=`${await R()}${$}`,n=await u();t||await hr({message:"Are you sure you want to proceed with these worktree changes?"})||(r.info("Operation cancelled. Exiting..."),vr.exit(0));let{branchesToRemove:c}=br({releasePRsList:n,currentWorktrees:i}),l=await Rr(c,o);kr(l);let m={removedWorktrees:l,count:l.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(i){throw r.error({error:i},"\u274C Error managing worktrees"),i}},br=e=>{let{releasePRsList:t,currentWorktrees:i}=e;return{branchesToRemove:i.filter(n=>n.startsWith(yr)).filter(n=>!t.includes(n))}},Rr=async(e,t)=>{let i=[];for(let s of e)try{let o=`${t}/${s}`;await wr`git worktree remove ${o}`,i.push(s)}catch(o){r.error({error:o,branch:s},`\u274C Failed to remove worktree for ${s}`)}return i},kr=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
19
+ `)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},xr={name:"worktrees-sync",description:"Synchronize worktrees with active release branches",inputSchema:{},outputSchema:{removedWorktrees:ie.array(ie.string()).describe("List of removed worktree branches"),count:ie.number().describe("Number of worktrees removed during sync")},handler:z};import{config as Cr}from"dotenv";import{resolve as $r}from"node:path";import{$ as ne}from"zx";async function ae(){try{ne.quiet=!0;let t=(await ne`git rev-parse --show-toplevel`).stdout.trim();Cr({path:$r(t,".env"),quiet:!0}),r.info("Loaded .env file from git repository root")}catch{}finally{ne.quiet=!1}}await ae();var w=new Pr;w.command("merge-dev").description("Merge dev branch into every release branch").option("-a, --all","Select all active release branches").option("-y, --yes","Skip confirmation prompt").action(async e=>{await W({all:e.all,confirmedCommand:e.yes})});w.command("release-list").description("List all release branches").action(async()=>{await D()});w.command("release-create").description("Create a single release branch").option("-v, --version <version>","Specify the version to create, e.g. 1.2.5").option("-d, --description <description>","Optional description for the Jira version").option("-y, --yes","Skip confirmation prompt").option("--no-checkout","Do not checkout the created branch after creation (checkout is default)").action(async e=>{await V({version:e.version,description:e.description,confirmedCommand:e.yes,checkout:e.checkout})});w.command("release-create-batch").description("Create multiple release branches (batch operation)").option("-v, --versions <versions>","Specify the versions to create by comma, e.g. 1.2.5, 1.2.6").option("-d, --description <description>","Optional description for the Jira versions").option("-y, --yes","Skip confirmation prompt").action(async e=>{await M({versions:e.versions,description:e.description,confirmedCommand:e.yes})});w.command("release-deploy").description("Deploy any release branch to any environment").option("-v, --version <version>","Specify the version to deploy, e.g. 1.2.5").option("-e, --env <env>","Specify the environment to deploy to, e.g. dev").action(async e=>{await B({version:e.version,env:e.env})});w.command("release-deliver").description("Release a new version to production").option("-v, --version <version>","Specify the version to release, e.g. 1.2.5").option("-y, --yes","Skip confirmation prompt").action(async e=>{await L({version:e.version,confirmedCommand:e.yes})});w.command("worktrees-sync").description("Sync git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").action(async e=>{await z({confirmedCommand:e.yes})});w.command("worktrees-add").description("Add git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").option("-a, --all","Select all active release branches").action(async e=>{await q({confirmedCommand:e.yes,all:e.all})});w.command("worktrees-list").description("List all git worktrees with detailed information").action(async()=>{await _()});w.command("worktrees-remove").description("Remove git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").option("-a, --all","Select all active release branches").action(async e=>{await G({confirmedCommand:e.yes,all:e.all})});await N();w.parse();
20
20
  //# sourceMappingURL=cli.js.map