gitlab-skill 1.0.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,682 @@
1
+ # GitLab API - Referencia Rápida
2
+
3
+ > Cheatsheet para acceso rápido a comandos y patrones más comunes
4
+
5
+ ---
6
+
7
+ ## Autenticación Rápida
8
+
9
+ ```bash
10
+ # REST API
11
+ export GITLAB_TOKEN="tu-token-aqui"
12
+ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
13
+ --url "https://gitlab.example.com/api/v4/user"
14
+
15
+ # GraphQL API
16
+ curl --request POST \
17
+ --header "Authorization: Bearer $GITLAB_TOKEN" \
18
+ --header "Content-Type: application/json" \
19
+ --data '{"query": "query {currentUser {name}}"}' \
20
+ --url "https://gitlab.com/api/graphql"
21
+
22
+ # glab CLI
23
+ glab auth login
24
+ # o
25
+ export GITLAB_TOKEN="tu-token-aqui"
26
+ glab api user
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Top 10 Operaciones REST API
32
+
33
+ ### 1. Listar proyectos
34
+ ```bash
35
+ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
36
+ --url "https://gitlab.example.com/api/v4/projects?per_page=50"
37
+ ```
38
+
39
+ ### 2. Crear issue
40
+ ```bash
41
+ curl --request POST \
42
+ --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
43
+ --header "Content-Type: application/json" \
44
+ --data '{"title": "Bug en login", "labels": "bug,high-priority"}' \
45
+ --url "https://gitlab.example.com/api/v4/projects/123/issues"
46
+ ```
47
+
48
+ ### 3. Crear merge request
49
+ ```bash
50
+ curl --request POST \
51
+ --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
52
+ --header "Content-Type: application/json" \
53
+ --data '{
54
+ "source_branch": "feature-branch",
55
+ "target_branch": "main",
56
+ "title": "Add new feature"
57
+ }' \
58
+ --url "https://gitlab.example.com/api/v4/projects/123/merge_requests"
59
+ ```
60
+
61
+ ### 4. Ejecutar pipeline
62
+ ```bash
63
+ curl --request POST \
64
+ --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
65
+ --url "https://gitlab.example.com/api/v4/projects/123/pipeline?ref=main"
66
+ ```
67
+
68
+ ### 5. Obtener archivo
69
+ ```bash
70
+ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
71
+ --url "https://gitlab.example.com/api/v4/projects/123/repository/files/README.md/raw?ref=main"
72
+ ```
73
+
74
+ ### 6. Crear archivo
75
+ ```bash
76
+ curl --request POST \
77
+ --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
78
+ --header "Content-Type: application/json" \
79
+ --data '{
80
+ "branch": "main",
81
+ "commit_message": "Add file",
82
+ "content": "File content"
83
+ }' \
84
+ --url "https://gitlab.example.com/api/v4/projects/123/repository/files/new-file.txt"
85
+ ```
86
+
87
+ ### 7. Listar pipelines
88
+ ```bash
89
+ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
90
+ --url "https://gitlab.example.com/api/v4/projects/123/pipelines?status=running"
91
+ ```
92
+
93
+ ### 8. Obtener jobs de pipeline
94
+ ```bash
95
+ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
96
+ --url "https://gitlab.example.com/api/v4/projects/123/pipelines/456/jobs"
97
+ ```
98
+
99
+ ### 9. Crear release
100
+ ```bash
101
+ curl --request POST \
102
+ --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
103
+ --header "Content-Type: application/json" \
104
+ --data '{
105
+ "tag_name": "v1.0.0",
106
+ "name": "Release 1.0.0",
107
+ "description": "Release notes"
108
+ }' \
109
+ --url "https://gitlab.example.com/api/v4/projects/123/releases"
110
+ ```
111
+
112
+ ### 10. Crear variable CI/CD
113
+ ```bash
114
+ curl --request POST \
115
+ --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
116
+ --header "Content-Type: application/json" \
117
+ --data '{
118
+ "key": "DEPLOY_KEY",
119
+ "value": "secret-value",
120
+ "protected": true,
121
+ "masked": true
122
+ }' \
123
+ --url "https://gitlab.example.com/api/v4/projects/123/variables"
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Top 10 Operaciones GraphQL
129
+
130
+ ### 1. Query usuario actual
131
+ ```graphql
132
+ query {
133
+ currentUser {
134
+ id
135
+ username
136
+ name
137
+ email
138
+ }
139
+ }
140
+ ```
141
+
142
+ ### 2. Query proyecto con issues
143
+ ```graphql
144
+ query {
145
+ project(fullPath: "grupo/proyecto") {
146
+ id
147
+ name
148
+ issues(first: 10, state: OPENED) {
149
+ nodes {
150
+ iid
151
+ title
152
+ state
153
+ }
154
+ }
155
+ }
156
+ }
157
+ ```
158
+
159
+ ### 3. Query merge requests
160
+ ```graphql
161
+ query {
162
+ project(fullPath: "grupo/proyecto") {
163
+ mergeRequests(first: 10, state: OPENED) {
164
+ nodes {
165
+ iid
166
+ title
167
+ sourceBranch
168
+ targetBranch
169
+ }
170
+ }
171
+ }
172
+ }
173
+ ```
174
+
175
+ ### 4. Mutation: Crear issue
176
+ ```graphql
177
+ mutation {
178
+ createIssue(input: {
179
+ projectPath: "grupo/proyecto",
180
+ title: "Bug en login"
181
+ }) {
182
+ issue {
183
+ iid
184
+ title
185
+ }
186
+ errors
187
+ }
188
+ }
189
+ ```
190
+
191
+ ### 5. Mutation: Crear MR
192
+ ```graphql
193
+ mutation {
194
+ mergeRequestCreate(input: {
195
+ projectPath: "grupo/proyecto",
196
+ sourceBranch: "feature",
197
+ targetBranch: "main",
198
+ title: "Add feature"
199
+ }) {
200
+ mergeRequest {
201
+ iid
202
+ title
203
+ }
204
+ errors
205
+ }
206
+ }
207
+ ```
208
+
209
+ ### 6. Mutation: Cerrar issue
210
+ ```graphql
211
+ mutation {
212
+ updateIssue(input: {
213
+ projectPath: "grupo/proyecto",
214
+ iid: "42",
215
+ stateEvent: CLOSE
216
+ }) {
217
+ issue {
218
+ iid
219
+ state
220
+ }
221
+ errors
222
+ }
223
+ }
224
+ ```
225
+
226
+ ### 7. Mutation: Agregar comentario
227
+ ```graphql
228
+ mutation {
229
+ createNote(input: {
230
+ noteableId: "gid://gitlab/Issue/123",
231
+ body: "Comentario"
232
+ }) {
233
+ note {
234
+ id
235
+ body
236
+ }
237
+ errors
238
+ }
239
+ }
240
+ ```
241
+
242
+ ### 8. Query pipelines
243
+ ```graphql
244
+ query {
245
+ project(fullPath: "grupo/proyecto") {
246
+ pipelines(first: 10, status: RUNNING) {
247
+ nodes {
248
+ id
249
+ iid
250
+ status
251
+ ref
252
+ }
253
+ }
254
+ }
255
+ }
256
+ ```
257
+
258
+ ### 9. Mutation: Crear pipeline
259
+ ```graphql
260
+ mutation {
261
+ pipelineCreate(input: {
262
+ projectPath: "grupo/proyecto",
263
+ ref: "main"
264
+ }) {
265
+ pipeline {
266
+ id
267
+ iid
268
+ }
269
+ errors
270
+ }
271
+ }
272
+ ```
273
+
274
+ ### 10. Query con paginación
275
+ ```graphql
276
+ query($cursor: String) {
277
+ project(fullPath: "grupo/proyecto") {
278
+ issues(first: 20, after: $cursor) {
279
+ edges {
280
+ node {
281
+ iid
282
+ title
283
+ }
284
+ cursor
285
+ }
286
+ pageInfo {
287
+ hasNextPage
288
+ endCursor
289
+ }
290
+ }
291
+ }
292
+ }
293
+ ```
294
+
295
+ ---
296
+
297
+ ## Top 10 Comandos glab CLI
298
+
299
+ ### 1. Autenticación
300
+ ```bash
301
+ glab auth login
302
+ ```
303
+
304
+ ### 2. Listar issues
305
+ ```bash
306
+ glab issue list --state opened --label bug
307
+ ```
308
+
309
+ ### 3. Crear issue
310
+ ```bash
311
+ glab issue create --title "Bug" --description "Descripción" --label bug
312
+ ```
313
+
314
+ ### 4. Listar merge requests
315
+ ```bash
316
+ glab mr list --state opened
317
+ ```
318
+
319
+ ### 5. Crear merge request
320
+ ```bash
321
+ glab mr create --source-branch feature --target-branch main --title "Feature"
322
+ ```
323
+
324
+ ### 6. Ver pipeline
325
+ ```bash
326
+ glab ci status
327
+ glab ci view
328
+ ```
329
+
330
+ ### 7. Ver trace de job
331
+ ```bash
332
+ glab ci trace
333
+ glab ci trace <job-id>
334
+ ```
335
+
336
+ ### 8. Clonar proyecto
337
+ ```bash
338
+ glab repo clone grupo/proyecto
339
+ ```
340
+
341
+ ### 9. Llamada directa a API
342
+ ```bash
343
+ glab api projects/123
344
+ glab api --method POST projects/123/issues --field title="Issue"
345
+ ```
346
+
347
+ ### 10. Listar releases
348
+ ```bash
349
+ glab release list
350
+ ```
351
+
352
+ ---
353
+
354
+ ## Paginación Rápida
355
+
356
+ ### REST - Offset
357
+ ```bash
358
+ # Página 2, 50 items
359
+ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
360
+ --url "https://gitlab.example.com/api/v4/projects?page=2&per_page=50"
361
+ ```
362
+
363
+ ### REST - Keyset (más eficiente)
364
+ ```bash
365
+ # Primera página
366
+ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
367
+ --url "https://gitlab.example.com/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc"
368
+
369
+ # Siguiente (usar id_after del último item)
370
+ curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
371
+ --url "https://gitlab.example.com/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc&id_after=42"
372
+ ```
373
+
374
+ ### GraphQL
375
+ ```graphql
376
+ # Primera página
377
+ query {
378
+ project(fullPath: "grupo/proyecto") {
379
+ issues(first: 20) {
380
+ pageInfo {
381
+ hasNextPage
382
+ endCursor
383
+ }
384
+ nodes { iid title }
385
+ }
386
+ }
387
+ }
388
+
389
+ # Siguiente (usar endCursor)
390
+ query {
391
+ project(fullPath: "grupo/proyecto") {
392
+ issues(first: 20, after: "cursor-value") {
393
+ pageInfo {
394
+ hasNextPage
395
+ endCursor
396
+ }
397
+ nodes { iid title }
398
+ }
399
+ }
400
+ }
401
+ ```
402
+
403
+ ---
404
+
405
+ ## Manejo de Errores
406
+
407
+ ### Verificar código HTTP
408
+ ```bash
409
+ HTTP_CODE=$(curl --write-out '%{http_code}' --silent --output /dev/null \
410
+ --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
411
+ --url "https://gitlab.example.com/api/v4/projects/123")
412
+
413
+ echo "HTTP Code: $HTTP_CODE"
414
+ ```
415
+
416
+ ### Retry con backoff
417
+ ```bash
418
+ retry_api_call() {
419
+ local url="$1"
420
+ local max_attempts=5
421
+ local timeout=1
422
+
423
+ for attempt in $(seq 1 $max_attempts); do
424
+ HTTP_CODE=$(curl --write-out '%{http_code}' --silent --output response.json \
425
+ --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "$url")
426
+
427
+ if [ "$HTTP_CODE" -eq 429 ]; then
428
+ echo "Rate limited, waiting ${timeout}s..."
429
+ sleep $timeout
430
+ timeout=$((timeout * 2))
431
+ elif [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
432
+ cat response.json
433
+ return 0
434
+ else
435
+ echo "Error: HTTP $HTTP_CODE"
436
+ return 1
437
+ fi
438
+ done
439
+ }
440
+ ```
441
+
442
+ ### Verificar errores GraphQL
443
+ ```bash
444
+ RESPONSE=$(curl --request POST --silent \
445
+ --header "Authorization: Bearer $GITLAB_TOKEN" \
446
+ --header "Content-Type: application/json" \
447
+ --data '{"query": "query {currentUser {name}}"}' \
448
+ --url "https://gitlab.com/api/graphql")
449
+
450
+ if echo "$RESPONSE" | jq -e '.errors' > /dev/null; then
451
+ echo "Errors found:"
452
+ echo "$RESPONSE" | jq '.errors'
453
+ else
454
+ echo "$RESPONSE" | jq '.data'
455
+ fi
456
+ ```
457
+
458
+ ---
459
+
460
+ ## Códigos HTTP Comunes
461
+
462
+ | Código | Significado | Acción |
463
+ |--------|-------------|--------|
464
+ | 200 | OK | Procesar respuesta |
465
+ | 201 | Created | Recurso creado |
466
+ | 204 | No Content | Éxito sin datos |
467
+ | 400 | Bad Request | Verificar parámetros |
468
+ | 401 | Unauthorized | Verificar token |
469
+ | 403 | Forbidden | Verificar permisos |
470
+ | 404 | Not Found | Verificar ID/path |
471
+ | 409 | Conflict | Recurso ya existe |
472
+ | 422 | Unprocessable | Validación falló |
473
+ | 429 | Too Many Requests | Rate limit - esperar |
474
+ | 500 | Server Error | Reintentar más tarde |
475
+ | 503 | Service Unavailable | Servidor sobrecargado |
476
+
477
+ ---
478
+
479
+ ## Filtros Comunes
480
+
481
+ ### Issues
482
+ ```bash
483
+ # Por estado
484
+ ?state=opened
485
+ ?state=closed
486
+
487
+ # Por labels
488
+ ?labels=bug,critical
489
+
490
+ # Por assignee
491
+ ?assignee_id=5
492
+
493
+ # Por milestone
494
+ ?milestone=v1.0
495
+
496
+ # Por búsqueda
497
+ ?search=login
498
+ ```
499
+
500
+ ### Merge Requests
501
+ ```bash
502
+ # Por estado
503
+ ?state=opened
504
+ ?state=merged
505
+
506
+ # Por autor
507
+ ?author_id=5
508
+
509
+ # Por reviewer
510
+ ?reviewer_id=10
511
+
512
+ # Por source branch
513
+ ?source_branch=feature-branch
514
+
515
+ # Por target branch
516
+ ?target_branch=main
517
+ ```
518
+
519
+ ### Pipelines
520
+ ```bash
521
+ # Por estado
522
+ ?status=running
523
+ ?status=success
524
+ ?status=failed
525
+
526
+ # Por ref
527
+ ?ref=main
528
+
529
+ # Por SHA
530
+ ?sha=abc123
531
+
532
+ # Por fecha
533
+ ?updated_after=2026-01-01T00:00:00Z
534
+ ?updated_before=2026-12-31T23:59:59Z
535
+ ```
536
+
537
+ ---
538
+
539
+ ## Variables de Entorno glab
540
+
541
+ ```bash
542
+ # Token de autenticación
543
+ export GITLAB_TOKEN="tu-token"
544
+
545
+ # Host de GitLab
546
+ export GITLAB_HOST="https://gitlab.example.com"
547
+ export GL_HOST="https://gitlab.example.com"
548
+
549
+ # Deshabilitar prompts
550
+ export NO_PROMPT=true
551
+
552
+ # Debug
553
+ export DEBUG=true
554
+
555
+ # Config directory
556
+ export GLAB_CONFIG_DIR="$HOME/.config/glab"
557
+ ```
558
+
559
+ ---
560
+
561
+ ## Scopes de Tokens
562
+
563
+ | Scope | Descripción |
564
+ |-------|-------------|
565
+ | `api` | Read-write completo (REST + GraphQL) |
566
+ | `read_api` | Read-only (REST + GraphQL) |
567
+ | `read_repository` | Read-only repositorio |
568
+ | `write_repository` | Write repositorio |
569
+ | `sudo` | Actuar como otro usuario (admin) |
570
+
571
+ ---
572
+
573
+ ## URL Encoding
574
+
575
+ ```bash
576
+ # Caracteres especiales
577
+ / → %2F
578
+ ? → %3F
579
+ @ → %40
580
+ + → %2B
581
+ = → %3D
582
+ & → %26
583
+
584
+ # Ejemplos
585
+ grupo/proyecto → grupo%2Fproyecto
586
+ src/app.js → src%2Fapp.js
587
+ feature/new-feature → feature%2Fnew-feature
588
+ ```
589
+
590
+ ---
591
+
592
+ ## Límites Importantes
593
+
594
+ | Límite | Valor |
595
+ |--------|-------|
596
+ | REST - Per page (max) | 100 |
597
+ | REST - Per page (default) | 20 |
598
+ | GraphQL - Complejidad (no auth) | 200 |
599
+ | GraphQL - Complejidad (auth) | 250 |
600
+ | GraphQL - Query size | 10,000 caracteres |
601
+ | GraphQL - Page size (max) | 100 |
602
+ | Request timeout | 30 segundos |
603
+ | Blob size (multiple) | 20 MB |
604
+
605
+ ---
606
+
607
+ ## Scripts Útiles
608
+
609
+ ### Listar todos los proyectos (con paginación)
610
+ ```bash
611
+ #!/bin/bash
612
+ page=1
613
+ while true; do
614
+ response=$(curl --silent \
615
+ --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
616
+ --url "https://gitlab.example.com/api/v4/projects?page=$page&per_page=100")
617
+
618
+ if [ "$(echo "$response" | jq '. | length')" -eq 0 ]; then
619
+ break
620
+ fi
621
+
622
+ echo "$response" | jq -r '.[] | "\(.id) - \(.name)"'
623
+ page=$((page + 1))
624
+ done
625
+ ```
626
+
627
+ ### Monitorear pipeline
628
+ ```bash
629
+ #!/bin/bash
630
+ PROJECT_ID="123"
631
+ PIPELINE_ID="456"
632
+
633
+ while true; do
634
+ status=$(curl --silent \
635
+ --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
636
+ --url "https://gitlab.example.com/api/v4/projects/$PROJECT_ID/pipelines/$PIPELINE_ID" \
637
+ | jq -r '.status')
638
+
639
+ echo "Pipeline status: $status"
640
+
641
+ if [[ "$status" == "success" || "$status" == "failed" || "$status" == "canceled" ]]; then
642
+ break
643
+ fi
644
+
645
+ sleep 10
646
+ done
647
+ ```
648
+
649
+ ### Crear issue en bulk
650
+ ```bash
651
+ #!/bin/bash
652
+ PROJECT_ID="123"
653
+
654
+ while IFS=',' read -r title description labels; do
655
+ curl --request POST \
656
+ --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
657
+ --header "Content-Type: application/json" \
658
+ --data "{
659
+ \"title\": \"$title\",
660
+ \"description\": \"$description\",
661
+ \"labels\": \"$labels\"
662
+ }" \
663
+ --url "https://gitlab.example.com/api/v4/projects/$PROJECT_ID/issues"
664
+
665
+ sleep 1 # Rate limiting
666
+ done < issues.csv
667
+ ```
668
+
669
+ ---
670
+
671
+ ## Recursos Rápidos
672
+
673
+ - **Docs REST**: https://docs.gitlab.com/api/rest/
674
+ - **Docs GraphQL**: https://docs.gitlab.com/api/graphql/
675
+ - **GraphQL Reference**: https://docs.gitlab.com/api/graphql/reference/
676
+ - **GraphQL Explorer**: https://gitlab.com/-/graphql-explorer
677
+ - **glab Docs**: https://docs.gitlab.com/cli/
678
+ - **Status Codes**: https://docs.gitlab.com/api/rest/troubleshooting/#status-codes
679
+
680
+ ---
681
+
682
+ **Última actualización**: 18 de febrero de 2026