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