shippie
Version:
an extensible code review agent
3 lines (2 loc) • 2.8 kB
JavaScript
import"./chunk-WUKYLWAZ.mjs";import{a as t}from"./chunk-MMWUM7UL.mjs";import{execSync as s}from"node:child_process";import r from"node:fs";import l from"node:path";import{password as p}from"@inquirer/prompts";import{glob as u}from"tinyglobby";var n=async e=>{let i=await u(e,{onlyFiles:!0});if(i.length===0)throw new Error(`No template file found for pattern: ${e}`);return i[0]};var v=async e=>{e.platform==="github"&&await y(),e.platform==="gitlab"&&await d(),e.platform==="azdev"&&await h()},f=async()=>{let e=await p({message:"Please input your OpenAI API key (leave blank to use GitHub Models):",mask:"*"});if(!e){t.info("No API key provided, using GitHub Models.");return}return e},m=async()=>await p({message:"Please input your OpenAI API key:"}),y=async()=>{let e=await f(),o=await n(`**/templates/${e?"github-pr.yml":"github-pr-models.yml"}`),a=l.join(process.cwd(),".github","workflows");r.mkdirSync(a,{recursive:!0});let c=l.join(a,"shippie.yml");if(r.writeFileSync(c,r.readFileSync(o,"utf8"),"utf8"),t.info(`Created GitHub Actions workflow at: ${c}`),e)try{s("gh auth status || gh auth login",{stdio:"inherit"}),s(`gh secret set OPENAI_API_KEY --body=${String(e)}`),t.info("Successfully added the OPENAI_API_KEY secret to your GitHub repository.")}catch{t.error("It seems that the GitHub CLI is not installed or there was an error during authentication. Don't forget to add the OPENAI_API_KEY to the repo settings/Environment/Actions/Repository Secrets manually.")}},d=async()=>{let e=await n("**/templates/gitlab-pr.yml"),i=process.cwd(),o=l.join(i,".gitlab-ci.yml");r.writeFileSync(o,r.readFileSync(e,"utf8"),"utf8"),t.info(`Created GitLab CI at: ${o}`);let a=await m();if(!a){t.error("No API key provided. Please manually add the OPENAI_API_KEY secret to your GitLab CI/CD environment variables for your repository.");return}try{s("glab auth login",{stdio:"inherit"}),s(`glab variable set OPENAI_API_KEY ${String(a)}`),t.info(`Successfully added the OPENAI_API_KEY secret to your GitLab repository.
Please make sure you have set up your Gitlab access token before using this tool. Refer to the README (Gitlab CI section) for information on how to do this.`)}catch{t.error("It seems that the GitLab CLI is not installed or there was an error during authentication. Don't forget to add the OPENAI_API_KEY and the GITLAB_TOKEN to the repo's CI/CD Variables manually. Refer to the README (Gitlab CI section)for information on how to set up your access token.")}},h=async()=>{let e=await n("**/templates/azdev-pr.yml"),i=process.cwd(),o=l.join(i,"shippie.yaml");r.writeFileSync(o,r.readFileSync(e,"utf8"),"utf8"),t.info(`Created Azure DevOps Pipeline at: ${o}`),t.info("Please manually add the OPENAI_API_KEY and API_TOKEN secrets as encrypted variables in the UI.")};export{v as configure};