infra-kit 0.1.71 → 0.1.74
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 +29 -15
- package/dist/cli.js.map +4 -4
- package/dist/mcp.js +32 -19
- package/dist/mcp.js.map +4 -4
- package/package.json +7 -7
- package/src/commands/doctor/doctor.ts +105 -0
- package/src/commands/doctor/index.ts +1 -0
- package/src/commands/env-clear/env-clear.ts +99 -0
- package/src/commands/env-clear/index.ts +1 -0
- package/src/commands/env-list/env-list.ts +50 -0
- package/src/commands/env-list/index.ts +1 -0
- package/src/commands/env-load/env-load.ts +94 -0
- package/src/commands/env-load/index.ts +1 -0
- package/src/commands/env-status/env-status.ts +97 -0
- package/src/commands/env-status/index.ts +1 -0
- package/src/commands/gh-release-deploy-all/gh-release-deploy-all.ts +1 -13
- package/src/commands/gh-release-deploy-selected/gh-release-deploy-selected.ts +1 -13
- package/src/commands/gh-release-deploy-service/gh-release-deploy-service.ts +1 -14
- package/src/entry/cli.ts +40 -3
- package/src/integrations/doppler/doppler-cli-auth.ts +25 -0
- package/src/integrations/doppler/doppler-project.ts +23 -0
- package/src/integrations/doppler/index.ts +2 -0
- package/src/lib/constants.ts +18 -0
- package/src/lib/load-env/load-env.ts +1 -0
- package/src/mcp/tools/index.ts +8 -0
- package/src/integrations/acli/acli-auth/acli-auth.ts +0 -25
- package/src/integrations/acli/acli-auth/index.ts +0 -1
- package/src/integrations/acli/index.ts +0 -1
package/dist/mcp.js
CHANGED
|
@@ -1,21 +1,34 @@
|
|
|
1
|
-
import{StdioServerTransport as
|
|
2
|
-
`).filter(Boolean),
|
|
1
|
+
import{StdioServerTransport as qt}from"@modelcontextprotocol/sdk/server/stdio.js";import Pr from"node:process";import P from"node:process";import qe from"node:process";import ie from"pino";import Nr from"pino-pretty";var z="/tmp/mcp-infra-kit.log",Ge=()=>{let e=qe.argv.includes("--debug")?"debug":"info",t=ie({level:e},ie.destination({dest:z}));return t.info(`Logger initialized with level: ${e}. Logging to: ${z}`),t},_r=()=>{let e=qe.argv.includes("--debug")?"debug":"info",t=["time","pid","hostname"];return e==="debug"&&t.push("level"),ie({level:e},Nr({ignore:t.join(","),colorize:!0}))},r=_r();var ze=e=>{P.on("SIGINT",()=>{e.info({msg:"Received SIGINT. Shutting down..."}),P.exit(0)}),P.on("SIGTERM",()=>{e.info({msg:"Received SIGTERM. Shutting down..."}),P.exit(0)}),P.on("uncaughtException",t=>{e.fatal({err:t,msg:"Uncaught Exception"}),e.error(`Uncaught Exception! Check ${z}. Shutting down...`),e.flush(),P.exit(1)}),P.on("unhandledRejection",(t,s)=>{e.fatal({reason:t,promise:s,msg:"Unhandled Rejection"}),e.error(`Unhandled Rejection! Check ${z}. Shutting down...`),e.flush(),P.exit(1)})};import{config as Jr}from"dotenv";import{resolve as jr}from"node:path";import{$ as Ke}from"zx";import{$ as He}from"zx";var E=async e=>{let s=(await He`git worktree list`).stdout.split(`
|
|
2
|
+
`).filter(Boolean),n={release:Or,feature:Dr};return s.map(n[e]).filter(o=>o!==null)},Or=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("release/v")?null:`release/${t[0]?.split("/").pop()||""}`},Dr=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("feature/")?null:`feature/${t[0]?.split("/").pop()||""}`},v=async()=>(await He`git rev-parse --show-toplevel`).stdout.trim();var ae=async()=>{try{Ke.quiet=!0;let e=await v();Jr({path:jr(e,".env"),quiet:!0}),r.info("Loaded .env file from git repository root")}catch{}finally{Ke.quiet=!1}};import{McpServer as Ut}from"@modelcontextprotocol/sdk/server/mcp.js";var Xe=async e=>{};var Ye=async e=>{};import le from"node:fs";import Vr from"node:path";import F from"node:process";import{z as pe}from"zod";var b=["dev","arthur","renana","roman","eliran","oriana"],ce={"hulyo-monorepo":"hulyo","travelist-monorepo":"travelist"},_="./node_modules/.cache/infra-kit",V="env-cache.json",O="INFRA_KIT_ENV_CONFIG",M="INFRA_KIT_ENV_PROJECT",L="INFRA_KIT_ENV_LOADED_AT",W="-worktrees";var Qe=async()=>{let e=Vr.join(_,V);if(!F.env[O])return r.error("No loaded environment found. Run `env-load` first."),{content:[{type:"text",text:"No loaded environment found. Run `env-load` first."}]};let n=JSON.parse(le.readFileSync(e,"utf-8")).varNames.filter(i=>i in F.env);if(n.length===0)return le.unlinkSync(e),r.info("Current session is clear, no environment variables to unset."),{content:[{type:"text",text:"Current session is clear, no environment variables to unset."}]};for(let i of n)F.stdout.write(`unset ${i}
|
|
3
|
+
`);F.stdout.write(`unset ${O}
|
|
4
|
+
`),F.stdout.write(`unset ${M}
|
|
5
|
+
`),F.stdout.write(`unset ${L}
|
|
6
|
+
`),le.unlinkSync(e),r.info(`Cleared ${n.length} environment variables`);let o={variableCount:n.length,unsetStatements:n.map(i=>`unset ${i}`)};return{content:[{type:"text",text:JSON.stringify(o,null,2)}],structuredContent:o}},me={name:"env-clear",description:"Clear previously loaded environment variables. Usage: source <(infra-kit env-clear)",inputSchema:{},outputSchema:{variableCount:pe.number().describe("Number of variables cleared"),unsetStatements:pe.array(pe.string()).describe("Unset statements generated")},handler:Qe};import{z as ue}from"zod";import Ze from"node:process";import{$ as er}from"zx";var D=async()=>{try{await er`doppler --version`}catch(e){r.error({error:e},"Error: Doppler CLI is not installed."),r.error("Please install it from: https://docs.doppler.com/docs/install-cli"),Ze.exit(1)}try{await er`doppler me`}catch(e){r.error({error:e},"Error: Doppler CLI is not authenticated."),r.error("Please authenticate by running: doppler login"),Ze.exit(1)}};import Mr from"node:path";var J=async()=>{let e=await v(),t=Mr.basename(e),s=ce[t];if(!s)throw new Error(`Could not determine Doppler project for directory "${t}". Expected one of: ${Object.keys(ce).join(", ")}`);return s};var rr=async()=>{await D();let e=await J();r.info(`Doppler Project: ${e}
|
|
7
|
+
`),r.info("Available Configs:");for(let s of b)r.info(` - ${s}`);let t={project:e,configs:b};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:t}},de={name:"env-list",description:"List available Doppler configs for the detected project",inputSchema:{},outputSchema:{project:ue.string().describe("Detected Doppler project name"),configs:ue.array(ue.string()).describe("Available environment configs")},handler:rr};import tr from"node:fs";import Lr from"node:path";import B from"node:process";import{z as ee}from"zod";import{$ as Wr}from"zx";var or=async e=>{await D();let{config:t}=e,s=await J(),o=(await Wr`doppler secrets download --no-file --format env --project ${s} --config ${t}`).stdout.trim();B.stdout.write(`set -a
|
|
8
|
+
`),B.stdout.write(`${o}
|
|
9
|
+
`),B.stdout.write(`set +a
|
|
10
|
+
`),B.stdout.write(`export ${O}=${t}
|
|
11
|
+
`),B.stdout.write(`export ${M}=${s}
|
|
12
|
+
`),B.stdout.write(`export ${L}=${new Date().toISOString()}
|
|
13
|
+
`);let i=o.split(`
|
|
14
|
+
`).filter(p=>p.includes("=")).map(p=>p.split("=")[0]),l=Lr.join(_,V),a={config:t,loadedAt:new Date().toISOString(),varNames:i};tr.mkdirSync(_,{recursive:!0}),tr.writeFileSync(l,JSON.stringify(a,null,2)),r.info(`Loaded ${i.length} variables from ${s}/${t}`);let m={variableCount:i.length,project:s,config:t};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},fe={name:"env-load",description:"Load environment variables from Doppler for a given config. Usage: source <(infra-kit env-load -c dev)",inputSchema:{config:ee.string().describe("Environment config name to load (e.g. dev, arthur, renana)")},outputSchema:{variableCount:ee.number().describe("Number of variables loaded"),project:ee.string().describe("Doppler project name"),config:ee.string().describe("Doppler config name")},handler:or};import sr from"node:fs";import Fr from"node:path";import re from"node:process";import{z as T}from"zod";var nr=async()=>{await D();let e=await J();r.info(`Doppler Environment Status:
|
|
15
|
+
`),r.info(" Authenticated: yes"),r.info(` Detected Project: ${e}`),r.info(` Available Configs: ${b.join(", ")}`);let t=Fr.join(_,V),s=0,n=0,o=re.env[O]??null,i=re.env[M]??null,l=re.env[L]??null;if(o){if(sr.existsSync(t)){let m=JSON.parse(sr.readFileSync(t,"utf-8"));n=m.varNames.length,s=m.varNames.filter(p=>p in re.env).length}r.info(` Session: ${s} of ${n} vars loaded (project: ${i}, config: ${o}, loaded at: ${l})`)}else r.info(" Session: no env loaded");let a={authenticated:!0,project:e,configs:b,sessionLoadedCount:s,sessionTotalCount:n,sessionConfig:o,sessionProject:i,sessionLoadedAt:l};return{content:[{type:"text",text:JSON.stringify(a,null,2)}],structuredContent:a}},ge={name:"env-status",description:"Show Doppler authentication status and detected project info",inputSchema:{},outputSchema:{authenticated:T.boolean().describe("Whether the user is authenticated"),project:T.string().describe("Detected Doppler project name"),configs:T.array(T.string()).describe("Available environment configs"),sessionLoadedCount:T.number().describe("Number of cached vars active in the current session"),sessionTotalCount:T.number().describe("Total number of cached var names"),sessionConfig:T.string().nullable().describe("Doppler config name of the loaded session"),sessionProject:T.string().nullable().describe("Doppler project name of the loaded session"),sessionLoadedAt:T.string().nullable().describe("ISO 8601 timestamp of when the env was loaded")},handler:nr};import qr from"@inquirer/checkbox";import Gr from"@inquirer/confirm";import zr from"node:process";import{z as U}from"zod";import{$ as C}from"zx";import{$ as fs}from"zx";import ir from"node:process";import{$ as k}from"zx";var he=e=>e.replace("release/","").slice(1).split(".").map(Number),ve=e=>[...e].sort((t,s)=>{let[n,o,i]=he(t),[l,a,m]=he(s);return n!==l?(n??0)-(l??0):o!==a?(o??0)-(a??0):(i??0)-(m??0)});var h=async()=>{try{let e=await k`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..."),ir.exit(1));let s=t.map(n=>n.headRefName);return ve(s)}catch(e){r.error({error:e},"\u274C Error fetching release PRs"),ir.exit(1)}},te=async e=>{let{version:t,jiraVersionUrl:s}=e,n=`release/v${t}`;try{k.quiet=!0,await k`git switch dev`,await k`git pull origin dev`,await k`git checkout -b ${n}`,await k`git push -u origin ${n}`,await k`git commit --allow-empty-message --allow-empty --message ''`,await k`git push origin ${n}`;let i=(await k`gh pr create --title "Release v${t}" --body "${s} \n" --base dev --head ${n}`).stdout.trim();return await k`git switch dev`,k.quiet=!1,{branchName:n,prUrl:i}}catch(o){throw r.error({error:o,branchName:n},`Error creating release branch ${n}`),o}};var Ur=()=>{let e="",t=[],s=!1;return{start(n){e=n,t=[],s=!1},setInteractive(){s=!0},addOption(n,o){t.push({flag:n,value:o})},print(){if(!s||t.length===0)return;let n=t.map(o=>typeof o.value=="boolean"?o.value?o.flag:"":Array.isArray(o.value)?`${o.flag} "${o.value.join(", ")}"`:`${o.flag} ${o.value}`).filter(Boolean).join(" ");r.info(""),r.info("# Equivalent command:"),r.info(`pnpm exec infra-kit ${e} ${n}`)},reset(){e="",t=[],s=!1}}},c=Ur();var ar=async e=>{let{all:t,confirmedCommand:s}=e;c.start("merge-dev");let n=await h();if(n.length===0)return r.info("\u2139\uFE0F No open release branches found"),c.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 o=[];t?o=n:(c.setInteractive(),o=await qr({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(p=>({name:p.replace("release/v",""),value:p}))}));let i=o.length===n.length;i?c.addOption("--all",!0):c.addOption("--branches",o);let l=s?!0:await Gr({message:`Are you sure you want to merge dev into these branches: ${o.join(", ")}?`});s||c.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),zr.exit(0)),i&&c.addOption("--yes",!0),C.quiet=!0,await C`git fetch origin`,await C`git switch dev`,await C`git pull origin dev`;let a=[];for(let p of o)await Hr(p)||a.push(p);if(C.quiet=!1,a.length>0){r.info(`
|
|
3
16
|
\u26A0\uFE0F ${a.length} branch(es) failed to merge automatically.
|
|
4
|
-
`),
|
|
5
|
-
`),
|
|
6
|
-
`);throw new Error(l)}let c=Number.parseInt(s,10);if(Number.isNaN(c))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${s}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:r,projectId:c,email:i}},re=async()=>{try{return await N()}catch(e){return t.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var Ne=async e=>{let{version:r,confirmedCommand:s}=e;n.start("release-deliver");let i=await v(),o="";r?o=`release/v${r}`:(n.setInteractive(),o=await br({message:"\u{1F33F} Select release branch",choices:i.map(a=>({name:a.replace("release/v",""),value:a}))}));let c=o.replace("release/v","");n.addOption("--version",c),i.includes(o)||(t.error(`\u274C Release branch ${o} not found in open PRs. Exiting...`),te.exit(1));let l=s?!0:await wr({message:`Are you sure you want to deliver version ${o} to production?`});s||n.setInteractive(),l||(t.info("Operation cancelled. Exiting..."),te.exit(0)),n.addOption("--yes",!0);try{S.quiet=!0,await S`gh pr merge ${o} --squash --admin --delete-branch`,await S`gh pr create --base main --head dev --title "Release v${o.replace("release/v","")} (RC)" --body ""`,await S`gh pr merge dev --squash --admin`,S.quiet=!1,await S`gh workflow run deploy-all.yml --ref main -f environment=prod`,S.quiet=!0,await S`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`,S.quiet=!1;let a=await re();if(a)try{let m=o.replace("release/","");await ee({versionName:m},a)}catch(m){t.error({error:m},"Failed to deliver Jira release (non-blocking)")}else t.info("\u{1F514} Jira is not configured, skipping Jira release delivery");t.info(`Successfully delivered ${o} to production!`),n.print();let p={releaseBranch:o,version:o.replace("release/v",""),success:!0};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}}catch(a){t.error({error:a},"\u274C Error merging release branch into dev"),te.exit(1)}},oe={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:Ne};import Rr from"@inquirer/confirm";import je from"@inquirer/select";import se from"node:process";import{z as A}from"zod";import{$ as ie}from"zx";var C=["dev","arthur","renana","roman","eliran","oriana"],j="-worktrees";var Me=async e=>{let{version:r,env:s,skipTerraform:i}=e;n.start("release-deploy-all");let o=["dev"],c=await v();o.push(...c);let l="";r?l=r==="dev"?"dev":`release/v${r}`:(n.setInteractive(),l=await je({message:"\u{1F33F} Select release branch",choices:o.map(d=>({name:d.replace("release/v",""),value:d}))}));let a=l==="dev"?"dev":l.replace("release/v","");n.addOption("--version",a),o.includes(l)||(t.error(`\u274C Release branch ${l} not found in open PRs. Exiting...`),se.exit(1));let p="";s?p=s:(n.setInteractive(),p=await je({message:"\u{1F9EA} Select environment",choices:C.map(d=>({name:d,value:d}))})),n.addOption("--env",p),C.includes(p)||(t.error(`\u274C Invalid environment: ${p}. Exiting...`),se.exit(1));let m=!1;typeof i<"u"?m=i:(n.setInteractive(),m=await Rr({message:"\u{1F3D7}\uFE0F Skip terraform deployment?",default:!1})),m&&n.addOption("--skip-terraform",!0);try{ie.quiet=!0,await ie`gh workflow run deploy-all.yml --ref ${l} -f environment=${p} ${m?["-f","skip_terraform_deploy=true"]:[]}`,ie.quiet=!1,t.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${l} and environment: ${p}`),n.print();let u={releaseBranch:l,version:l.replace("release/v",""),environment:p,skipTerraformDeploy:m,success:!0};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(d){t.error({error:d},"\u274C Error launching workflow"),se.exit(1)}},ne={name:"gh-release-deploy-all",description:"Deploy a release branch to a specified environment",inputSchema:{version:A.string().describe('Version to deploy (e.g., "1.2.5")'),env:A.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),skipTerraform:A.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:A.string().describe("The release branch that was deployed"),version:A.string().describe("The version that was deployed"),environment:A.string().describe("The environment deployed to"),skipTerraformDeploy:A.boolean().describe("Whether terraform deployment was skipped"),success:A.boolean().describe("Whether the deployment was successful")},handler:Me};import kr from"@inquirer/checkbox";import xr from"@inquirer/confirm";import De from"@inquirer/select";import $r from"node:fs/promises";import{resolve as Tr}from"node:path";import M from"node:process";import Sr from"yaml";import{z as R}from"zod";import{$ as ae}from"zx";var We=async e=>{let{version:r,env:s,services:i,skipTerraform:o}=e;n.start("release-deploy-selected");let c=["dev"],l=await v();c.push(...l);let a="";r?a=r==="dev"?"dev":`release/v${r}`:(n.setInteractive(),a=await De({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)||(t.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),M.exit(1));let m="";s?m=s:(n.setInteractive(),m=await De({message:"\u{1F9EA} Select environment",choices:C.map(g=>({name:g,value:g}))})),n.addOption("--env",m),C.includes(m)||(t.error(`\u274C Invalid environment: ${m}. Exiting...`),M.exit(1));let d=await Cr();d.length===0&&(t.error("\u274C No services found in workflow file. Exiting..."),M.exit(1));let u=[];i&&i.length>0?u=i:(n.setInteractive(),u=await kr({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:d.map(g=>({name:g,value:g}))})),n.addOption("--services",u),u.length===0&&(t.error("\u274C No services selected. Exiting..."),M.exit(1));let h=u.filter(g=>!d.includes(g));h.length>0&&(t.error(`\u274C Invalid services: ${h.join(", ")}. Available services: ${d.join(", ")}`),M.exit(1));let f=!1;typeof o<"u"?f=o:(n.setInteractive(),f=await xr({message:"\u{1F3D7}\uFE0F Skip terraform deployment?",default:!1})),f&&n.addOption("--skip-terraform",!0);try{ae.quiet=!0;let g=u.flatMap(or=>["-f",`${or}=true`]);await ae`gh workflow run deploy-selected-services.yml --ref ${a} -f environment=${m} ${g} ${f?["-f","skip_terraform_deploy=true"]:[]}`,ae.quiet=!1,t.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${a}, environment: ${m}, services: ${u.join(", ")}`),n.print();let $e={releaseBranch:a,version:a.replace("release/v",""),environment:m,services:u,skipTerraformDeploy:f,success:!0};return{content:[{type:"text",text:JSON.stringify($e,null,2)}],structuredContent:$e}}catch(g){t.error({error:g},"\u274C Error launching workflow"),M.exit(1)}},Cr=async()=>{let e=await w(),r=Tr(e,".github/workflows/deploy-selected-services.yml"),s=await $r.readFile(r,"utf-8"),o=Sr.parse(s).on.workflow_dispatch.inputs,c=[];for(let[l,a]of Object.entries(o))a.type==="boolean"&&l!=="skip_terraform_deploy"&&c.push(l);return c},ce={name:"gh-release-deploy-selected",description:"Deploy selected services from a release branch to a specified environment",inputSchema:{version:R.string().describe('Version to deploy (e.g., "1.2.5")'),env:R.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),services:R.array(R.string()).describe('List of services to deploy (e.g., ["client-be", "client-fe"])'),skipTerraform:R.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:R.string().describe("The release branch that was deployed"),version:R.string().describe("The version that was deployed"),environment:R.string().describe("The environment deployed to"),services:R.array(R.string()).describe("The services that were deployed"),skipTerraformDeploy:R.boolean().describe("Whether terraform deployment was skipped"),success:R.boolean().describe("Whether the deployment was successful")},handler:We};import Er from"@inquirer/confirm";import le from"@inquirer/select";import Pr from"node:fs/promises";import{resolve as Ar}from"node:path";import G from"node:process";import Ir from"yaml";import{z as T}from"zod";import{$ as me}from"zx";var Be=async e=>{let{version:r,env:s,service:i,skipTerraform:o}=e;n.start("release-deploy-service");let c=["dev"],l=await v();c.push(...l);let a="";r?a=r==="dev"?"dev":`release/v${r}`:(n.setInteractive(),a=await le({message:"\u{1F33F} Select release branch",choices:c.map(f=>({name:f.replace("release/v",""),value:f}))}));let p=a==="dev"?"dev":a.replace("release/v","");n.addOption("--version",p),c.includes(a)||(t.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),G.exit(1));let m="";s?m=s:(n.setInteractive(),m=await le({message:"\u{1F9EA} Select environment",choices:C.map(f=>({name:f,value:f}))})),n.addOption("--env",m),C.includes(m)||(t.error(`\u274C Invalid environment: ${m}. Exiting...`),G.exit(1));let d=await Jr(),u="";i?u=i:(n.setInteractive(),u=await le({message:"\u{1F680} Select service to deploy",choices:d.map(f=>({name:f,value:f}))})),n.addOption("--service",u),d.includes(u)||(t.error(`\u274C Invalid service: ${u}. Available services: ${d.join(", ")}`),G.exit(1));let h=!1;typeof o<"u"?h=o:(n.setInteractive(),h=await Er({message:"\u{1F3D7}\uFE0F Skip terraform deployment?",default:!1})),h&&n.addOption("--skip-terraform",!0);try{me.quiet=!0,await me`gh workflow run deploy-single-service.yml --ref ${a} -f environment=${m} -f service=${u} ${h?["-f","skip_terraform_deploy=true"]:[]}`,me.quiet=!1,t.info(`Successfully launched deploy-single-service workflow_dispatch for release branch: ${a}, environment: ${m}, service: ${u}`),n.print();let g={releaseBranch:a,version:a.replace("release/v",""),environment:m,service:u,skipTerraformDeploy:h,success:!0};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(f){t.error({error:f},"\u274C Error launching workflow"),G.exit(1)}},Jr=async()=>{let e=await w(),r=Ar(e,".github/workflows/deploy-single-service.yml"),s=await Pr.readFile(r,"utf-8");return Ir.parse(s).on.workflow_dispatch.inputs.service.options},pe={name:"gh-release-deploy-service",description:"Deploy a specific service in a release branch to a specified environment",inputSchema:{version:T.string().describe('Version to deploy (e.g., "1.2.5")'),env:T.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),service:T.string().describe('Service to deploy (e.g., "client-be", "client-fe")'),skipTerraform:T.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:T.string().describe("The release branch that was deployed"),version:T.string().describe("The version that was deployed"),environment:T.string().describe("The environment deployed to"),service:T.string().describe("The service that was deployed"),skipTerraformDeploy:T.boolean().describe("Whether terraform deployment was skipped"),success:T.boolean().describe("Whether the deployment was successful")},handler:Be};import{z as ue}from"zod";var Le=async()=>{let r=(await v()).map(i=>i.replace("release/",""));t.info(`All release branches:
|
|
7
|
-
`),
|
|
8
|
-
${
|
|
9
|
-
`)}`);let s={releases:
|
|
10
|
-
`)}catch(g){let
|
|
11
|
-
`)}let d=
|
|
12
|
-
`),
|
|
13
|
-
`)),
|
|
14
|
-
`).filter(Boolean);return s.length===0?"clean":s.length<=3?"modified":"dirty"}catch{return"unknown"}},
|
|
15
|
-
\u{1F33F} Git Worktrees`),
|
|
16
|
-
\u{1F33F} Git Worktrees`),
|
|
17
|
-
${"\u2550".repeat(100)}`),
|
|
18
|
-
${e}`),
|
|
19
|
-
`)),
|
|
20
|
-
`)),
|
|
17
|
+
`),r.info(`\u{1F4CB} Manual merge script for failed branches:
|
|
18
|
+
`),r.info("```bash");for(let p of a)r.info(`# Phase #1: Merge dev into ${p}`),r.info(`git switch ${p} && git pull origin ${p} && git merge origin/dev`),r.info("# Phase #2:Resolve conflicts if any, then:"),r.info(`git push origin ${p} && git switch dev`);r.info(`\u2705 ${o.length-a.length}/${o.length} merges completed successfully.`)}else r.info("\u2705 All merges completed successfully!");c.print();let m={successfulMerges:o.length-a.length,failedMerges:a.length,failedBranches:a,totalBranches:o.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},Hr=async e=>{try{return await C`git switch ${e}`,await C`git pull origin ${e}`,await C`git merge origin/dev --no-edit`,await C`git push origin ${e}`,await C`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 C`git reset --merge HEAD~1`,!1}},ye={name:"gh-merge-dev",description:"Merge dev branch into selected release branches",inputSchema:{all:U.boolean().describe("Merge dev into all release branches without prompting")},outputSchema:{successfulMerges:U.number().describe("Number of successful merges"),failedMerges:U.number().describe("Number of failed merges"),failedBranches:U.array(U.string()).describe("List of branches that failed to merge"),totalBranches:U.number().describe("Total number of branches processed")},handler:ar};import Qr from"@inquirer/confirm";import Zr from"@inquirer/select";import xe from"node:process";import{z as oe}from"zod";import{$ as S}from"zx";import H from"node:process";var we=async(e,t)=>{try{let{baseUrl:s,token:n,email:o,projectId:i}=t,l={name:e.name,projectId:e.projectId||i,description:e.description||"",released:e.released||!1,archived:e.archived||!1},a=`${s}/rest/api/3/version`,m=btoa(`${o}:${n}`),p=await fetch(a,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${m}`},body:JSON.stringify(l)});if(!p.ok){let u=await p.text();throw r.error({status:p.status,statusText:p.statusText,error:u},"Failed to create Jira version"),new Error(`HTTP ${p.status}: ${p.statusText}`)}return{success:!0,version:await p.json()}}catch(s){throw r.error({error:s},"Error creating Jira version"),s}},Kr=async e=>{try{let{baseUrl:t,token:s,email:n,projectId:o}=e,i=`${t}/rest/api/3/project/${o}/versions`,l=btoa(`${n}:${s}`),a=await fetch(i,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${l}`}});if(!a.ok){let p=await a.text();throw r.error({status:a.status,statusText:a.statusText,error:p},"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}},Xr=async(e,t)=>{try{return(await Kr(t)).find(o=>o.name===e)||null}catch(s){throw r.error({error:s,versionName:e},"Error finding Jira version by name"),s}},Yr=async(e,t)=>{try{let{baseUrl:s,token:n,email:o}=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 l=`${s}/rest/api/3/version/${e.versionId}`,a=btoa(`${o}:${n}`),m=await fetch(l,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${a}`},body:JSON.stringify(i)});if(!m.ok){let d=await m.text();throw r.error({status:m.status,statusText:m.statusText,error:d},"Failed to update Jira version"),new Error(`HTTP ${m.status}: ${m.statusText}`)}return{success:!0,version:await m.json()}}catch(s){throw r.error({error:s},"Error updating Jira version"),s}},be=async(e,t)=>{try{let{versionName:s}=e,n=await Xr(s,t);if(!n)throw r.error({versionName:s},"Jira version not found"),new Error(`Version "${s}" not found in Jira project`);return await Yr({versionId:n.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},t)}catch(s){throw r.error({error:s},"Error delivering Jira release"),s}},q=async()=>{let e=H.env.JIRA_BASE_URL,t=H.env.JIRA_TOKEN||H.env.JIRA_API_TOKEN,s=H.env.JIRA_PROJECT_ID,n=H.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)"),s||o.push("JIRA_PROJECT_ID (numeric project ID)"),n||o.push("JIRA_EMAIL (your Jira email address)"),o.length>0){let l=["Jira configuration is required but incomplete.","Please configure the following environment variables:",...o.map(a=>` - ${a}`),"","You can set these in your .env file or as environment variables."].join(`
|
|
19
|
+
`);throw new Error(l)}let i=Number.parseInt(s,10);if(Number.isNaN(i))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${s}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:t,projectId:i,email:n}},Re=async()=>{try{return await q()}catch(e){return r.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var cr=async e=>{let{version:t,confirmedCommand:s}=e;c.start("release-deliver");let n=await h(),o="";t?o=`release/v${t}`:(c.setInteractive(),o=await Zr({message:"\u{1F33F} Select release branch",choices:n.map(a=>({name:a.replace("release/v",""),value:a}))}));let i=o.replace("release/v","");c.addOption("--version",i),n.includes(o)||(r.error(`\u274C Release branch ${o} not found in open PRs. Exiting...`),xe.exit(1));let l=s?!0:await Qr({message:`Are you sure you want to deliver version ${o} to production?`});s||c.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),xe.exit(0)),c.addOption("--yes",!0);try{S.quiet=!0,await S`gh pr merge ${o} --squash --admin --delete-branch`,await S`gh pr create --base main --head dev --title "Release v${o.replace("release/v","")} (RC)" --body ""`,await S`gh pr merge dev --squash --admin`,S.quiet=!1,await S`gh workflow run deploy-all.yml --ref main -f environment=prod`,S.quiet=!0,await S`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`,S.quiet=!1;let a=await Re();if(a)try{let p=o.replace("release/","");await be({versionName:p},a)}catch(p){r.error({error:p},"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!`),c.print();let m={releaseBranch:o,version:o.replace("release/v",""),success:!0};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(a){r.error({error:a},"\u274C Error merging release branch into dev"),xe.exit(1)}},ke={name:"gh-release-deliver",description:"Deliver a release branch to production",inputSchema:{version:oe.string().describe('Version to deliver to production (e.g., "1.2.5")')},outputSchema:{releaseBranch:oe.string().describe("The release branch that was delivered"),version:oe.string().describe("The version that was delivered"),success:oe.boolean().describe("Whether the delivery was successful")},handler:cr};import lr from"@inquirer/select";import Ce from"node:process";import{z as I}from"zod";import{$ as Ee}from"zx";var pr=async e=>{let{version:t,env:s,skipTerraform:n}=e;c.start("release-deploy-all");let o=["dev"],i=await h();o.push(...i);let l="";t?l=t==="dev"?"dev":`release/v${t}`:(c.setInteractive(),l=await lr({message:"\u{1F33F} Select release branch",choices:o.map(d=>({name:d.replace("release/v",""),value:d}))}));let a=l==="dev"?"dev":l.replace("release/v","");c.addOption("--version",a),o.includes(l)||(r.error(`\u274C Release branch ${l} not found in open PRs. Exiting...`),Ce.exit(1));let m="";s?m=s:(c.setInteractive(),m=await lr({message:"\u{1F9EA} Select environment",choices:b.map(d=>({name:d,value:d}))})),c.addOption("--env",m),b.includes(m)||(r.error(`\u274C Invalid environment: ${m}. Exiting...`),Ce.exit(1));let p=n??!1;p&&c.addOption("--skip-terraform",!0);try{Ee.quiet=!0,await Ee`gh workflow run deploy-all.yml --ref ${l} -f environment=${m} ${p?["-f","skip_terraform_deploy=true"]:[]}`,Ee.quiet=!1,r.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${l} and environment: ${m}`),c.print();let u={releaseBranch:l,version:l.replace("release/v",""),environment:m,skipTerraformDeploy:p,success:!0};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(d){r.error({error:d},"\u274C Error launching workflow"),Ce.exit(1)}},$e={name:"gh-release-deploy-all",description:"Deploy a release branch to a specified environment",inputSchema:{version:I.string().describe('Version to deploy (e.g., "1.2.5")'),env:I.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),skipTerraform:I.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:I.string().describe("The release branch that was deployed"),version:I.string().describe("The version that was deployed"),environment:I.string().describe("The environment deployed to"),skipTerraformDeploy:I.boolean().describe("Whether terraform deployment was skipped"),success:I.boolean().describe("Whether the deployment was successful")},handler:pr};import et from"@inquirer/checkbox";import mr from"@inquirer/select";import rt from"node:fs/promises";import{resolve as tt}from"node:path";import G from"node:process";import ot from"yaml";import{z as x}from"zod";import{$ as Te}from"zx";var ur=async e=>{let{version:t,env:s,services:n,skipTerraform:o}=e;c.start("release-deploy-selected");let i=["dev"],l=await h();i.push(...l);let a="";t?a=t==="dev"?"dev":`release/v${t}`:(c.setInteractive(),a=await mr({message:"\u{1F33F} Select release branch",choices:i.map(g=>({name:g.replace("release/v",""),value:g}))}));let m=a==="dev"?"dev":a.replace("release/v","");c.addOption("--version",m),i.includes(a)||(r.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),G.exit(1));let p="";s?p=s:(c.setInteractive(),p=await mr({message:"\u{1F9EA} Select environment",choices:b.map(g=>({name:g,value:g}))})),c.addOption("--env",p),b.includes(p)||(r.error(`\u274C Invalid environment: ${p}. Exiting...`),G.exit(1));let d=await st();d.length===0&&(r.error("\u274C No services found in workflow file. Exiting..."),G.exit(1));let u=[];n&&n.length>0?u=n:(c.setInteractive(),u=await et({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:d.map(g=>({name:g,value:g}))})),c.addOption("--services",u),u.length===0&&(r.error("\u274C No services selected. Exiting..."),G.exit(1));let y=u.filter(g=>!d.includes(g));y.length>0&&(r.error(`\u274C Invalid services: ${y.join(", ")}. Available services: ${d.join(", ")}`),G.exit(1));let f=o??!1;f&&c.addOption("--skip-terraform",!0);try{Te.quiet=!0;let g=u.flatMap(Ir=>["-f",`${Ir}=true`]);await Te`gh workflow run deploy-selected-services.yml --ref ${a} -f environment=${p} ${g} ${f?["-f","skip_terraform_deploy=true"]:[]}`,Te.quiet=!1,r.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${a}, environment: ${p}, services: ${u.join(", ")}`),c.print();let Ue={releaseBranch:a,version:a.replace("release/v",""),environment:p,services:u,skipTerraformDeploy:f,success:!0};return{content:[{type:"text",text:JSON.stringify(Ue,null,2)}],structuredContent:Ue}}catch(g){r.error({error:g},"\u274C Error launching workflow"),G.exit(1)}},st=async()=>{let e=await v(),t=tt(e,".github/workflows/deploy-selected-services.yml"),s=await rt.readFile(t,"utf-8"),o=ot.parse(s).on.workflow_dispatch.inputs,i=[];for(let[l,a]of Object.entries(o))a.type==="boolean"&&l!=="skip_terraform_deploy"&&i.push(l);return i},Se={name:"gh-release-deploy-selected",description:"Deploy selected services from a release branch to a specified environment",inputSchema:{version:x.string().describe('Version to deploy (e.g., "1.2.5")'),env:x.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),services:x.array(x.string()).describe('List of services to deploy (e.g., ["client-be", "client-fe"])'),skipTerraform:x.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:x.string().describe("The release branch that was deployed"),version:x.string().describe("The version that was deployed"),environment:x.string().describe("The environment deployed to"),services:x.array(x.string()).describe("The services that were deployed"),skipTerraformDeploy:x.boolean().describe("Whether terraform deployment was skipped"),success:x.boolean().describe("Whether the deployment was successful")},handler:ur};import Ae from"@inquirer/select";import nt from"node:fs/promises";import{resolve as it}from"node:path";import se from"node:process";import at from"yaml";import{z as $}from"zod";import{$ as Pe}from"zx";var dr=async e=>{let{version:t,env:s,service:n,skipTerraform:o}=e;c.start("release-deploy-service");let i=["dev"],l=await h();i.push(...l);let a="";t?a=t==="dev"?"dev":`release/v${t}`:(c.setInteractive(),a=await Ae({message:"\u{1F33F} Select release branch",choices:i.map(f=>({name:f.replace("release/v",""),value:f}))}));let m=a==="dev"?"dev":a.replace("release/v","");c.addOption("--version",m),i.includes(a)||(r.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),se.exit(1));let p="";s?p=s:(c.setInteractive(),p=await Ae({message:"\u{1F9EA} Select environment",choices:b.map(f=>({name:f,value:f}))})),c.addOption("--env",p),b.includes(p)||(r.error(`\u274C Invalid environment: ${p}. Exiting...`),se.exit(1));let d=await ct(),u="";n?u=n:(c.setInteractive(),u=await Ae({message:"\u{1F680} Select service to deploy",choices:d.map(f=>({name:f,value:f}))})),c.addOption("--service",u),d.includes(u)||(r.error(`\u274C Invalid service: ${u}. Available services: ${d.join(", ")}`),se.exit(1));let y=o??!1;y&&c.addOption("--skip-terraform",!0);try{Pe.quiet=!0,await Pe`gh workflow run deploy-single-service.yml --ref ${a} -f environment=${p} -f service=${u} ${y?["-f","skip_terraform_deploy=true"]:[]}`,Pe.quiet=!1,r.info(`Successfully launched deploy-single-service workflow_dispatch for release branch: ${a}, environment: ${p}, service: ${u}`),c.print();let g={releaseBranch:a,version:a.replace("release/v",""),environment:p,service:u,skipTerraformDeploy:y,success:!0};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(f){r.error({error:f},"\u274C Error launching workflow"),se.exit(1)}},ct=async()=>{let e=await v(),t=it(e,".github/workflows/deploy-single-service.yml"),s=await nt.readFile(t,"utf-8");return at.parse(s).on.workflow_dispatch.inputs.service.options},Ie={name:"gh-release-deploy-service",description:"Deploy a specific service in a release branch to a specified environment",inputSchema:{version:$.string().describe('Version to deploy (e.g., "1.2.5")'),env:$.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),service:$.string().describe('Service to deploy (e.g., "client-be", "client-fe")'),skipTerraform:$.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:$.string().describe("The release branch that was deployed"),version:$.string().describe("The version that was deployed"),environment:$.string().describe("The environment deployed to"),service:$.string().describe("The service that was deployed"),skipTerraformDeploy:$.boolean().describe("Whether terraform deployment was skipped"),success:$.boolean().describe("Whether the deployment was successful")},handler:dr};import{z as Ne}from"zod";var fr=async()=>{let t=(await h()).map(n=>n.replace("release/",""));r.info(`All release branches:
|
|
20
|
+
`),r.info(`
|
|
21
|
+
${t.join(`
|
|
22
|
+
`)}`);let s={releases:t,count:t.length};return{content:[{type:"text",text:JSON.stringify(s,null,2)}],structuredContent:s}},_e={name:"gh-release-list",description:"List all open release branches",inputSchema:{},outputSchema:{releases:Ne.array(Ne.string()).describe("List of all release branches"),count:Ne.number().describe("Number of release branches")},handler:fr};import gr from"@inquirer/confirm";import hr from"node:process";import{z as N}from"zod";import{$ as Oe,question as vr}from"zx";import{$ as K}from"zx";var X=async()=>{K.quiet=!0,await K`git fetch origin`,await K`git switch dev`,await K`git pull origin dev`,K.quiet=!1},Y=async(e,t,s)=>{let n=`v${e}`,o=await we({name:n,projectId:t.projectId,description:s||"",released:!1,archived:!1},t),i=`${t.baseUrl}/projects/${o.version.projectId}/versions/${o.version.id}/tab/release-report-all-issues`,l=await te({version:e,jiraVersionUrl:i});return{version:e,branchName:l.branchName,prUrl:l.prUrl,jiraVersionUrl:i}};var yr=async e=>{let{version:t,description:s,confirmedCommand:n,checkout:o}=e;c.start("release-create");let i=t,l=s,a=o,m=await q();i||(c.setInteractive(),i=await vr("Enter version (e.g. 1.2.5): ")),(!i||i.trim()==="")&&(r.error("No version provided. Exiting..."),hr.exit(1));let p=i.trim();c.addOption("--version",p),l===void 0&&(c.setInteractive(),l=await vr("Enter description (optional, press Enter to skip): "),l.trim()===""&&(l="")),l&&c.addOption("--description",l);let d=n?!0:await gr({message:`Are you sure you want to create release branch for version ${p}?`});n||c.setInteractive(),d||(r.info("Operation cancelled. Exiting..."),hr.exit(0)),c.addOption("--yes",!0),await X();let u=await Y(p,m,l);r.info(`\u2705 Successfully created release: v${p}`),r.info(`\u{1F517} GitHub PR: ${u.prUrl}`),r.info(`\u{1F517} Jira Version: ${u.jiraVersionUrl}`),a===void 0&&(c.setInteractive(),a=await gr({message:`Do you want to checkout to the created branch ${u.branchName}?`,default:!0})),a||c.addOption("--no-checkout",!0),a&&(Oe.quiet=!0,await Oe`git switch ${u.branchName}`,Oe.quiet=!1,r.info(`\u{1F504} Switched to branch ${u.branchName}`)),c.print();let y={version:p,branchName:u.branchName,prUrl:u.prUrl,jiraVersionUrl:u.jiraVersionUrl,isCheckedOut:a};return{content:[{type:"text",text:JSON.stringify(y,null,2)}],structuredContent:y}},De={name:"release-create",description:"Create a single release branch for specified version with Jira version creation",inputSchema:{version:N.string().describe('Version to create (e.g., "1.2.5")'),description:N.string().optional().describe("Optional description for the Jira version"),checkout:N.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:N.string().describe("Version number"),branchName:N.string().describe("Release branch name"),prUrl:N.string().describe("GitHub PR URL"),jiraVersionUrl:N.string().describe("Jira version URL"),isCheckedOut:N.boolean().describe("Whether the branch was checked out")},handler:yr};import lt from"@inquirer/confirm";import wr from"node:process";import{z as w}from"zod";import{question as pt}from"zx";var br=async e=>{let{versions:t,description:s,confirmedCommand:n}=e;c.start("release-create-batch");let o=t,i=await q();o||(c.setInteractive(),o=await pt("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let l=o.split(",").map(f=>f.trim());c.addOption("--versions",l.join(", ")),l.length===0&&(r.error("No versions provided. Exiting..."),wr.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=n?!0:await lt({message:`Are you sure you want to create release branches for these versions: ${l.join(", ")}?`});n||c.setInteractive(),a||(r.info("Operation cancelled. Exiting..."),wr.exit(0)),c.addOption("--yes",!0),s&&c.addOption("--description",s),await X();let m=[],p=[];for(let f of l)try{let g=await Y(f,i,s);m.push(g),r.info(`\u2705 Successfully created release: v${f}`),r.info(`\u{1F517} GitHub PR: ${g.prUrl}`),r.info(`\u{1F517} Jira Version: ${g.jiraVersionUrl}
|
|
23
|
+
`)}catch(g){let A=g instanceof Error?g.message:String(g);p.push({version:f,error:A}),r.error(`\u274C Failed to create release: v${f}`),r.error(` Error: ${A}
|
|
24
|
+
`)}let d=m.length,u=p.length;d===l.length?r.info(`\u2705 All ${l.length} release branches were created successfully.`):d>0?(r.warn(`\u26A0\uFE0F ${d} of ${l.length} release branches were created successfully.`),r.warn(`\u274C ${u} release(s) failed.`)):r.error(`\u274C All ${l.length} release branches failed to create.`),c.print();let y={createdBranches:m.map(f=>f.branchName),successCount:d,failureCount:u,releases:m,failedReleases:p};return{content:[{type:"text",text:JSON.stringify(y,null,2)}],structuredContent:y}},Je={name:"release-create-batch",description:"Create multiple release branches for specified versions with Jira version creation (batch operation)",inputSchema:{versions:w.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6")'),description:w.string().optional().describe("Optional description for the Jira versions")},outputSchema:{createdBranches:w.array(w.string()).describe("List of created release branches"),successCount:w.number().describe("Number of releases created successfully"),failureCount:w.number().describe("Number of releases that failed"),releases:w.array(w.object({version:w.string().describe("Version number"),branchName:w.string().describe("Release branch name"),prUrl:w.string().describe("GitHub PR URL"),jiraVersionUrl:w.string().describe("Jira version URL")})).describe("Detailed information for each created release with URLs"),failedReleases:w.array(w.object({version:w.string().describe("Version number that failed"),error:w.string().describe("Error message")})).describe("List of releases that failed with error messages")},handler:br};import mt from"@inquirer/checkbox";import Rr from"@inquirer/confirm";import{copyFileSync as ut,existsSync as dt}from"node:fs";import ft from"node:process";import{z as Q}from"zod";import{$ as je}from"zx";var gt="feature",ht="release",vt="release/v",kr=async e=>{let{confirmedCommand:t,all:s,cursor:n}=e;c.start("worktrees-add");try{let o=await E("release"),i=await v(),l=`${i}${W}`;await xr(`${l}/${ht}`),await xr(`${l}/${gt}`);let a=await h();if(a.length===0)return r.info("\u2139\uFE0F No open release branches found"),c.print(),{content:[{type:"text",text:JSON.stringify({createdWorktrees:[],count:0},null,2)}],structuredContent:{createdWorktrees:[],count:0}};let m=[];s?m=a:(c.setInteractive(),m=await mt({required:!0,message:"\u{1F33F} Select release branches",choices:a.map(A=>({name:A.replace("release/v",""),value:A}))}));let p=m.length===a.length;p?c.addOption("--all",!0):c.addOption("--branches",m);let d=t?!0:await Rr({message:"Are you sure you want to proceed with these worktree changes?"});t||c.setInteractive(),d||(r.info("Operation cancelled. Exiting..."),ft.exit(0)),p&&c.addOption("--yes",!0);let u=n?!0:await Rr({message:"Open created worktrees in Cursor?"});u||c.setInteractive(),u&&c.addOption("--cursor",!0);let{branchesToCreate:y}=yt({selectedReleaseBranches:m,currentWorktrees:o}),f=await wt(y,l,i);if(bt(f),u)for(let A of f)await je`cursor ${l}/${A}`;c.print();let g={createdWorktrees:f,count:f.length};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(o){throw r.error({error:o},"\u274C Error managing worktrees"),o}},xr=async e=>{await je`mkdir -p ${e}`},yt=e=>{let{selectedReleaseBranches:t,currentWorktrees:s}=e,n=s.filter(i=>i.startsWith(vt));return{branchesToCreate:t.filter(i=>!n.includes(i))}},wt=async(e,t,s)=>{let n=[];for(let o of e)try{let i=`${t}/${o}`;await je`git worktree add ${i} ${o}`;let l=`${s}/.env`;dt(l)&&(ut(l,`${i}/.env`),r.info("\u{1F4CB} Copied .env to worktree")),n.push(o)}catch(i){r.error({error:i,branch:o},`\u274C Failed to create worktree for ${o}`)}return n},bt=e=>{e.length>0?(r.info(`
|
|
25
|
+
`),r.info("\u2705 Created worktrees:"),r.info(e.join(`
|
|
26
|
+
`)),r.info("")):r.info("\u2139\uFE0F No new worktrees to create")},Ve={name:"worktrees-add",description:"Create worktrees for selected release branches",inputSchema:{all:Q.boolean().describe("Add worktrees for all release branches without prompting"),cursor:Q.boolean().optional().describe("Open created worktrees in Cursor")},outputSchema:{createdWorktrees:Q.array(Q.string()).describe("List of created worktree branches"),count:Q.number().describe("Number of worktrees created")},handler:kr};import{z as R}from"zod";import{$ as Z}from"zx";var Er=async()=>{try{let[e,t]=await Promise.all([E("release"),E("feature")]),s=await v(),n=await Rt(e,t,s);Tt(n);let o={worktrees:n,totalCount:n.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}},Rt=async(e,t,s)=>{let n=[...e.map(i=>({branch:i,type:"release"})),...t.map(i=>({branch:i,type:"feature"}))],o=[];for(let{branch:i,type:l}of n)try{let a=`${s}/${i}`,m=await xt(i),p=await kt(a),d=await Ct(a),u=await Et(a),y=await $t(a);o.push({branch:i,path:a,commit:p.substring(0,8),isCurrent:m,type:l,status:d,lastCommitMessage:u.substring(0,60)+(u.length>60?"...":""),aheadBehind:y})}catch(a){r.warn({error:a,branch:i},`\u26A0\uFE0F Could not process worktree ${i}`)}return o.sort((i,l)=>i.type!==l.type?i.type==="release"?-1:1:i.branch.localeCompare(l.branch))},xt=async e=>{try{return(await Z`git branch --show-current`).stdout.trim()===e}catch{return!1}},kt=async e=>{try{return(await Z`cd ${e} && git rev-parse HEAD`).stdout.trim()}catch{return"unknown"}},Ct=async e=>{try{let s=(await Z`cd ${e} && git status --porcelain`).stdout.trim().split(`
|
|
27
|
+
`).filter(Boolean);return s.length===0?"clean":s.length<=3?"modified":"dirty"}catch{return"unknown"}},Et=async e=>{try{return(await Z`cd ${e} && git log -1 --pretty=format:"%s"`).stdout.trim()}catch{return"No commit message available"}},$t=async e=>{try{let s=(await Z`cd ${e} && git rev-list --count --left-right @{u}...HEAD 2>/dev/null || echo "0 0"`).stdout.trim().split(" ").map(Number),n=s[0]||0,o=s[1]||0;return o===0&&n===0?"up to date":o>0&&n===0?`\u2191${o} ahead`:n>0&&o===0?`\u2193${n} behind`:`\u2191${o} \u2193${n}`}catch{return"unknown"}},Tt=e=>{if(e.length===0){r.info(`
|
|
28
|
+
\u{1F33F} Git Worktrees`),r.info("\u2500".repeat(80)),r.info("\u2139\uFE0F No worktrees found"),r.info("\u2500".repeat(80));return}r.info(`
|
|
29
|
+
\u{1F33F} Git Worktrees`),r.info("\u2550".repeat(100));let t=e.filter(o=>o.type==="release"),s=e.filter(o=>o.type==="feature");Cr("\u{1F680} Releases",t),s.length>0&&t.length>0&&r.info(""),Cr("\u2728 Features",s);let n=e.find(o=>o.isCurrent);r.info(`
|
|
30
|
+
${"\u2550".repeat(100)}`),r.info(`\u{1F4CA} Summary: ${e.length} total worktrees (${t.length} releases, ${s.length} features)`),n&&r.info(`\u{1F4CD} Currently on: ${n.branch}`),r.info("")},Cr=(e,t)=>{if(t.length!==0){r.info(`
|
|
31
|
+
${e}`),r.info("\u2500".repeat(50));for(let[s,n]of t.entries())St(n),s<t.length-1&&r.info("")}},St=e=>{let t=e.isCurrent?"\u{1F4CD}":" ",s=At(e.status),o=`${e.type==="release"?"\u{1F680}":"\u2728"} ${e.branch}`;r.info(`${t} ${s} ${o}`);let i=e.aheadBehind!=="unknown"?` | ${e.aheadBehind}`:"";r.info(` \u{1F4DD} ${e.commit}${i}`),r.info(` \u{1F4AC} ${e.lastCommitMessage}`);let l=e.path.split("/").slice(-2).join("/");r.info(` \u{1F4C1} ${l}`)},At=e=>{switch(e){case"clean":return"\u2705";case"modified":return"\u26A0\uFE0F ";case"dirty":return"\u{1F534}";default:return"\u2753"}},Me={name:"worktrees-list",description:"List all git worktrees with detailed information",inputSchema:{},outputSchema:{worktrees:R.array(R.object({branch:R.string(),path:R.string(),commit:R.string(),isCurrent:R.boolean(),type:R.enum(["release","feature"]),status:R.string(),lastCommitMessage:R.string(),aheadBehind:R.string()})).describe("List of all worktrees with details"),totalCount:R.number().describe("Total number of worktrees"),releaseCount:R.number().describe("Number of release worktrees"),featureCount:R.number().describe("Number of feature worktrees")},handler:Er};import Pt from"@inquirer/checkbox";import It from"@inquirer/confirm";import Nt from"node:process";import{z as ne}from"zod";import{$ as _t}from"zx";var $r=async e=>{let{confirmedCommand:t,all:s}=e;c.start("worktrees-remove");try{let n=await E("release");if(n.length===0)return r.info("\u2139\uFE0F No active worktrees to remove"),c.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let i=`${await v()}${W}`,l=[];s?l=n:(c.setInteractive(),l=await Pt({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(u=>({name:u.replace("release/v",""),value:u}))}));let a=l.length===n.length;a?c.addOption("--all",!0):c.addOption("--branches",l);let m=t?!0:await It({message:"Are you sure you want to proceed with these worktree changes?"});t||c.setInteractive(),m||(r.info("Operation cancelled. Exiting..."),Nt.exit(0)),a&&c.addOption("--yes",!0);let p=await Ot(l,i);Dt(p),c.print();let d={removedWorktrees:p,count:p.length};return{content:[{type:"text",text:JSON.stringify(d,null,2)}],structuredContent:d}}catch(n){throw r.error({error:n},"\u274C Error managing worktrees"),n}},Ot=async(e,t)=>{let s=[];for(let n of e)try{let o=`${t}/${n}`;await _t`git worktree remove ${o}`,s.push(n)}catch(o){r.error({error:o,branch:n},`\u274C Failed to remove worktree for ${n}`)}return s},Dt=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
|
|
32
|
+
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},Le={name:"worktrees-remove",description:"Remove selected worktrees",inputSchema:{all:ne.boolean().describe("Remove all worktrees without prompting")},outputSchema:{removedWorktrees:ne.array(ne.string()).describe("List of removed worktree branches"),count:ne.number().describe("Number of worktrees removed")},handler:$r};import Jt from"@inquirer/confirm";import jt from"node:process";import{z as We}from"zod";import{$ as Vt}from"zx";var Mt="release/v",Tr=async e=>{let{confirmedCommand:t}=e;c.start("worktrees-sync");try{let s=await E("release"),o=`${await v()}${W}`,i=await h(),l=t?!0:await Jt({message:"Are you sure you want to proceed with these worktree changes?"});t||c.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),jt.exit(0)),t||c.addOption("--yes",!0);let{branchesToRemove:a}=Lt({releasePRsList:i,currentWorktrees:s}),m=await Wt(a,o);Ft(m),c.print();let p={removedWorktrees:m,count:m.length};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}}catch(s){throw r.error({error:s},"\u274C Error managing worktrees"),s}},Lt=e=>{let{releasePRsList:t,currentWorktrees:s}=e;return{branchesToRemove:s.filter(i=>i.startsWith(Mt)).filter(i=>!t.includes(i))}},Wt=async(e,t)=>{let s=[];for(let n of e)try{let o=`${t}/${n}`;await Vt`git worktree remove ${o}`,s.push(n)}catch(o){r.error({error:o,branch:n},`\u274C Failed to remove worktree for ${n}`)}return s},Ft=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
|
|
33
|
+
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},Fe={name:"worktrees-sync",description:"Synchronize worktrees with active release branches",inputSchema:{},outputSchema:{removedWorktrees:We.array(We.string()).describe("List of removed worktree branches"),count:We.number().describe("Number of worktrees removed during sync")},handler:Tr};var Be=e=>async t=>{let{toolName:s,handler:n}=e;r.info({msg:`Tool execution started: ${s}`,params:t});try{let o=await n({...t,confirmedCommand:!0});return r.info({msg:`Tool execution successful: ${s}`}),o}catch(o){throw r.error({err:o,params:t,msg:`Tool execution failed: ${s}`}),o}};var Bt=[ge,de,fe,me,ye,De,Je,ke,$e,Se,Ie,_e,Ve,Me,Le,Fe],Sr=async e=>{for(let t of Bt)e.registerTool(t.name,{description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema},Be({toolName:t.name,handler:t.handler}))};async function Ar(){let e=new Ut({name:"infra-kit",version:"0.1.0"},{capabilities:{resources:{},tools:{},prompts:{}}});return await Xe(e),await Ye(e),await Sr(e),e}await ae();var j=Ge(),Gt=async()=>{let e;try{e=await Ar(),j.info("MCP Server instance created")}catch(t){j.error({err:t,msg:"Failed to create MCP server"}),j.error("Fatal error during server creation."),Pr.exit(1)}try{let t=new qt;await e.connect(t),j.info({msg:"Server connected to transport. Ready."})}catch(t){j.error({err:t,msg:"Failed to initialize server"}),j.error("Fatal error during server transport init."),Pr.exit(1)}};ze(j);Gt();
|
|
21
34
|
//# sourceMappingURL=mcp.js.map
|