> ## Documentation Index
> Fetch the complete documentation index at: https://bilanc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Pull Request Metrics

> API endpoints for pull request related metrics

## Pull Request Metrics

Pull request metrics provide insights into the volume, size, productivity, and interactions of pull requests in your repositories.

### Available Metrics

<ParamField path="pull-requests-count" type="string">
  Number of pull requests
</ParamField>

<ParamField path="pull-requests-size" type="string">
  Size of pull requests (additions + deletions)
</ParamField>

<ParamField path="review-rate" type="string">
  Percentage of PRs that received at least one review
</ParamField>

<ParamField path="complexity-score" type="string">
  Code complexity score of pull requests
</ParamField>

<ParamField path="contributors-count" type="string">
  Number of unique contributors
</ParamField>

<ParamField path="reviews-count" type="string">
  Number of reviews submitted
</ParamField>

<ParamField path="review-interactions-count" type="string">
  Number of review interactions
</ParamField>

<ParamField path="review-rounds" type="string">
  Number of review rounds per PR
</ParamField>

<ParamField path="reviewers-per-pr" type="string">
  Average number of reviewers per PR
</ParamField>

<ParamField path="active-reviewers" type="string">
  Number of distinct reviewers in the period
</ParamField>

<ParamField path="changes-requested-rate" type="string">
  Rate of reviews that requested changes
</ParamField>

<ParamField path="comment-interactions-count" type="string">
  Comment interaction count
</ParamField>

<ParamField path="comments-count" type="string">
  Number of comments
</ParamField>

<ParamField path="comments-per-pr" type="string">
  Average number of comments per PR
</ParamField>

<ParamField path="commit-interactions-count" type="string">
  Commit interaction count
</ParamField>

<ParamField path="commits-count" type="string">
  Number of commits
</ParamField>

## Pull Requests Count Metric

This endpoint provides the count of pull requests based on specified filters.

<CodeGroup>
  ```bash Request theme={null}
  curl -X POST 'https://api.bilanc.co/metrics/pull-requests-count' \
    -H 'Authorization: YOUR_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
      "filters": {
        "pr_states": ["merged", "closed"],
        "start_date": "2023-01-01",
        "end_date": "2023-01-02"
      },
      "group_by": ["repository", "pr_state"],
      "date_level": "day",
      "date_field": "created_at",
    }'
  ```

  ```json Response theme={null}
  [
    {
      "day_date": "2023-01-01",
      "repository": "repo-a",
      "pr_state": "merged",
      "pr_count": 5
    },
    {
      "day_date": "2023-01-01",
      "repository": "repo-b",
      "pr_state": "merged",
      "pr_count": 8
    },
    {
      "day_date": "2023-01-01",
      "repository": "repo-a",
      "pr_state": "closed",
      "pr_count": 1
    },
    {
      "day_date": "2023-01-02",
      "repository": "repo-a",
      "pr_state": "merged",
      "pr_count": 3
    },
  ]
  ```
</CodeGroup>

## Pull Requests Size Metric

This endpoint provides information about the size of pull requests.

<CodeGroup>
  ```bash Request theme={null}
  curl -X POST 'https://api.bilanc.co/metrics/pull-requests-size' \
    -H 'Authorization: YOUR_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
      "filters": {
        "start_date": "2023-01-01",
        "end_date": "2023-12-31"
      },
      "group_by": ["repository"],
      "aggregation": "sum",
      "date_field": "created_at"
    }'
  ```

  ```json Response theme={null}
  [
    {
      "date_level_not_set": true,
      "repository": "frontend-repo",
      "sum_additions": 5499,
      "sum_deletions": 1234,
      "sum_total_changes": 6733
    },
    {
      "date_level_not_set": true,
      "repository": "backend-repo",
      "sum_additions": 7800,
      "sum_deletions": 4500,
      "sum_total_changes": 12300
    },
  ]
  ```
</CodeGroup>

## Complexity Score Metric

This endpoint provides the complexity score of pull requests, which measures code complexity introduced per PR.

<CodeGroup>
  ```bash Request theme={null}
  curl -X POST 'https://api.bilanc.co/metrics/complexity-score' \
    -H 'Authorization: YOUR_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
      "filters": {
        "team": ["team123"],
        "start_date": "2023-01-02",
        "end_date": "2023-01-31"
      },
      "group_by": ["team_name"],
      "date_level": "week",
      "aggregation": "AVG",
      "date_field": "merged_at"
    }'
  ```

  ```json Response theme={null}
  [
    {
      "week_date": "2023-01-02",
      "team_name": "Frontend",
      "avg_complexity_score": 4.5
    },
    {
      "week_date": "2023-01-02",
      "team_name": "Backend",
      "avg_complexity_score": 6.1
    },
    {
      "week_date": "2023-01-09",
      "team_name": "Frontend",
      "avg_complexity_score": 3.8
    },
    {
      "week_date": "2023-01-09",
      "team_name": "Backend",
      "avg_complexity_score": 5.4
    }
  ]
  ```
</CodeGroup>

## Parameter Notes

<ResponseField name="date_field" type="string">
  For pull request metrics, the following date fields are available:

  * `created_at`: When the PR was created
  * `merged_at`: When the PR was merged
  * `closed_at`: When the PR was closed
</ResponseField>

<ResponseField name="aggregation" type="string">
  Required for non-count metrics. Accepted values: `SUM`, `MAX`, `MIN`, `AVG`.
  Count-based metrics (`pull-requests-count`, `reviews-count`, `comments-count`, `commits-count`, `review-interactions-count`, `comment-interactions-count`, `commit-interactions-count`, `review-rounds`, `active-reviewers`, `reviewers-per-pr`, `review-rate`, `changes-requested-rate`, `comments-per-pr`, `contributors-count`) do not require an aggregation.
</ResponseField>

<ResponseField name="filters" type="object">
  Applicable filters for pull request metrics:

  * `repositories`: Array of `{"repository_name": "..."}` objects
  * `member`: Filter by author merged user IDs
  * `team`: Filter by team IDs
  * `squad_ids`: Filter by squad IDs
  * `squad_levels`: Filter by squad hierarchy level
  * `manager_ids`: Filter by manager user IDs
  * `departments`: Filter by department names
  * `pr_states`: PR states — `open`, `closed`, `merged`
  * `pr_categories`: PR category classifications
  * `pr_ids`: Filter by specific PR IDs
  * `sources`: VCS source — `github`, `gitlab`, `bitbucket`
  * `pull_requests_search_term`: Full-text search across PR title, description, body, summary, and category
  * `locations`: Filter by employee location
  * `levels`: Filter by employee level
  * `review_hour_of_day`: Filter reviews by hour of day (0–23) — for `reviews-by-time-of-day`
  * `review_rounds_bucket`: Filter by review rounds bucket — for `review-rounds`
</ResponseField>

## Common Use Cases

* **Monitor PR Volume**: Track the number of PRs created over time
* **Identify Large PRs**: Find PRs that are above a certain size threshold using `metric_min_value`
* **Analyze Review Culture**: Track review rate and comments per PR
* **Assess productivity Trends**: Monitor if code productivity is increasing or decreasing over time
* **Team Comparison**: Compare PR metrics across different teams or repositories
