@r5n/sisyphus 0.12.0 → 0.12.2

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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="https://raw.githubusercontent.com/r5n-labs/clis/develop/packages/sisyphus/assets/logo.svg" width="128" alt="Sisyphus logo — a figure pushing a boulder uphill">
2
+ <img src="https://raw.githubusercontent.com/r5n-labs/clis/develop/packages/sisyphus/assets/logo.svg" width="128" alt="Sisyphus logo — a boulder on its way uphill">
3
3
  </p>
4
4
 
5
5
  # Sisyphus
package/dist/cli.js CHANGED
@@ -91,7 +91,7 @@ Run "${this.commandPath} --help" for usage.`),process.exit(1);let o=this.command
91
91
  `))});return`${h?"[":"{"}${S}${B.join(L)}${k}${h?"]":"}"}`}function c(l,p,g){if(!g)return Xs(l,o);let h=e.lastIndexOf(`
92
92
  `,p-1)+1,f=e.slice(h,p).match(/^[\t ]*/)?.[0]??"";return JSON.stringify(l,null,n).replaceAll(`
93
93
  `,i+f)}return e.slice(0,s.start)+a(s,r)+e.slice(s.end)}function Xs(e,t){if(Array.isArray(e))return`[${e.map((n)=>Xs(n,t)).join(`,${t}`)}]`;if(e===null||typeof e!=="object")return JSON.stringify(e);let r=Object.entries(e);if(r.length===0)return"{}";let s=r.map(([n,i])=>`${JSON.stringify(n)}:${t}${Xs(i,t)}`);return`{${t}${s.join(`,${t}`)}${t}}`}function fu(e){let t=e.matchAll(/"(?:[^"\\]|\\.)*"|[^\s{}[\],:]+|[{}[\],:]/g),r=t.next().value;function s(){if(!r)throw Error("Unexpected end of JSON");let i=r;return r=t.next().value,i}function n(){let i=s(),o=[],a=i[0]==="{";if(!a&&i[0]!=="[")return{end:i.index+i[0].length,entries:o,start:i.index,value:JSON.parse(i[0])};let c=a?"}":"]";while(r&&r[0]!==c){let p=r.index,g=a?JSON.parse(s()[0]):String(o.length);if(a)s();if(o.push({key:g,node:n(),start:p}),r?.[0]===",")s()}let l=s().index+1;return{end:l,entries:o,start:i.index,value:JSON.parse(e.slice(i.index,l))}}return n()}var yu=2,wu=ht(Object);class Zs{config;configPath;defaultConfig;loadError;constructor(e,t){this.configPath=Co.resolve(e),this.defaultConfig=t,this.config=this.loadConfig()}get path(){return this.configPath}get(e){return this.config[e]}set(e,t){this.config={...this.config,[e]:t},this.save()}delete(e){delete this.config[e],this.save()}exists(){return me.existsSync(this.configPath)}getAll(){return structuredClone(this.config)}save(e){if(this.loadError)throw Error(`Cannot overwrite unreadable config at ${this.configPath}; repair the file and try again`,{cause:this.loadError});if(e)this.config={...e};this.ensureDirectoryExists();let t=this.exists()?me.realpathSync(this.configPath):this.configPath,r=`${t}.${crypto.randomUUID()}.tmp`;try{let s=this.exists()?me.statSync(this.configPath).mode:void 0,n=this.exists()?Vt(me.readFileSync(this.configPath,"utf-8"),this.config):`${JSON.stringify(this.config,null,yu)}
