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