Preskočiť na obsah

GitLab integrácia

Táto sekcia popisuje integráciu GitPulse s GitLab.

Prehľad integrácie

graph LR
    subgraph "GitLab"
        REPO["Repository"]
        HOOK["Webhooks"]
        API["GitLab API"]
    end

    subgraph "GitPulse"
        WEBHOOK["Webhook Handler"]
        SYNC["Sync Service"]
        DB[("Database")]
    end

    REPO --> |events| HOOK
    HOOK --> |"POST /webhook"| WEBHOOK
    API --> |"pull data"| SYNC
    WEBHOOK --> DB
    SYNC --> DB

Podporované funkcie

Funkcia Popis Stav
Commits Sledovanie commit history Yes
Merge Requests MR vytvorenie, review, merge Yes
Issues Vytvorenie a zatvorenie issues Yes
Pipelines CI/CD pipeline status Yes
Comments Diskusie na MR a issues Yes
Branches Branch creation/deletion Yes
Tags Release tags Yes

Čo nájdete v tejto sekcii

  • Tokeny


    Konfigurácia GitLab prístupových tokenov

    Tokeny

  • Webhooky


    Nastavenie real-time notifikácií

    Webhooky

  • CI/CD Pipeline


    Integrácia s GitLab CI

    CI/CD

Rýchly štart

1. Vytvorenie tokenu

  1. Prejdite na GitLab -> Settings -> Access Tokens
  2. Vytvorte token s oprávneniami:
  3. api - Full API access
  4. read_repository - Read repository
  5. Uložte token do .env:
Bash
GITLAB_URL=https://gitlab.kpi.tuke.sk
GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxxx

2. Konfigurácia webhook

  1. V GitLab projekte: Settings -> Webhooks
  2. URL: https://gitpulse.kpi.fei.tuke.sk/api/v1/webhooks/gitlab
  3. Secret Token: Vygenerujte a uložte do .env
  4. Trigger events: Push, MR, Issues, Pipeline

3. Test pripojenia

Bash
1
2
3
4
5
6
# Test API pripojenia
curl -H "Private-Token: ${GITLAB_TOKEN}" \
  "${GITLAB_URL}/api/v4/user"

# Test webhook (z GitPulse)
curl -X POST http://localhost:8000/api/v1/webhooks/test

Architektúra

sequenceDiagram
    participant GL as GitLab
    participant WH as Webhook Handler
    participant Q as Redis Queue
    participant W as Worker
    participant DB as Database

    GL->>WH: POST /webhooks/gitlab
    WH->>WH: Verify signature
    WH->>Q: Enqueue event
    WH-->>GL: 200 OK

    W->>Q: Dequeue event
    W->>W: Process event
    W->>DB: Store event
    W->>W: Calculate metrics

Podporované event typy

Push Events

JSON
{
  "object_kind": "push",
  "event_name": "push",
  "ref": "refs/heads/main",
  "commits": [
    {
      "id": "abc123...",
      "message": "feat: add new feature",
      "author": {
        "name": "John Doe",
        "email": "john@example.com"
      },
      "added": ["file1.py"],
      "modified": ["file2.py"],
      "removed": []
    }
  ]
}

Merge Request Events

JSON
{
  "object_kind": "merge_request",
  "event_type": "merge_request",
  "object_attributes": {
    "iid": 1,
    "title": "Feature: Add login",
    "state": "merged",
    "source_branch": "feature/login",
    "target_branch": "main",
    "author_id": 123
  }
}

Pipeline Events

JSON
1
2
3
4
5
6
7
8
9
{
  "object_kind": "pipeline",
  "object_attributes": {
    "id": 456,
    "status": "success",
    "duration": 120,
    "stages": ["build", "test", "deploy"]
  }
}

Limity a rate limiting

Resource Limit Poznámka
API requests 600/min Per token
Webhook payload 25 MB Max payload size
Concurrent webhooks 10 Per project

Bezpečnosť

  • Všetky tokeny sú uložené šifrované
  • Webhook signature verification
  • IP whitelist pre webhook endpoints (odporúčané)
  • Audit log všetkých API volaní

Ďalšie kroky

  1. Konfigurácia tokenov
  2. Nastavenie webhookov
  3. GitLab CI integrácia