94
- `;if(me.writeFileSync(r,n,{flag:"wx",mode:s}),s!==void 0)me.chmodSync(r,s);me.renameSync(r,t)}catch(s){throw Error(`Failed to save config to ${this.configPath}`,{cause:s})}finally{me.rmSync(r,{force:!0})}}ensureDirectoryExists(){let e=Co.dirname(this.configPath);if(!me.existsSync(e))try{me.mkdirSync(e,{recursive:!0})}catch(t){throw Error(`Failed to create config directory at ${e}`,{cause:t})}}loadConfig(){if(!me.existsSync(this.configPath))return structuredClone(this.defaultConfig);try{let e=me.readFileSync(this.configPath,"utf-8"),t=JSON.parse(e);if(Array.isArray(t))throw Error("Config must be an object");let r=wu(t);return dt(structuredClone(this.defaultConfig),r)}catch(e){return this.loadError=e,console.warn(`Config file corrupted at ${this.configPath}. Using defaults.`),structuredClone(this.defaultConfig)}}}var ko="0.12.0";class j extends Ft{}import{existsSync as Nu}from"fs";import{mkdir as ju,writeFile as Fu}from"fs/promises";import{dirname as Bu}from"path";class Ue{owner;repo;constructor(e){this.owner=e.owner,this.repo=e.repo}}class Or extends Ue{name="bitbucket";notImplemented(){throw new u("Bitbucket is not supported yet","Bitbucket support is coming soon")}async ensureAvailable(){this.notImplemented()}async getDefaultBranch(){this.notImplemented()}async findPr(e){this.notImplemented()}async createPr(e){this.notImplemented()}async updatePr(e,t){this.notImplemented()}async getPr(e){this.notImplemented()}async getPrFromCurrentBranch(){this.notImplemented()}async getPrCommits(e){this.notImplemented()}async getPrFiles(e){this.notImplemented()}async ensureLabelExists(e,t){this.notImplemented()}async getRelease(e){this.notImplemented()}async createRelease(e){this.notImplemented()}async deleteRelease(e){this.notImplemented()}}var F="sis",Qs="\uD83E\uDEA8",Ve="other",ft={build:23,chore:25,ci:24,docs:20,feat:10,"feat!":0,fix:11,"fix!":1,perf:12,refactor:13,style:21,test:22,["other"]:100},yt=50,wt=".sisyphus",xo="stones",To="released",_r=7,Eo="unknown",Gt="unknown",Io="0.0.0",he="latest",en=["bun","run","build"],Ee="main",Ao=4,Oo=8,Mr="config.json";var Ge={$schema:"https://raw.githubusercontent.com/r5n-labs/clis/refs/heads/develop/packages/sisyphus/schema.json",changelog:{append:!0,filename:"CHANGELOG.md",generate:!0,packageHeader:"{emoji} {version} ({date})",root:!1,rootHeader:"{date} - {packages}",sections:{breaking:"Breaking changes",build:"Build",chore:"Chores",ci:"CI",dependencies:"Dependency updates",docs:"Documentation",feat:"Features",fix:"Bug fixes",other:"Other changes",perf:"Performance",refactor:"Refactoring",style:"Styling",test:"Tests"}},commit:{author:"r5n-bot",email:"r5n-bot@users.noreply.github.com",message:"chore(release): {message}"},commits:{skip:{authors:["r5n-bot[bot]"],messagePatterns:["^chore\\(release\\):","^chore: add stone"]}},dependents:{kinds:["dependencies","devDependencies","optionalDependencies","peerDependencies"],updateInternal:"always"},ignore:[],lastStone:{commit:"",date:""},plugins:[],pr:{labelMapping:{breaking:"major","breaking-change":"major",bug:"patch",chore:"patch",docs:"patch",enhancement:"minor",feature:"minor",fix:"patch"},skip:{authors:["r5n-bot[bot]"],labels:["sisyphus-release","skip-stone"],titlePatterns:["^chore\\(release\\):"]}},release:{build:{command:[...en],outputs:[],root:[]},createRelease:!1,npm:!1,push:!1,tags:!1},scripts:{post:{},pre:{}},single:!1,sisyphusDir:".sisyphus",stones:[],tag:"latest"};var vu=200,$u=404,Pu=10,Ru=3000,_o=ve().map((e)=>e.length>0?e:ge()),Su=Qe(Qe(Ut({filename:_o,previous_filename:_o.or(Bt()),status:ve()}).map((e)=>e.status==="renamed"&&e.previous_filename===void 0?ge():e)));function Cu(e){if(typeof e!=="object"||e===null)return!1;let t=e;return typeof t.tag_name==="string"&&typeof t.draft==="boolean"&&(typeof t.name==="string"||t.name===null)&&(typeof t.body==="string"||t.body===null)}class Lr extends Ue{name="github";get apiPath(){return`repos/${encodeURIComponent(this.owner)}/${encodeURIComponent(this.repo)}`}async ensureAvailable(){try{await Bun.$`which gh`.quiet()}catch{throw new u("GitHub CLI (gh) is not installed","Install from https://cli.github.com and run: gh auth login")}try{await Bun.$`gh auth status`.quiet()}catch{throw new u("GitHub CLI (gh) is not authenticated","Run: gh auth login")}}async getDefaultBranch(){try{return(await Bun.$`gh repo view --json defaultBranchRef --jq .defaultBranchRef.name`.quiet()).stdout.toString().trim()||Ee}catch{return Ee}}async findPr(e){try{let t=[];if(e.head)t.push("--head",e.head);if(e.label)t.push("--label",e.label);let r=await Bun.$`gh pr list --json number,url,title,body,labels,author,headRefName,baseRefName,mergeCommit,state --limit 1 ${t}`.quiet(),s=JSON.parse(r.stdout.toString());if(!s[0])return null;return this.mapPrResponse(s[0])}catch{return null}}async createPr(e){let t=await Bun.$`gh api ${this.apiPath}/pulls --method POST -f head=${e.head} -f base=${e.base} -f title=${e.title} -f body=${e.body}`,s=JSON.parse(t.stdout.toString()).number;if(e.labels&&e.labels.length>0){let n=e.labels.flatMap((i)=>["-f",`labels[]=${i}`]);await Bun.$`gh api ${this.apiPath}/issues/${s}/labels --method POST ${n}`}return this.getPr(s)}async updatePr(e,t){let r=[];if(t.title)r.push("--title",t.title);if(t.body)r.push("--body",t.body);await Bun.$`gh pr edit ${e} ${r}`}async getPr(e){try{let t=await Bun.$`gh api ${this.apiPath}/pulls/${e}`.quiet(),r=JSON.parse(t.stdout.toString());return this.mapRestApiResponse(r)}catch{throw new u(`Failed to fetch PR #${e}`,"Make sure the PR exists and you have access")}}async getPrFromCurrentBranch(){try{let e=await Bun.$`gh pr view --json number,title,body,labels,author,headRefName,baseRefName,url,mergeCommit,state`.quiet(),t=JSON.parse(e.stdout.toString());return this.mapPrResponse(t)}catch{throw new u("No PR found for current branch","Make sure you have an open PR or provide a URL with --url")}}async getPrCommits(e){try{return(await Bun.$`gh api ${this.apiPath}/pulls/${e}/commits --jq '.[].sha'`.quiet()).stdout.toString().trim().split(`
94
+ `;if(me.writeFileSync(r,n,{flag:"wx",mode:s}),s!==void 0)me.chmodSync(r,s);me.renameSync(r,t)}catch(s){throw Error(`Failed to save config to ${this.configPath}`,{cause:s})}finally{me.rmSync(r,{force:!0})}}ensureDirectoryExists(){let e=Co.dirname(this.configPath);if(!me.existsSync(e))try{me.mkdirSync(e,{recursive:!0})}catch(t){throw Error(`Failed to create config directory at ${e}`,{cause:t})}}loadConfig(){if(!me.existsSync(this.configPath))return structuredClone(this.defaultConfig);try{let e=me.readFileSync(this.configPath,"utf-8"),t=JSON.parse(e);if(Array.isArray(t))throw Error("Config must be an object");let r=wu(t);return dt(structuredClone(this.defaultConfig),r)}catch(e){return this.loadError=e,console.warn(`Config file corrupted at ${this.configPath}. Using defaults.`),structuredClone(this.defaultConfig)}}}var ko="0.12.2";class j extends Ft{}import{existsSync as Nu}from"fs";import{mkdir as ju,writeFile as Fu}from"fs/promises";import{dirname as Bu}from"path";class Ue{owner;repo;constructor(e){this.owner=e.owner,this.repo=e.repo}}class Or extends Ue{name="bitbucket";notImplemented(){throw new u("Bitbucket is not supported yet","Bitbucket support is coming soon")}async ensureAvailable(){this.notImplemented()}async getDefaultBranch(){this.notImplemented()}async findPr(e){this.notImplemented()}async createPr(e){this.notImplemented()}async updatePr(e,t){this.notImplemented()}async getPr(e){this.notImplemented()}async getPrFromCurrentBranch(){this.notImplemented()}async getPrCommits(e){this.notImplemented()}async getPrFiles(e){this.notImplemented()}async ensureLabelExists(e,t){this.notImplemented()}async getRelease(e){this.notImplemented()}async createRelease(e){this.notImplemented()}async deleteRelease(e){this.notImplemented()}}var F="sis",Qs="\uD83E\uDEA8",Ve="other",ft={build:23,chore:25,ci:24,docs:20,feat:10,"feat!":0,fix:11,"fix!":1,perf:12,refactor:13,style:21,test:22,["other"]:100},yt=50,wt=".sisyphus",xo="stones",To="released",_r=7,Eo="unknown",Gt="unknown",Io="0.0.0",he="latest",en=["bun","run","build"],Ee="main",Ao=4,Oo=8,Mr="config.json";var Ge={$schema:"https://raw.githubusercontent.com/r5n-labs/clis/refs/heads/develop/packages/sisyphus/schema.json",changelog:{append:!0,filename:"CHANGELOG.md",generate:!0,packageHeader:"{emoji} {version} ({date})",root:!1,rootHeader:"{date} - {packages}",sections:{breaking:"Breaking changes",build:"Build",chore:"Chores",ci:"CI",dependencies:"Dependency updates",docs:"Documentation",feat:"Features",fix:"Bug fixes",other:"Other changes",perf:"Performance",refactor:"Refactoring",style:"Styling",test:"Tests"}},commit:{author:"r5n-bot",email:"r5n-bot@users.noreply.github.com",message:"chore(release): {message}"},commits:{skip:{authors:["r5n-bot[bot]"],messagePatterns:["^chore\\(release\\):","^chore: add stone"]}},dependents:{kinds:["dependencies","devDependencies","optionalDependencies","peerDependencies"],updateInternal:"always"},ignore:[],lastStone:{commit:"",date:""},plugins:[],pr:{labelMapping:{breaking:"major","breaking-change":"major",bug:"patch",chore:"patch",docs:"patch",enhancement:"minor",feature:"minor",fix:"patch"},skip:{authors:["r5n-bot[bot]"],labels:["sisyphus-release","skip-stone"],titlePatterns:["^chore\\(release\\):"]}},release:{build:{command:[...en],outputs:[],root:[]},createRelease:!1,npm:!1,push:!1,tags:!1},scripts:{post:{},pre:{}},single:!1,sisyphusDir:".sisyphus",stones:[],tag:"latest"};var vu=200,$u=404,Pu=10,Ru=3000,_o=ve().map((e)=>e.length>0?e:ge()),Su=Qe(Qe(Ut({filename:_o,previous_filename:_o.or(Bt()),status:ve()}).map((e)=>e.status==="renamed"&&e.previous_filename===void 0?ge():e)));function Cu(e){if(typeof e!=="object"||e===null)return!1;let t=e;return typeof t.tag_name==="string"&&typeof t.draft==="boolean"&&(typeof t.name==="string"||t.name===null)&&(typeof t.body==="string"||t.body===null)}class Lr extends Ue{name="github";get apiPath(){return`repos/${encodeURIComponent(this.owner)}/${encodeURIComponent(this.repo)}`}async ensureAvailable(){try{await Bun.$`which gh`.quiet()}catch{throw new u("GitHub CLI (gh) is not installed","Install from https://cli.github.com and run: gh auth login")}try{await Bun.$`gh auth status`.quiet()}catch{throw new u("GitHub CLI (gh) is not authenticated","Run: gh auth login")}}async getDefaultBranch(){try{return(await Bun.$`gh repo view --json defaultBranchRef --jq .defaultBranchRef.name`.quiet()).stdout.toString().trim()||Ee}catch{return Ee}}async findPr(e){try{let t=[];if(e.head)t.push("--head",e.head);if(e.label)t.push("--label",e.label);let r=await Bun.$`gh pr list --json number,url,title,body,labels,author,headRefName,baseRefName,mergeCommit,state --limit 1 ${t}`.quiet(),s=JSON.parse(r.stdout.toString());if(!s[0])return null;return this.mapPrResponse(s[0])}catch{return null}}async createPr(e){let t=await Bun.$`gh api ${this.apiPath}/pulls --method POST -f head=${e.head} -f base=${e.base} -f title=${e.title} -f body=${e.body}`,s=JSON.parse(t.stdout.toString()).number;if(e.labels&&e.labels.length>0){let n=e.labels.flatMap((i)=>["-f",`labels[]=${i}`]);await Bun.$`gh api ${this.apiPath}/issues/${s}/labels --method POST ${n}`}return this.getPr(s)}async updatePr(e,t){let r=[];if(t.title)r.push("--title",t.title);if(t.body)r.push("--body",t.body);await Bun.$`gh pr edit ${e} ${r}`}async getPr(e){try{let t=await Bun.$`gh api ${this.apiPath}/pulls/${e}`.quiet(),r=JSON.parse(t.stdout.toString());return this.mapRestApiResponse(r)}catch{throw new u(`Failed to fetch PR #${e}`,"Make sure the PR exists and you have access")}}async getPrFromCurrentBranch(){try{let e=await Bun.$`gh pr view --json number,title,body,labels,author,headRefName,baseRefName,url,mergeCommit,state`.quiet(),t=JSON.parse(e.stdout.toString());return this.mapPrResponse(t)}catch{throw new u("No PR found for current branch","Make sure you have an open PR or provide a URL with --url")}}async getPrCommits(e){try{return(await Bun.$`gh api ${this.apiPath}/pulls/${e}/commits --jq '.[].sha'`.quiet()).stdout.toString().trim().split(`
95
95
  `).filter(Boolean)}catch{return[]}}async getPrFiles(e){try{let t=await Bun.$`gh api ${this.apiPath}/pulls/${e}/files --paginate --slurp`.quiet(),r=Su(JSON.parse(t.stdout.toString())).flat();if(r.length>=Ru)throw new u(`PR #${e} reaches the GitHub file limit`,"The complete changed file list cannot be established; create the stone from a complete local checkout");return[...new Set(r.flatMap((s)=>s.status==="renamed"&&s.previous_filename!==void 0?[s.previous_filename,s.filename]:[s.filename]))]}catch(t){if(t instanceof u)throw t;throw new u(`Failed to fetch PR #${e} files`,"Check GitHub access and retry the analysis")}}async ensureLabelExists(e,t){try{let r=t?.description??"",s=t?.color?["--color",t.color]:[];await Bun.$`gh label create ${e} --description ${r} ${s} --force`.quiet()}catch{}}async getRelease(e){let t=`${this.apiPath}/releases/tags/${encodeURIComponent(e)}`,r=await Bun.$`gh api ${t} --include`.quiet().nothrow(),s=r.stdout.toString().replaceAll(`\r
96
96
  `,`
97
97
  `),[n="",...i]=s.split(`
package/package.json CHANGED
@@ -31,5 +31,5 @@
31
31
  },
32
32
  "type": "module",
33
33
  "types": "src/cli.ts",
34
- "version": "0.12.0"
34
+ "version": "0.12.2"
35
35
  }