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