# weekly-ticket-report

Cron job for team-workflow role.

## Description

Generate TCOC weekly summary report. Queries Jira for tickets created in the past week, categorizes by component (Import/DM/BR/CDC), and posts summary to Feishu.

## New Feature: Summary Section

Add a text summary section at the top of the weekly report.

### Required Data

| 数据项 | 来源 | 字段 |
|--------|------|-------|
| Import 新增任务数 | Bitable - Failed Jobs | Component="Import", Time=本周 |
| Import 失败任务数 | Bitable - Failed Jobs | Component="Import", Time=本周 |
| BR 新增任务数 | Bitable - Failed Jobs | Component="BR", Time=本周 |
| BR 失败任务数 | Bitable - Failed Jobs | Component="BR", Time=本周 |
| DM 正在运行 | (Future PR) | Component="DM", Status="Running" |
| CDC 正在运行 | (Future PR) | Component="CDC", Status="Running" |
| TCOC 统计 | Bitable - Oncall Records | Category="TCOC" |
| Critical Alert | Bitable - Oncall Records | Category="ALERT" |

### Output Format

```markdown
## 汇总

- **任务运行数据**
  - Import 新增 10 任务，失败 2 任务，成功率 80%
  - BR 新增 5 任务，失败 1 任务，成功率 80%

- **风险情况**
  - TCOC 共计 5 个
    - (DM: 3, Import: 2)
  - Critical Alert 共计 12 个
    - (CDC: 8, BR: 4)
```

### Implementation Plan

1. Add new function `generate_summary_section(records)` in `main.py`
2. Query Failed Jobs Bitable for Import/BR statistics
3. Calculate success rate
4. Insert summary at the **top of the report** (before existing Summary table)
5. Also include this summary in the **Feishu notification message**

### Future Enhancements

- Add DM running tasks count (from Bitable/Grafana)
- Add CDC running tasks count (from Bitable/Grafana)

## Cron Schedule

UTC 1:30 every Thursday / UTC+8 9:30 every Thursday (`30 1 * * 4`)

## Usage

```bash
SKIP_SEND_NOTIFICATION=true python3 $AI_CONFIG_REPO/cronjobs/team-workflow/weekly-ticket-report/main.py
```

## Environment Variables

- `JIRA_API_TOKEN` - Required for Jira API access
- `JIRA_USER` - Jira username (qiang.wu@pingcap.com)
- `CRONJOB_TEAM_WORKFLOW_APP_ID` - Feishu app ID
- `CRONJOB_TEAM_WORKFLOW_APP_SECRET` - Feishu app secret
- `CRONJOB_TEAM_WORKFLOW_NOTIFY_CHAT_ID` - Feishu group for notifications (default: oc_2c586abb5204eca2ddf6ddf5de338bf6)
- `SKIP_UPLOAD_FEISHU_DOC` - Set to "true" to skip uploading to Feishu Wiki (useful for testing, default: false)

## Output

- Feishu Card message with summary
- Wiki document with detailed TCOC links

## Related Files

- Script: `cronjobs/team-workflow/weekly-ticket-report/main.py`
