Pull request size plugin

This plugin adds the size information of pull requests to the pull request search page. It also adds the number of commits ahead and behind the destination branch.

Bitbucket pull request with files and number of lines changed

It’s enabled by default, but you can customize it further by:

  • Categorizing pull requests by size thresholds
  • Enforcing a maximum size threshold using a merge check
  • Excluding files when calculating the size

Thresholds

You can define thresholds for pull request changes to easily group and classify them into different sizes and understand them at a glance. It also allows you to filter using the sizes you’ve defined.

function pullRequestSize(options: PullRequestSizeOptions): PluginDef<PullRequestSizeOptions> (+1 overload)pullRequestSize({
  PullRequestSizeOptions.thresholds?: Record<string, SizeCriteria> | undefinedthresholds: {
    
type Small: {
    maxFiles: number;
    maxTotalLines: number;
}
Small
: {maxFiles?: number | undefinedmaxFiles: 3, maxTotalLines?: number | undefinedmaxTotalLines: 25},
type Medium: {
    maxTotalLines: number;
}
Medium
: {maxTotalLines?: number | undefinedmaxTotalLines: 300},
type Large: {
    maxLinesAdded: number;
    maxLinesRemoved: number;
}
Large
: {maxLinesAdded?: number | undefinedmaxLinesAdded: 500, maxLinesRemoved?: number | undefinedmaxLinesRemoved: 300},
type Huge: {}Huge: {}, // <--- Catch all threshold }, })

The names are arbitrary, and you can have as many thresholds as necessary. You can use lines (maxTotalLines,maxLinesAdded,maxLinesRemoved) and files (maxFiles) to define the threshold criteria. Upper limits should usually be defined as a catch-all threshold. You can achieve this by using an empty criterion, as shown above.

Flowie automatically creates labels and associates them based on the thresholds.

Bitbucket pull request with size label

Enforce a maximum size

Once you have defined your thresholds, you can optionally set a maximum size using the maxSize option.

function pullRequestSize(options: PullRequestSizeOptions): PluginDef<PullRequestSizeOptions> (+1 overload)pullRequestSize({
  PullRequestSizeOptions.thresholds?: Record<string, SizeCriteria> | undefinedthresholds: {
    
type Small: {
    maxTotalLines: number;
}
Small
: {maxTotalLines?: number | undefinedmaxTotalLines: 100},
type Medium: {
    maxTotalLines: number;
}
Medium
: {maxTotalLines?: number | undefinedmaxTotalLines: 300},
type Large: {}Large: {}, }, PullRequestSizeOptions.maxSize?: string | undefinedmaxSize: "Medium", })

In this example, pull requests classified above Medium will fail the merge checks, thereby preventing them from being merged.

Bitbucket pull request size check failing

Excluding files

Some files or directories are generated and are usually not relevant during the code review. It’s possible to exclude these files when calculating the pull request size.

function pullRequestSize(options: PullRequestSizeOptions): PluginDef<PullRequestSizeOptions> (+1 overload)pullRequestSize({
  PullRequestSizeOptions.exclude?: string[] | undefinedexclude: ["package-lock.json"],
})

Complete example

import {const configure: (config: Config | (() => Config)) => voidconfigure} from "flowie.app"
import {const pullRequestSize: OptionsPluginNoDefault<PullRequestSizeOptions, false>pullRequestSize, const merge: OptionsPlugin<MergePluginOptions, false>merge} from "flowie.app/plugins"

function configure(config: Config | (() => Config)): voidconfigure({
  Config.plugins?: PluginDef<unknown>[] | undefinedplugins: [
    // Use merge plugin to enforce merge checks
    function merge(): PluginDef<MergePluginOptions> (+2 overloads)merge(),
    function pullRequestSize(options: PullRequestSizeOptions): PluginDef<PullRequestSizeOptions> (+1 overload)pullRequestSize({
      PullRequestSizeOptions.thresholds?: Record<string, SizeCriteria> | undefinedthresholds: {
        
type Small: {
    maxTotalLines: number;
}
Small
: {maxTotalLines?: number | undefinedmaxTotalLines: 100},
type Medium: {
    maxTotalLines: number;
}
Medium
: {maxTotalLines?: number | undefinedmaxTotalLines: 300},
type Large: {}Large: {}, }, PullRequestSizeOptions.maxSize?: string | undefinedmaxSize: "Medium", PullRequestSizeOptions.exclude?: string[] | undefinedexclude: ["package-lock.json"], }), ], })