Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copie para mgi-workspace/.env (nao commitar). Valores sao exemplos — ajuste ao seu ambiente.

# --- Supabase (obrigatorio para sync) ---
SUPABASE_URL=https://xxx.supabase.co
SUPABASE_SERVICE_ROLE_KEY=

# --- GitLab API (obrigatorio para baixar issues) ---
GITLAB_URL=https://gitlab.com
GITLAB_TOKEN=
# GITLAB_TOKEN_CONTRATOS_V2=
# GITLAB_TOKEN_CONTRATOS=

# --- Repositorios Git locais (coleta de commits/branches/releases) ---
# Formato: caminho_local=slug;outro_caminho=slug
# Exemplo Windows + WSL (ajuste ao seu ambiente):
# MGI_REPOS=/mnt/mgi/contratos_v2=contratos_v2;/mnt/mgi/contratos=contratos

# --- Caminhos WSL para detectores Git (git log dentro do Ubuntu) ---
# Formato: slug=/caminho/no/wsl;slug2=/caminho2
# MGI_WSL_REPO_PATHS=contratos_v2=/root/MGI/contratos_v2;contratos=/root/MGI/contratos

# --- Provisionamento de usuarios (provision_gitlab_users.py) ---
# MGI_PROVISION_PASSWORD=

# --- Pipeline ---
# MGI_BASE_DIR=D:\mgi-workspace
# MGI_ALL_MODULES=1
# MGI_CLOSED_EXCLUDE_DAYS=60
# MGI_SINCE_DAYS=30
42 changes: 0 additions & 42 deletions .github/workflows/mirror-gitlab.yml

This file was deleted.

54 changes: 54 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: requirements-dev.txt

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt

- name: Ruff
run: ruff check .

pytest:
runs-on: ubuntu-latest
needs: lint
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: requirements-dev.txt

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt

- name: Run tests with coverage
run: pytest
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ venv/
# Segredos e ambiente
.env
.env.*
!.env.example

# Artefatos gerados pela pipeline
gitlab_issues_raw.json
Expand All @@ -20,8 +21,9 @@ gitlab_fiscalizacao_data.json
gitlab_git_data.json
*.log

# Excel gerado (fica na raiz do workspace)
# Excel gerado (fica na raiz do workspace ou em templates/)
*.xlsx
templates/*.xlsx

# IDE / OS
.DS_Store
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 MariaHilmar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 32 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# MGI KPI Pipeline

[![Tests](https://github.com/MariaHilmar/mgi-kpi-pipeline/actions/workflows/tests.yml/badge.svg)](https://github.com/MariaHilmar/mgi-kpi-pipeline/actions/workflows/tests.yml)
[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

Pipeline que coleta dados de issues e commits dos repositórios GitLab do MGI,
processa tudo **em memória** (taxonomia, área funcional, tipo, enriquecimento
Dev/Git, qualidade) e sincroniza direto com o Supabase, que alimenta o dashboard
Expand Down Expand Up @@ -31,8 +35,12 @@ de Excel/openpyxl.

## Estrutura

O código é "flat" (arquivos na raiz) por compatibilidade com os scripts de
orquestração/agendador que chamam os módulos pelo nome. Principais módulos:
O código fica na **raiz do repositório** (layout "flat"), de propósito: os scripts
de orquestração e o Task Scheduler do Windows invocam os módulos pelo nome de
arquivo (`python pipeline_maestro.py`, etc.). Uma pasta `src/` seria mais comum
em bibliotecas publicadas no PyPI; aqui a prioridade é operação local e CI simples.

Principais módulos:

| Módulo | Responsabilidade |
|--------|------------------|
Expand All @@ -51,10 +59,6 @@ orquestração/agendador que chamam os módulos pelo nome. Principais módulos:
| `backfill_profile_gitlab_ids.py` | Vincula `profiles.gitlab_user_id` por e-mail (contas já existentes). |
| `provision_gitlab_users.py` | Cria contas Supabase a partir de membros GitLab (com `gitlab_user_id`). |

> Os módulos do antigo fluxo Excel (`process_gitlab_issues_v2.py`,
> `gerar_graficos_dashboard.py`, `excel_com_save.py`, etc.) permanecem no
> repositório como legado, mas **não são mais chamados pelo fluxo principal**.

Testes em `tests/` (`pytest`).

## Requisitos
Expand All @@ -72,11 +76,13 @@ pip install -r requirements-dev.txt
## Variáveis de ambiente

Todas opcionais (têm default em `config.py`). Para o sync, use um `.env` na
raiz do workspace (`mgi-workspace/.env`).
raiz do workspace (`mgi-workspace/.env`). Veja `.env.example` neste repositório.

| Variável | Default | Descrição |
|----------|---------|-----------|
| `MGI_BASE_DIR` | pasta do workspace | Base para logs/JSON. |
| `MGI_REPOS` | *(vazio)* | Caminhos locais dos clones Git: `path=repo_slug;path2=slug2`. Ver `.env.example`. |
| `MGI_WSL_REPO_PATHS` | slugs padrão MGI | Caminhos WSL para `git log`: `slug=/wsl/path;slug2=/path2`. |
| `MGI_ISSUES_JSON` | `mgi-kpi-pipeline/gitlab_issues_raw.json` | Fonte das issues processadas. |
| `MGI_ALL_MODULES` | `1` | `1` = todos os módulos; `0` = só `Fiscalização`/`Fornecedor`. |
| `MGI_CLOSED_EXCLUDE_DAYS` | `60` | Exclui issues fechadas há mais de N dias. |
Expand Down Expand Up @@ -118,16 +124,32 @@ python backfill_profile_gitlab_ids.py --dry-run
python backfill_profile_gitlab_ids.py
```

## Testes
## Agendamento (opcional — Windows)

Para execução diária automática no **Windows Task Scheduler**, use
`agendar_task_scheduler.ps1` / `desagendar_task_scheduler.ps1`.
Não é necessário para desenvolvimento nem para o repositório público — apenas
para quem roda o pipeline em máquina Windows de produção. Detalhes em
[docs/05-agendamento.md](docs/05-agendamento.md).

## Testes e qualidade

```bash
pytest
pytest # testes + cobertura mínima (38%)
ruff check . # lint
```

A suíte cobre a derivação de campos (`issue_fields`), a construção de records
(`processar_issues_memoria`), os filtros e o cliente de sync (`sync_supabase`,
com `requests` mockado), além das funções puras de taxonomia, datas e chaves.
O CI (`.gitlab-ci.yml`) roda `pytest` a cada push/MR.

## Repositório e CI

**Repositório canônico:** [GitHub — MariaHilmar/mgi-kpi-pipeline](https://github.com/MariaHilmar/mgi-kpi-pipeline).
Detalhes em [docs/08-repositorio-github.md](docs/08-repositorio-github.md).

CI no GitHub Actions: `ruff check` + `pytest` (Python 3.11/3.12). Referência
de CI GitLab legado: [docs/legacy-gitlab-ci.yml](docs/legacy-gitlab-ci.yml).

## Banco de dados (Supabase)

Expand Down
Loading
Loading