ghit 0.1.19 → 0.1.20

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.
Files changed (2) hide show
  1. package/bin/cli.mjs +5 -3
  2. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -26,9 +26,11 @@ export const APIs = ${JSON.stringify(l,null,2).replace(/"([A-Za-z_][\w$]*)":/g,`
26
26
  `;description=`Generate extended API definitions from the GitHub OpenAPI spec`;async handle(){let[e,t]=D();t(this);let{name:n}=this.dictionary;if(n===`apis`)q.run();else if(n===`reset`){if(!await this.confirm(`Are you sure you want to remove all generated APIs? This action cannot be undone.`))return void this.newLine().info(`Operation cancelled.`).newLine();let{existsSync:e,unlinkSync:t}=await import(`node:fs`),n=this.spinner(`Removing generated APIs...`).start(),r=0;for(let i of[`local`,`global`]){let a=q.getOutputPath(i);e(a)&&(t(a),n.succeed(`Removed generated ${i} APIs successfully.`),r++)}r>0?n.succeed(`Removed all generated APIs successfully.`):n.fail(`No generated APIs found to remove.`)}}},Se=class extends v{signature=`info`;description=`Display application runtime information.`;async handle(){let e={version:`unknown`,dependencies:{}},n=R(`user`),r=de(),i=y(import.meta.url),a=R(`default_repo`,void 0,{bypassCurrentRepo:!0})?.full_name||null,o=T(),[s,c]=D(),[l]=N();c(this),F();let u=this.spinner(`Gathering application information...
27
27
  `).start();if(r)try{e=i(r)}catch{}U(500,()=>{u.succeed(`Application Information Loaded.
28
28
  `);let r=new ae;r.push({"App Version":e.version},{Platform:`${d.platform()} ${d.arch()} (${d.release()})`},{CPUs:d.cpus().length},{Host:`${d.userInfo().username}@${d.hostname()}`},{Memory:`${(d.freemem()/1024**3).toFixed(2)} GB / ${(d.totalmem()/1024**3).toFixed(2)} GB`},{"Database Path":g.join(l,`app.db`)},{"Github User":n?`${n.login} (ID: ${n.id})`:`Not logged in`},{"Default Repo":(a||`Not set`)+`${a===o?.full_name?` (Current)`:``}`},{"Current Repo":o?`${o.full_name}`:`Not detected`},{"Current Directory":process.cwd().replace(d.homedir(),`~`)}),console.log(r.toString()),t.log(`
29
- Dependencies:`,`yellow`),t.log(Object.keys(e.dependencies).map(e=>`${e}`).join(`, `),`green`),this.newLine()})}},Ce=class extends v{signature=`init`;description=`Initialize the application.`;async handle(){let[e,t]=D();t(this),F(),this.info(`Application initialized successfully.`).newLine()}},X=class{command;normalizeIssuePath(e){return e.replaceAll(`\\`,`/`).replace(/^\.\//,``)}constructor(){let[e]=D();this.command=e()}setFilePath(e,t){if(!t)return e;let n=this.normalizeIssuePath(t);return e=e.includes(`<!-- ghit#filepath:`)?e.replace(/<!--\s*ghit#filepath:\s*.+?\s*-->/i,`<!-- ghit#filepath: ${n} -->`):`<!-- ghit#filepath: ${n} -->\n\n`+e,e}getFilePath(e){let t=e.match(/<!--\s*ghit#filepath:\s*(.+?)\s*-->/i);if(t)return this.normalizeIssuePath(t[1].trim())}parseFrontmatter(e){let t=e.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);if(!t)return{metadata:{},body:e};let[,n,r]=t,i={},a=n.split(`
29
+ Dependencies:`,`yellow`),t.log(Object.keys(e.dependencies).map(e=>`${e}`).join(`, `),`green`),this.newLine()})}},Ce=class extends v{signature=`init`;description=`Initialize the application.`;async handle(){let[e,t]=D();t(this),F(),this.info(`Application initialized successfully.`).newLine()}},X=class{command;normalizeIssuePath(e){return e.replaceAll(`\\`,`/`).replace(/^\.\//,``)}constructor(){let[e]=D();this.command=e()}setFilePath(e,t){if(!t)return e;let n=this.normalizeIssuePath(t);return e=e.includes(`<!-- ghit#filepath:`)?e.replace(/<!--\s*ghit#filepath:\s*.+?\s*-->/i,`<!-- ghit#filepath: ${n} -->`):`<!-- ghit#filepath: ${n} -->\n\n`+e,e}getFilePath(e){let t=e.match(/<!--\s*ghit#filepath:\s*(.+?)\s*-->/i);if(t)return this.normalizeIssuePath(t[1].trim())}parseFrontmatter(e){let t=e.replace(/\r\n?/g,`
30
+ `).match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);if(!t)return{metadata:{},body:e};let[,n,r]=t,i={},a=n.split(`
30
31
  `),o=null;for(let e of a){let t=e.match(/^(\w+):\s*['"]?(.*?)['"]?$/);if(t){let[,e,n]=t;o=e,i[e]=n}else o&&e.trim()&&(i[o]+=`
31
- `+e.trim())}return{metadata:i,body:r.trim()}}async updateIssue(e,t,n,r){try{let i=e.filePath?this.setFilePath(e.body??``,e.filePath):e.body??``,{data:a}=await A().issues.update({body:i,repo:r,owner:n,issue_number:t.number,title:e.title,labels:e.labels||[],assignees:e.assignees||[]});return a}catch(e){throw this.requestError(e,n,r)}}async createIssue(e,t,n){try{let r=e.filePath?this.setFilePath(e.body??``,e.filePath):e.body??``,{data:i}=await A().issues.create({body:r,repo:n,owner:t,type:e.type,title:e.title,labels:e.labels||[],assignees:e.assignees||[]});return i}catch(e){throw this.requestError(e,t,n)}}getIssueFiles(e){let t=[],n=this.command.spinner(`Reading issue files...`).start(),r=e=>{let n=m.readdirSync(e,{withFileTypes:!0});for(let i of n){let n=g.join(e,i.name);i.isDirectory()?r(n):i.isFile()&&i.name.endsWith(`.md`)&&t.push(n)}};r(e);let i=t.sort();return n.succeed(`Found ${i.length} issue files`),i.length===0&&(n.info(`No issue files found. Exiting.`),process.exit(0)),i}prepareIssue(e,t,n){let{metadata:r,body:i}=this.parseFrontmatter(e),a=[];r.labels&&(a=r.labels.split(`,`).map(e=>e.trim()).filter(e=>e));let o=[];return r.assignees&&r.assignees.trim()&&(o=r.assignees.split(`,`).map(e=>e.trim()).filter(e=>e)),{filePath:this.normalizeIssuePath(t),title:r.title||r.name||n,type:r.type,body:i,labels:a,assignees:o,fileName:n}}processIssueFile(e){let t=this.command.argument(`path`,`issues`),n=g.isAbsolute(t)?t:g.resolve(process.cwd(),t),r=m.readFileSync(e,`utf-8`),i=g.relative(n,e);g.isAbsolute(i)&&(i=g.relative(process.cwd(),e));let a=g.basename(e,`.md`);return this.prepareIssue(r,i,a)}processMultiIssueMarkdown(e){try{let t=m.readFileSync(e,`utf-8`).split(/\n(\+{6}|={6})\n/),n=[];for(let r of t){if(!r||!r.trim()||!r.match(/title: (.+)/))continue;let t=r.replace(/^---\n([\s\S]*?)\n---/m,(e,t)=>`---\n${t.split(`
32
+ `+e.trim())}return{metadata:i,body:r.trim()}}async updateIssue(e,t,n,r){try{let i=e.filePath?this.setFilePath(e.body??``,e.filePath):e.body??``,{data:a}=await A().issues.update({body:i,repo:r,owner:n,issue_number:t.number,title:e.title,labels:e.labels||[],assignees:e.assignees||[]});return a}catch(e){throw this.requestError(e,n,r)}}async createIssue(e,t,n){try{let r=e.filePath?this.setFilePath(e.body??``,e.filePath):e.body??``,{data:i}=await A().issues.create({body:r,repo:n,owner:t,type:e.type,title:e.title,labels:e.labels||[],assignees:e.assignees||[]});return i}catch(e){throw this.requestError(e,t,n)}}getIssueFiles(e){let t=[],n=this.command.spinner(`Reading issue files...`).start(),r=e=>{let n=m.readdirSync(e,{withFileTypes:!0});for(let i of n){let n=g.join(e,i.name);i.isDirectory()?r(n):i.isFile()&&i.name.endsWith(`.md`)&&t.push(n)}};r(e);let i=t.sort();return n.succeed(`Found ${i.length} issue files`),i.length===0&&(n.info(`No issue files found. Exiting.`),process.exit(0)),i}prepareIssue(e,t,n){let{metadata:r,body:i}=this.parseFrontmatter(e),a=[];r.labels&&(a=r.labels.split(`,`).map(e=>e.trim()).filter(e=>e));let o=[];return r.assignees&&r.assignees.trim()&&(o=r.assignees.split(`,`).map(e=>e.trim()).filter(e=>e)),{filePath:this.normalizeIssuePath(t),title:r.title||r.name||n,type:r.type,body:i,labels:a,assignees:o,fileName:n}}processIssueFile(e){let t=this.command.argument(`path`,`issues`),n=g.isAbsolute(t)?t:g.resolve(process.cwd(),t),r=m.readFileSync(e,`utf-8`),i=g.relative(n,e);g.isAbsolute(i)&&(i=g.relative(process.cwd(),e));let a=g.basename(e,`.md`);return this.prepareIssue(r,i,a)}processMultiIssueMarkdown(e){try{let t=m.readFileSync(e,`utf-8`).replace(/\r\n?/g,`
33
+ `).split(/\n[ \t]*(?:\+{6}|={6})[ \t]*\n/),n=[];for(let r of t){if(!r||!r.trim()||!r.match(/^title:\s+(.+)$/im))continue;let t=r.replace(/^---\n([\s\S]*?)\n---/m,(e,t)=>`---\n${t.split(`
32
34
  `).filter(e=>e.trim()!==``||e.includes(`:`)).join(`
33
35
  `)}\n---`);t=t.replace(/labels:\s*\[(.*?)\]/g,(e,t)=>`labels: ${t.split(`,`).map(e=>e.replace(/['"]/g,``).trim()).filter(Boolean).join(`,`)}`);let i=g.relative(process.cwd(),e),a=g.basename(e);n.push(this.prepareIssue(t.trimStart()+`
34
36
  `,i,a))}return n}catch(e){return this.command.error(`ERROR: Failed to read markdown file: ${e.message}`),[]}}async validateAccess(e,t){let n=this.command.spinner(`Checking GitHub access...`).start();try{let r=await A().repos.get({owner:e,repo:t});return n.succeed(`GitHub access validated successfully.`),r}catch(e){n.stop();let t=``;throw n.fail(`GitHub access validation failed: ${e.message}.`),e.status===404&&(t=`This usually means:
@@ -127,4 +129,4 @@ ${e.body??``}`,r=`${t+1}-${e.title.replace(/[^a-z0-9]+/gi,`-`).replace(/^-+/,``)
127
129
  ▐▌ ▐▌ ▐▌ █ █
128
130
  ▐▌▝▜▌▐▛▀▜▌ █ █
129
131
  ▝▚▄▞▘▐▌ ▐▌▗▄█▄▖ █
130
- `,Re=`0.1.19`,ze=class{};Ie(),re.init(new ze,{logo:Le,version:Re,exceptionHandler(e){let[t]=O(),n=t();console.error(n.debug?e:e.message)},baseCommands:[Se,Ce,Ne,Pe,be,Te,Fe,Oe,we,ke,Ee,xe,De,..._e()]});export{};
132
+ `,Re=`0.1.20`,ze=class{};Ie(),re.init(new ze,{logo:Le,version:Re,exceptionHandler(e){let[t]=O(),n=t();console.error(n.debug?e:e.message)},baseCommands:[Se,Ce,Ne,Pe,be,Te,Fe,Oe,we,ke,Ee,xe,De,..._e()]});export{};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ghit",
3
3
  "type": "module",
4
- "version": "0.1.19",
4
+ "version": "0.1.20",
5
5
  "description": "A CLI tool for managing GitHub repositories, issues, and workflows from your terminal, combining custom workflows with full GitHub API coverage.",
6
6
  "main": "bin/cli.mjs",
7
7
  "private": false,