# pr-stale-monitor

Hourly check for stale PRs in ai-configuration repository.

## Description

Monitors open PRs in `tidbcloud/data-service-infra-ai-configurations` and sends a reminder to the Feishu group if any PR has been open for more than 6 hours without being closed.

## File Structure

```
pr-stale-monitor/
├── main.py      # Main entry script
└── README.md
```

## Workflow

```
main.py
  │
  ├── 1. Get Feishu app token (FEISHU_CODE_EXPERT_APP_ID/SECRET)
  │
  ├── 2. Get GitHub token
  │
  ├── 3. Fetch open PRs from GitHub API
  │
  ├── 4. Check PRs open for more than 6 hours
  │
  └── 5. Send reminder to Feishu group
```

## Usage

### Run manually

```bash
cd ~/github/data-service-infra-ai-configurations/cronjobs/team-code-expert/pr-stale-monitor
python3 main.py
```

### Add to cron (hourly)

```bash
# Edit crontab
crontab -e

# Add this line (run at every hour)
0 * * * * cd ~/github/data-service-infra-ai-configurations/cronjobs/team-code-expert/pr-stale-monitor && python3 main.py >> /var/log/pr-stale-monitor.log 2>&1
```

## Configuration

### Environment Variables

Script automatically loads from `~/.bashrc`:

| Variable | Description |
|----------|-------------|
| `FEISHU_CODE_EXPERT_APP_ID` | Feishu app ID |
| `FEISHU_CODE_EXPERT_APP_SECRET` | Feishu app secret |
| `GITHUB_TOKEN` | GitHub token (optional, falls back to `gh auth token`) |

### Configuration Constants

| Constant | Default | Description |
|----------|---------|-------------|
| `REPO` | tidbcloud/data-service-infra-ai-configurations | Repository to monitor |
| `FEISHU_CHAT_ID` | oc_f0e4a980f9ec5e0bcf2111856c7e981f | Feishu group chat ID |
| `STALE_HOURS` | 6 | Hours threshold for stale PRs |

## Output

When stale PRs are found, sends a Feishu message like:

```
🔔 PR Stale Reminder

The following PRs have been open for more than 6 hours:

• #169 feat(daily_pr_merge_status): use FEISHU_CODE_EXPERT env vars
  Author: data-service-code-assistant[bot] | Hours: 6.5h | https://github.com/tidbcloud/data-service-infra-ai-configurations/pull/169

---
Time: 2026-03-19 23:48:00 UTC
```
