|
| 1 | +<!-- |
| 2 | +Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +contributor license agreements. See the NOTICE file distributed with |
| 4 | +this work for additional information regarding copyright ownership. |
| 5 | +The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +(the "License"); you may not use this file except in compliance with |
| 7 | +the License. You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +--> |
| 17 | + |
| 18 | +# GitHub Plugin - Bot Filtering |
| 19 | + |
| 20 | +## Overview |
| 21 | + |
| 22 | +The GitHub plugin supports filtering bot-generated PRs, reviews, and comments from data collection to prevent them from skewing metrics like lead time for changes and PR pickup time. |
| 23 | + |
| 24 | +## Configuration |
| 25 | + |
| 26 | +Set the `GITHUB_PR_EXCLUDELIST` environment variable with a comma-separated list of bot usernames to exclude: |
| 27 | + |
| 28 | +```bash |
| 29 | +export GITHUB_PR_EXCLUDELIST="renovate[bot],dependabot[bot],github-actions[bot]" |
| 30 | +``` |
| 31 | + |
| 32 | +## Common Bot Usernames |
| 33 | + |
| 34 | +- `renovate[bot]` - Renovate dependency updates |
| 35 | +- `dependabot[bot]` - GitHub Dependabot |
| 36 | +- `github-actions[bot]` - GitHub Actions automated PRs |
| 37 | +- `sonarcloud[bot]` - SonarCloud code analysis |
| 38 | +- `codecov[bot]` - Codecov coverage reports |
| 39 | + |
| 40 | +## What Gets Filtered |
| 41 | + |
| 42 | +When a username is in the exclusion list, the following entities are NOT collected: |
| 43 | + |
| 44 | +1. **Pull Requests** - PRs authored by bots |
| 45 | +2. **PR Reviews** - Reviews submitted by bots |
| 46 | +3. **PR Review Comments** - Comments on PR reviews by bots |
| 47 | +4. **Issue Comments** - Comments on issues by bots |
| 48 | + |
| 49 | +## How It Works |
| 50 | + |
| 51 | +- Filtering happens at the **extraction** layer |
| 52 | +- Raw API responses are still saved (in `_raw_github_api_*` tables) |
| 53 | +- Filtered entities never reach the tool layer tables |
| 54 | +- Metrics queries only see non-bot entities |
| 55 | + |
| 56 | +## Matching Rules |
| 57 | + |
| 58 | +- **Case-insensitive**: `renovate[bot]` matches `Renovate[bot]` and `RENOVATE[BOT]` |
| 59 | +- **Exact match**: Must match the full username |
| 60 | +- **Whitespace trimmed**: Extra spaces in the config are ignored |
| 61 | + |
| 62 | +## Examples |
| 63 | + |
| 64 | +### Docker Compose |
| 65 | + |
| 66 | +```yaml |
| 67 | +services: |
| 68 | + devlake: |
| 69 | + environment: |
| 70 | + - GITHUB_PR_EXCLUDELIST=renovate[bot],dependabot[bot] |
| 71 | +``` |
| 72 | +
|
| 73 | +### Kubernetes |
| 74 | +
|
| 75 | +```yaml |
| 76 | +env: |
| 77 | + - name: GITHUB_PR_EXCLUDELIST |
| 78 | + value: "renovate[bot],dependabot[bot],github-actions[bot]" |
| 79 | +``` |
| 80 | +
|
| 81 | +### Local Development |
| 82 | +
|
| 83 | +```bash |
| 84 | +# .env file |
| 85 | +GITHUB_PR_EXCLUDELIST=renovate[bot],dependabot[bot] |
| 86 | +``` |
| 87 | + |
| 88 | +## Updating the Exclusion List |
| 89 | + |
| 90 | +Changes to `GITHUB_PR_EXCLUDELIST` require a DevLake restart. After updating: |
| 91 | + |
| 92 | +1. Restart DevLake |
| 93 | +2. Trigger re-collection for affected repositories |
| 94 | +3. Previously collected bot data remains in the database |
| 95 | +4. New collections will respect the updated filter |
| 96 | + |
| 97 | +## Verification |
| 98 | + |
| 99 | +Check logs for filtering activity: |
| 100 | + |
| 101 | +``` |
| 102 | +DEBUG: Skipping PR #123 from bot user: renovate[bot] |
| 103 | +DEBUG: Skipping review #456 from bot user: dependabot[bot] |
| 104 | +``` |
| 105 | + |
| 106 | +## Troubleshooting |
| 107 | + |
| 108 | +**Bot PRs still appearing in metrics:** |
| 109 | + |
| 110 | +1. Verify `GITHUB_PR_EXCLUDELIST` is set correctly |
| 111 | +2. Check DevLake logs for "Skipping" messages |
| 112 | +3. Ensure username matches exactly (case-insensitive) |
| 113 | +4. Restart DevLake after config changes |
| 114 | +5. Re-run collection for the repository |
| 115 | + |
| 116 | +**How to find bot usernames:** |
| 117 | + |
| 118 | +Check GitHub PR/comment authors in the web UI - bot usernames typically end with `[bot]`. |
0 commit comments