@gilbert_oliveira/commit-wizard 1.0.26 → 1.2.0

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.
@@ -0,0 +1,185 @@
1
+ import { execSync } from 'child_process';
2
+ /**
3
+ * Utilitários para operações Git
4
+ */
5
+ export class GitUtils {
6
+ constructor(excludePatterns = []) {
7
+ this.excludePatterns = excludePatterns;
8
+ }
9
+ /**
10
+ * Verifica se o diretório atual é um repositório Git
11
+ */
12
+ isGitRepository() {
13
+ try {
14
+ execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
15
+ return true;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ /**
22
+ * Constrói argumentos de exclusão para comandos git
23
+ */
24
+ buildExcludeArgs() {
25
+ if (this.excludePatterns.length === 0) {
26
+ return '';
27
+ }
28
+ return this.excludePatterns.map(pattern => `":(exclude)${pattern}"`).join(' ');
29
+ }
30
+ /**
31
+ * Obtém status dos arquivos staged
32
+ */
33
+ getStagedStatus() {
34
+ if (!this.isGitRepository()) {
35
+ throw new Error('Diretório atual não é um repositório Git');
36
+ }
37
+ const excludeArgs = this.buildExcludeArgs();
38
+ try {
39
+ // Verifica arquivos staged
40
+ const stagedFiles = execSync(`git diff --cached --name-only -- . ${excludeArgs}`, {
41
+ encoding: 'utf8',
42
+ })
43
+ .toString()
44
+ .trim();
45
+ if (!stagedFiles) {
46
+ return {
47
+ hasStagedFiles: false,
48
+ stagedFiles: [],
49
+ diff: '',
50
+ };
51
+ }
52
+ // Obtém o diff completo
53
+ const diff = execSync(`git diff --cached -- . ${excludeArgs}`, { encoding: 'utf8' });
54
+ return {
55
+ hasStagedFiles: true,
56
+ stagedFiles: stagedFiles.split('\n').filter(file => file.trim()),
57
+ diff,
58
+ };
59
+ }
60
+ catch (error) {
61
+ throw new Error(`Erro ao obter status Git: ${error}`);
62
+ }
63
+ }
64
+ /**
65
+ * Realiza commit com mensagem
66
+ */
67
+ commit(message, additionalArgs = []) {
68
+ if (!this.isGitRepository()) {
69
+ throw new Error('Diretório atual não é um repositório Git');
70
+ }
71
+ try {
72
+ const args = additionalArgs.length > 0 ? ` ${additionalArgs.join(' ')}` : '';
73
+ execSync(`git commit -m "${message.replace(/"/g, '\\"')}"${args}`, {
74
+ stdio: 'inherit',
75
+ });
76
+ }
77
+ catch (error) {
78
+ throw new Error(`Erro ao realizar commit: ${error}`);
79
+ }
80
+ }
81
+ /**
82
+ * Realiza commit usando arquivo temporário para a mensagem
83
+ */
84
+ commitWithFile(messageFile, additionalArgs = []) {
85
+ if (!this.isGitRepository()) {
86
+ throw new Error('Diretório atual não é um repositório Git');
87
+ }
88
+ try {
89
+ const args = additionalArgs.length > 0 ? ` ${additionalArgs.join(' ')}` : '';
90
+ execSync(`git commit -F "${messageFile}"${args}`, {
91
+ stdio: 'inherit',
92
+ });
93
+ }
94
+ catch (error) {
95
+ throw new Error(`Erro ao realizar commit: ${error}`);
96
+ }
97
+ }
98
+ /**
99
+ * Obtém informações sobre o último commit
100
+ */
101
+ getLastCommitInfo() {
102
+ if (!this.isGitRepository()) {
103
+ throw new Error('Diretório atual não é um repositório Git');
104
+ }
105
+ try {
106
+ const info = execSync('git log -1 --pretty=format:"%H|%s|%an|%ad" --date=short', {
107
+ encoding: 'utf8',
108
+ });
109
+ const [hash, message, author, date] = info.split('|');
110
+ return { hash, message, author, date };
111
+ }
112
+ catch (error) {
113
+ throw new Error(`Erro ao obter informações do último commit: ${error}`);
114
+ }
115
+ }
116
+ /**
117
+ * Verifica se há arquivos não commitados
118
+ */
119
+ hasUncommittedChanges() {
120
+ if (!this.isGitRepository()) {
121
+ return false;
122
+ }
123
+ try {
124
+ const status = execSync('git status --porcelain', { encoding: 'utf8' });
125
+ return status.trim().length > 0;
126
+ }
127
+ catch {
128
+ return false;
129
+ }
130
+ }
131
+ /**
132
+ * Lista branches disponíveis
133
+ */
134
+ getBranches() {
135
+ if (!this.isGitRepository()) {
136
+ throw new Error('Diretório atual não é um repositório Git');
137
+ }
138
+ try {
139
+ const branchOutput = execSync('git branch', { encoding: 'utf8' });
140
+ const branches = branchOutput
141
+ .split('\n')
142
+ .map(line => line.trim())
143
+ .filter(line => line);
144
+ const current = branches
145
+ .find(branch => branch.startsWith('*'))
146
+ ?.replace('*', '')
147
+ .trim() || '';
148
+ const all = branches.map(branch => branch.replace('*', '').trim());
149
+ return { current, all };
150
+ }
151
+ catch (error) {
152
+ throw new Error(`Erro ao obter branches: ${error}`);
153
+ }
154
+ }
155
+ /**
156
+ * Obtém lista de arquivos alterados (staged)
157
+ */
158
+ getChangedFiles() {
159
+ const status = this.getStagedStatus();
160
+ return status.stagedFiles;
161
+ }
162
+ /**
163
+ * Obtém diff de um arquivo específico
164
+ */
165
+ getFileDiff(filePath) {
166
+ if (!this.isGitRepository()) {
167
+ throw new Error('Diretório atual não é um repositório Git');
168
+ }
169
+ try {
170
+ const diff = execSync(`git diff --cached -- "${filePath}"`, { encoding: 'utf8' });
171
+ return diff;
172
+ }
173
+ catch {
174
+ return '';
175
+ }
176
+ }
177
+ /**
178
+ * Obtém diff completo dos arquivos staged
179
+ */
180
+ getStagedDiff() {
181
+ const status = this.getStagedStatus();
182
+ return status.diff;
183
+ }
184
+ }
185
+ //# sourceMappingURL=git-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-utils.js","sourceRoot":"","sources":["../src/git-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQzC;;GAEG;AACH,MAAM,OAAO,QAAQ;IAGnB,YAAY,kBAA4B,EAAE;QACxC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,eAAe;QACb,IAAI,CAAC;YACH,QAAQ,CAAC,qCAAqC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;YACrE,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,O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AAE,CAAC;QACtC,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,16 +1,2 @@
1
- #!/usr/bin/env ts-node
2
- /**
3
- * Realiza a chamada à API do OpenAI.
4
- * @param prompt Texto que será enviado como mensagem do usuário.
5
- * @param mode Define o contexto: 'commit' para gerar mensagem de commit ou outro valor para resumo.
6
- * @returns Resposta da API (string com a mensagem ou o resumo).
7
- */
8
- export declare function callOpenAI(prompt: string, mode?: string): Promise<string>;
9
- /**
10
- * Divide o diff em chunks menores com base na contagem de tokens.
11
- * Utiliza o gpt-tokenizer para garantir que cada chunk não exceda o limite de tokens.
12
- * @param diff O diff completo em formato de string.
13
- * @param maxTokens Quantidade máxima de tokens permitida para cada chunk (padrão: 1000 tokens).
14
- * @returns Array de strings, cada uma representando um chunk.
15
- */
16
- export declare function chunkDiff(diff: string, maxTokens?: number): string[];
1
+ #!/usr/bin/env node
2
+ export {};