guild-agents 0.0.1 → 0.1.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,126 @@
1
+ /**
2
+ * github.js — Integración con GitHub CLI (gh)
3
+ *
4
+ * Requiere que el usuario tenga gh instalado y autenticado.
5
+ * Todas las operaciones son no-bloqueantes — si gh no está disponible,
6
+ * Guild funciona normalmente sin integración GitHub.
7
+ */
8
+
9
+ import { execSync } from 'child_process';
10
+
11
+ const LABELS = [
12
+ { name: 'backlog', color: '8E8E8E', description: 'Tarea documentada, pendiente de iniciar' },
13
+ { name: 'in-progress', color: '0075CA', description: 'En implementación' },
14
+ { name: 'in-review', color: 'E4A800', description: 'En validación QA' },
15
+ { name: 'done', color: '2EA44F', description: 'Completada y mergeada' },
16
+ { name: 'bug', color: 'D73A4A', description: 'Bug reportado por QA' },
17
+ { name: 'blocked', color: 'E99695', description: 'Bloqueada por dependencia' },
18
+ ];
19
+
20
+ /**
21
+ * Verifica si gh CLI está instalado y autenticado.
22
+ */
23
+ export function isGhAvailable() {
24
+ try {
25
+ execSync('gh auth status', { stdio: 'ignore' });
26
+ return true;
27
+ } catch {
28
+ return false;
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Configura los labels de estado en el repositorio GitHub.
34
+ */
35
+ export async function setupGithubLabels(repoUrl) {
36
+ if (!isGhAvailable()) {
37
+ console.warn('gh CLI no disponible — saltando configuración de labels.');
38
+ return;
39
+ }
40
+
41
+ const repo = extractRepoFromUrl(repoUrl);
42
+ if (!repo) return;
43
+
44
+ for (const label of LABELS) {
45
+ try {
46
+ execSync(
47
+ `gh label create "${label.name}" --color "${label.color}" --description "${label.description}" --repo ${repo} --force`,
48
+ { stdio: 'ignore' }
49
+ );
50
+ } catch {
51
+ // Label ya existe o error no crítico
52
+ }
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Asigna un issue a @me y cambia su label de estado.
58
+ */
59
+ export function assignIssue(issueNumber, fromLabel, toLabel) {
60
+ if (!isGhAvailable()) return;
61
+
62
+ try {
63
+ execSync(`gh issue assign ${issueNumber} --assignee @me`, { stdio: 'ignore' });
64
+ execSync(`gh issue edit ${issueNumber} --add-label "${toLabel}" --remove-label "${fromLabel}"`, { stdio: 'ignore' });
65
+ } catch {
66
+ // Non-critical
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Agrega un comentario a un issue.
72
+ */
73
+ export function commentIssue(issueNumber, body) {
74
+ if (!isGhAvailable()) return;
75
+
76
+ try {
77
+ execSync(`gh issue comment ${issueNumber} --body "${body}"`, { stdio: 'ignore' });
78
+ } catch {
79
+ // Non-critical
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Cierra un issue con un comentario.
85
+ */
86
+ export function closeIssue(issueNumber, comment) {
87
+ if (!isGhAvailable()) return;
88
+
89
+ try {
90
+ execSync(`gh issue close ${issueNumber} --comment "${comment}"`, { stdio: 'ignore' });
91
+ } catch {
92
+ // Non-critical
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Crea un issue de bug referenciando una tarea padre.
98
+ */
99
+ export function createBugIssue(title, body, parentIssueNumber) {
100
+ if (!isGhAvailable()) return null;
101
+
102
+ try {
103
+ const result = execSync(
104
+ `gh issue create --title "${title}" --body "${body}" --label "bug"`,
105
+ { encoding: 'utf8' }
106
+ );
107
+ const issueUrl = result.trim();
108
+ const issueNumber = issueUrl.split('/').pop();
109
+
110
+ if (parentIssueNumber) {
111
+ commentIssue(parentIssueNumber, `Bug encontrado: ${issueUrl}`);
112
+ }
113
+
114
+ return { number: issueNumber, url: issueUrl };
115
+ } catch {
116
+ return null;
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Extrae "owner/repo" de una URL de GitHub.
122
+ */
123
+ function extractRepoFromUrl(url) {
124
+ const match = url.match(/github\.com[/:]([^/]+\/[^/]+?)(?:\.git)?$/);
125
+ return match ? match[1] : null;
126
+ }
package/index.js DELETED
@@ -1 +0,0 @@
1
- // Guild Agents - coming soon